Zephyr and Nordic nRF Connect SDK - 07 Using UDP in OpenThread over API

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 มิ.ย. 2024
  • Thread is a network technology for wireless networks based on IPv6. It is ideally suited for home automation, Industry 4.0 and wireless sensor-actuator networks. In this video, we program OpenThread mesh network with Zephyr (nRF Connect SDK) using two developer board nRF52840-dk from Nordic Semiconductor. Then we are sending an UDP package from one device to a second one using the API from OpenThread.
    You can support me at Patreon:
    / wsnandiot
    ##Introduction into network technology Thread###########
    • Thread network technol...
    ##Sniffing IEEE 802.15.4 packages (Thread and ZigBee) with Wireshark###########
    • Thread network technol...
    ##Hardware###########
    Developer board nRF52840-dk:
    www.nordicsemi.com/Products/D...
    00:00 Introduction
    00:40 UDP use case
    01:29 Creating new project for sender
    02:57 OpenThread header files
    03:16 Implementing a button
    04:21 Send UDP package function
    08:34 Build sender example
    09:03 Testing the sender device
    10:23 Creating new project for receiver
    12:07 Receive callback-function
    13:37 Initialize UDP-parameter (open & bind)
    16:54 Testing the application
    17:33 Outro
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 14

  • @vigneshs6232
    @vigneshs6232 ปีที่แล้ว +1

    Without using only command window, Now I can make my message to send to particular Thread device using a Single button...You are making us to use the full capability of programming....
    Please teach about sending message to a particular Thread device from Border Router and also receiving messages or sensor readings from different Thread End devices to Master device or Border Router....
    Your flow of teaching programming is really perfect and fabulous....Please continue to do along this way...Eagerly waiting for your upcoming videos on CoAP and other latest things...
    Thankyou Once again...♥

  • @pranavnadimpalli730
    @pranavnadimpalli730 ปีที่แล้ว

    Excellent video! I am truly enjoying this series. It would be cool if you could create a whole network using DevKits and nrf Dongles

    • @wsniot
      @wsniot  ปีที่แล้ว

      I'd love to, but unfortunately I don't have the hardware for it. I would love to set up a larger network with various environmental sensors and send them to a CoAP server in the cloud via a border router and collect the data there. The sensors are not a problem, but I only have limited nrf hardware here at the moment and I also don't have the opportunity to set up a CoAP server in the cloud yet.

  • @rosskappa5410
    @rosskappa5410 ปีที่แล้ว +1

    I had errors with the original code so here's a little modified one:
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    void udpReceive_cb(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
    static void udp_init(void);
    void main(void)
    {
    // udp_init(); had errors when this this line wasnt in while(1)

    while (1) {
    udp_init();
    int a = 5;
    int c=5;
    c = c+5;

    // printk("qwerqwr
    ") // mcu keeps resetting itself
    // k_msleep(1000); // mcu keeps resetting itself
    }


    }
    void udpReceive_cb(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
    {
    uint16_t payloadLength = otMessageGetLength(aMessage) - otMessageGetOffset(aMessage);
    char buf[payloadLength+1];
    otMessageRead(aMessage, otMessageGetOffset(aMessage),buf, payloadLength);
    buf[payloadLength]='\0';
    printk("Received: %s
    ",buf);
    }
    static void udp_init(void)
    {
    otError error = OT_ERROR_NONE;
    otInstance *myInstance = openthread_get_default_instance();
    otUdpSocket mySocket;
    otSockAddr mySockAddr;
    memset(&mySockAddr,0,sizeof(mySockAddr));
    mySockAddr.mPort = 2222; // we chose this port.
    do{
    error = otUdpOpen(myInstance, &mySocket, udpReceive_cb, NULL); //udp mesajı gelince tanımlanan callback funca giriyor.
    if (error != OT_ERROR_NONE) break;
    error = otUdpBind(myInstance, &mySocket, &mySockAddr, OT_NETIF_THREAD);
    }while(false);
    if (error != OT_ERROR_NONE){
    printk("init_udp error: %d
    ", error);
    }
    }

    • @gabrielgraf2521
      @gabrielgraf2521 ปีที่แล้ว

      i had problems too. for me the solution was to keep the sleep in the while loop and the udp_int outside. i still didnt get why the mcu keept reseting

  • @mrafayshams3089
    @mrafayshams3089 ปีที่แล้ว

    I know if you wish to sell a thread or zigbee certified product; you need to get certification from appropriate authorities.
    But do I still need certification if I'm only using CoAP or UDP to communicate between sensors? Like an entry sensor communicates with the base station via Zigbee or UDP?

    • @wsniot
      @wsniot  ปีที่แล้ว +1

      I don't know the legal requirements on certified product but as I understand it, you can use Thread,and ZigBee for your own application and also sell it commercially. However, you cannot advertise with ZigBee or Thread until you have completed certification process. After all, Zephyr and OpenThread are free to use. CoAP as i know itself has anyway no certification program.

    • @mrafayshams3089
      @mrafayshams3089 ปีที่แล้ว

      @@wsniot I see now. Thanks once again! :)

  • @leoxie1971
    @leoxie1971 ปีที่แล้ว

    Doesn't it need to commissioning?

    • @wsniot
      @wsniot  ปีที่แล้ว

      No. Commissioning in a thread network is for sharing the network parameter and the network key. In this example the network parameter are set manually in the prj.conf. So no need to exchange them. But make sure you erase the chip before flashing. If not the device take the previously stored parameter.

    • @leoxie1971
      @leoxie1971 ปีที่แล้ว

      @@wsniot thank you WSN team, I guess that's kind of like out-band commissioning.

  • @rosskappa5410
    @rosskappa5410 ปีที่แล้ว +1

    #include
    #include
    #include
    #include
    #include
    /* 1000 msec = 1 sec */
    #define SLEEP_TIME_MS 1000
    /* The devicetree node identifier for the "led0" alias. */
    #define BUTTON0_NODE DT_NODELABEL(button0)
    static void udp_send(void);
    void button0_pressed_callback(const struct device *gpiob, struct gpio_callback *cb, gpio_port_pins_t pins){
    udp_send();
    }
    void main(void)
    {
    static const struct gpio_dt_spec button0 = GPIO_DT_SPEC_GET(BUTTON0_NODE, gpios);
    if (!(device_is_ready(button0.port))) {printk("port isn't ready
    "); return;}
    gpio_pin_configure_dt(&button0, GPIO_INPUT);
    gpio_pin_interrupt_configure_dt(&button0,GPIO_INT_EDGE_TO_INACTIVE); // configured interrupt
    static struct gpio_callback button0_cb; // will hold information such as the pin number and the function to be called when an interrupt occurs (callback function).
    gpio_init_callback(&button0_cb, button0_pressed_callback, BIT(button0.pin)); /* Initialize the struct gpio_callback button_cb_data by passing this variable,
    along with the callback function and the bit mask for the GPIO pin button.pin to gpio_init_callback().*/
    gpio_add_callback(button0.port, &button0_cb); // add the callback func
    while (1) {

    k_msleep(SLEEP_TIME_MS);
    }
    }
    static void udp_send(void)
    {
    otError error = OT_ERROR_NONE;
    const char *buf = "Hello Thread xd";
    otInstance *myInstance;
    myInstance = openthread_get_default_instance();
    otUdpSocket mySocket;
    otMessageInfo messageInfo;
    memset(&messageInfo, 0, sizeof(messageInfo));
    otIp6AddressFromString("ff03::1", &messageInfo.mPeerAddr);
    messageInfo.mPeerPort = 2222; /
    do{
    error = otUdpOpen(myInstance, &mySocket, NULL, NULL);
    if (error != OT_ERROR_NONE) break;
    otMessage *test_Message = otUdpNewMessage(myInstance, NULL);
    error = otMessageAppend(test_Message, buf, (uint16_t)strlen(buf));
    if (error != OT_ERROR_NONE) break;
    error = otUdpSend(myInstance, &mySocket, test_Message, &messageInfo);
    if (error != OT_ERROR_NONE) break;
    error = otUdpClose(myInstance, &mySocket);

    }while(false);
    if (error == OT_ERROR_NONE)
    printk("Sent.
    ");
    else
    printk("udpSend error: %d
    ", error);
    }

    • @gabrielgraf2521
      @gabrielgraf2521 ปีที่แล้ว

      thank you man! you are my hero! i hate when people dont uploade there code

    • @WaqarRashid
      @WaqarRashid 3 หลายเดือนก่อน

      If you are having issues with importing net/thread.h then try #include