User Tools

Site Tools


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.

Link to this comparison view

Both sides previous revisionPrevious revision
en:edu:zmitac:s2:aih:projekt:studenci:openthread [2024/09/17 23:40] – [Sending messages between Thread Nodes via CLI] blazkol203en:edu:zmitac:s2:aih:projekt:studenci:openthread [2024/09/18 20:58] (current) – blazkol203
Line 108: Line 108:
 The official documentation can be found at the following link: https://openthread.io/reference The official documentation can be found at the following link: https://openthread.io/reference
  
-<code>+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 ''esp_openthread_get_instance()'' function. In the STM32WB55 example, by default the OpenThread instance is initialized in the ''APP_THREAD_DeviceConfig(void)'' function.
  
 +==== 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:
 +
 +<code>
 +otSetStateChangedCallback(esp_openthread_get_instance(), handleNetifStateChanged, esp_openthread_get_instance());
 </code> </code>
  
-==== Reacting to device role changes ====+We also need to define a function that will be called after each state change:
  
 <code> <code>
Line 146: Line 152:
 } }
 </code> </code>
 +
 +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.
  
 <code> <code>
 #define UDP_PORT    1212 #define UDP_PORT    1212
  
 +static otUdpSocket sUdpSocket;
 static const char UDP_DEST_ADDR[] = "ff03::1"; static const char UDP_DEST_ADDR[] = "ff03::1";
 static const char UDP_PAYLOAD[]   = "Hello World!"; static const char UDP_PAYLOAD[]   = "Hello World!";
-static otUdpSocket sUdpSocket; 
 </code> </code>
 +
 +The following function can be used to initialize UDP:
  
 <code> <code>
Line 171: Line 182:
 } }
 </code> </code>
 +
 +We also define a function that will be called after receiving a message:
  
 <code> <code>
Line 188: Line 201:
 } }
 </code> </code>
 +
 +To send a UDP message we can use the following function:
  
 <code> <code>
Line 218: Line 233:
 } }
 </code> </code>
 +
 +Here is an example of calling the above function inside a button interrupt from an STM32WB55 board.
  
 <code> <code>
Line 228: Line 245:
   }   }
 } }
-</code> 
- 
-<code> 
- 
 </code> </code>
en/edu/zmitac/s2/aih/projekt/studenci/openthread.1726609238.txt.gz · Last modified: by blazkol203