No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s2:aih:projekt:studenci:openthread
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:edu:zmitac:s2:aih:projekt:studenci:openthread [2024/09/17 23:27] – blazkol203 | en:edu:zmitac:s2:aih:projekt:studenci:openthread [2024/09/18 20:58] (current) – blazkol203 | ||
|---|---|---|---|
| Line 42: | Line 42: | ||
| </ | </ | ||
| - | After that, we bringe up the IPv6 interface and the Thread protocol: | + | After that, we bringe up the IPv6 interface and the Thread protocol |
| - | < | + | |
| - | ifconfig up | + | |
| - | thread start | + | |
| - | </ | + | |
| - | + | ||
| - | After a while, the device should change its status to " | + | |
| ===== Connecting the STM32WB55 to the Thread Network ===== | ===== Connecting the STM32WB55 to the Thread Network ===== | ||
| Line 103: | Line 97: | ||
| </ | </ | ||
| - | Then send a message from second board to MLE-ID address of the first board and previously selected port: | + | Then send a message from the second board to MLE-ID address of the first board and previously selected port: |
| < | < | ||
| udp open | udp open | ||
| Line 114: | Line 108: | ||
| The official documentation can be found at the following link: https:// | The official documentation can be found at the following link: https:// | ||
| - | < | + | To make OpenThread API calls, it is necessary to initialize a static instance of the OpenThread library. In the ESP32H2 example, such an instance is returned by the '' |
| + | ==== Reacting to device role changes ==== | ||
| + | |||
| + | If we want to react whenever OpenThread instance state changes, we need to add following callback registration to our code: | ||
| + | |||
| + | < | ||
| + | otSetStateChangedCallback(esp_openthread_get_instance(), | ||
| </ | </ | ||
| - | ==== ESP32H2 ==== | + | We also need to define a function that will be called after each state change: |
| < | < | ||
| Line 152: | Line 152: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | The code above was written for the ESP32H2 platform, but in the Thread_CLI_Cmd example on STM32WB55 there exist similar functionality by default. | ||
| + | |||
| + | ==== Sending and receiving UDP messages ==== | ||
| + | When using UDP, we can define the port we want to use and also declare static variables such as socket, address or message payload. | ||
| < | < | ||
| #define UDP_PORT | #define UDP_PORT | ||
| + | static otUdpSocket sUdpSocket; | ||
| static const char UDP_DEST_ADDR[] = " | static const char UDP_DEST_ADDR[] = " | ||
| static const char UDP_PAYLOAD[] | static const char UDP_PAYLOAD[] | ||
| - | static otUdpSocket sUdpSocket; | ||
| </ | </ | ||
| + | |||
| + | The following function can be used to initialize UDP: | ||
| < | < | ||
| Line 175: | Line 182: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | We also define a function that will be called after receiving a message: | ||
| < | < | ||
| Line 192: | Line 201: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | To send a UDP message we can use the following function: | ||
| < | < | ||
| Line 223: | Line 234: | ||
| </ | </ | ||
| - | ==== STM32WB55 | + | Here is an example of calling the above function inside a button interrupt from an STM32WB55 |
| < | < | ||
| + | void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) | ||
| + | { | ||
| + | if(GPIO_Pin == BUTTON_SW1_PIN) { | ||
| + | sendUdp(PtOpenThreadInstance); | ||
| + | } else { | ||
| + | __NOP(); | ||
| + | } | ||
| + | } | ||
| </ | </ | ||
en/edu/zmitac/s2/aih/projekt/studenci/openthread.1726608429.txt.gz · Last modified: by blazkol203
