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
Next revision
Previous revision
en:edu:zmitac:s2:aih:projekt:studenci:openthread [2024/09/17 23:27] – blazkol203en:edu:zmitac:s2:aih:projekt:studenci:openthread [2024/09/18 20:58] (current) – blazkol203
Line 42: Line 42:
 </code> </code>
  
-After that, we bringe up the IPv6 interface and the Thread protocol: +After that, we bringe up the IPv6 interface and the Thread protocol with ''ifconfig up'' and ''thread start''. After a while, the device should change its status to "child" and then automatically to "router".
-<code> +
-ifconfig up +
-thread start +
-</code> +
- +
-After a while, the device should change its status to "child" and then automatically to "router".+
  
 ===== Connecting the STM32WB55 to the Thread Network ===== ===== Connecting the STM32WB55 to the Thread Network =====
Line 103: Line 97:
 </code> </code>
  
-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:
 <code> <code>
 udp open udp open
Line 114: 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>
  
-==== ESP32H2 ====+We also need to define a function that will be called after each state change:
  
 <code> <code>
Line 152: 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 ====
 +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 175: Line 182:
 } }
 </code> </code>
 +
 +We also define a function that will be called after receiving a message:
  
 <code> <code>
Line 192: Line 201:
 } }
 </code> </code>
 +
 +To send a UDP message we can use the following function:
  
 <code> <code>
Line 223: Line 234:
 </code> </code>
  
-==== STM32WB55 ====+Here is an example of calling the above function inside a button interrupt from an STM32WB55 board.
  
 <code> <code>
 +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) 
 +{ 
 +  if(GPIO_Pin == BUTTON_SW1_PIN) { 
 +   sendUdp(PtOpenThreadInstance); 
 +  } else { 
 +      __NOP(); 
 +  } 
 +}
 </code> </code>
en/edu/zmitac/s2/aih/projekt/studenci/openthread.1726608429.txt.gz · Last modified: by blazkol203