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:40] – blazkol203 | en:edu:zmitac:s2:aih:projekt:studenci:openthread [2024/09/18 20:58] (current) – blazkol203 | ||
|---|---|---|---|
| Line 97: | 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 108: | 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(), | ||
| </ | </ | ||
| - | ==== Reacting | + | We also need to define a function that will be called after each state change: |
| < | < | ||
| Line 146: | 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 ==== | ==== 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 171: | Line 182: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | We also define a function that will be called after receiving a message: | ||
| < | < | ||
| Line 188: | Line 201: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | To send a UDP message we can use the following function: | ||
| < | < | ||
| Line 218: | Line 233: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | Here is an example of calling the above function inside a button interrupt from an STM32WB55 board. | ||
| < | < | ||
| Line 228: | Line 245: | ||
| } | } | ||
| } | } | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | |||
| </ | </ | ||
en/edu/zmitac/s2/aih/projekt/studenci/openthread.1726609207.txt.gz · Last modified: by blazkol203
