This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

CLI Example OpenThread 2.0.0 - UDP data transfer from main.c

Hello!
We are working with NRF52840 dongles and want to be able to have them relay data over an OpenThread mesh network through UDP automatically. We have found within the OpenThread API a solid Udp.h library with all the Udp functions we need to create code that runs on the dongles from the main.c.
Below is our code that should broadcast the message: "Hallo" to all nodes that have an open socket on port 1994.
We have read that the ipv6 address ff03::1 is reserved for multicast UDP broadcasting and it works perfectly when manually performed with the CLI udp commands.
CLI:  Udp open, udp send ff03::1 1994 Hallo
With all the nodes that have udp open, udp bind :: 1994, receiving the Hallo message from the sending node.
We are trying to recreate this in the main.c of our nodes so that we can provide the nodes with some intelligence of their own.
This piece of code is run once when the push button on the dongle is pressed.
The code compiles perfectly and we have tested the functions that have a return with the RGB led (green OK, red not) to confirm that there weren't any errors produced (sadly not all functions return a no_error value)
void udpSend(){
    char buf[512];
    otMessageInfo messageInfo;

    strcpy(buf, "Hallo\0");

    memset(&messageInfo, 0, sizeof(messageInfo));

    otIp6AddressFromString("ff03::1\0", &messageInfo.mSockAddr);
    messageInfo.mSockPort = 1994;

    otUdpSocket mySocket;
    otIp6AddressFromString("ff03::1\0", &mySocket.mSockName.mAddress);
    mySocket.mSockName.mPort = 1994;
    otUdpOpen(thread_ot_instance_get(), &mySocket, NULL, NULL);

    otMessage *test_Message = otUdpNewMessage(thread_ot_instance_get(), NULL);

    if (otMessageAppend(test_Message, &buf, sizeof(buf)) == OT_ERROR_NONE){
       nrf_gpio_pin_write(LED2_G, 0);
    }
    else{
       nrf_gpio_pin_write(LED2_R, 0);
    } 

    otUdpSend(&mySocket, test_Message, &messageInfo);

    otUdpClose(&mySocket);
}

Now, we aren't exactly experts, so we are not sure why this isn't working as we had a lot of trouble figuring out how everything is called/initialised.
We hope to create a way to send and receive data through UDP through the code, so that they can operate autonomously.
We would really appreciate it if someone could assist us with our project!
Thanks!
Jonathan
Parents
  • Hi,

    I also had this problem. I have rebuild openthread libraries (infocenter.nordicsemi.com/.../thread_intro.html and now udp packets are working. Additionaly, mqtt have now wrong usage of otUdpNewMessage in 2 parameter (don't remember exactly).

    Best Regards

    Maciej Bozyk

  • Hi,

    We are currently developing an application using the nRF52840 Dongle and we found the same issue.
    Udp messages are correctly sent using CLI example ( under usb_bootloader folder) but when we try to modify the code to send the same message nothing happens, even if no errror is encountered by calling OpenThread API. 

    We decided to rebuild the libraries as you suggested but we encountered some problems including them inside Segger Embedded studio project (we try to modify the same example above).

    Can you provide us with some more information about your procedures? Do you have any code example can we can study to learn and resolve our issues?

    Edit: we resolved problems related to dependencies but nothing changed.

    No error during code but UDP messages sent only through CLI, not working by code.

    Any ideas?



    Thanks in advance! Best regards.

  • Hi Giorgio,

    I've rebuild OT libraries following this guide https://www.nordicsemi.com/DocLib/Content/SDK_Doc/Thread_SDK/v2-0-0/thread_intro?12#thread_qsg_libraries (in case of any problems, look on official OT guide: https://openthread.io/guides/build). Only problem I've found was that otUdpNewMessage() takes different 2 argument which I've changed in MQTT.

    I've made a script for easy OT libs update, just clone OT repo in the same library that you have SDK.

    #!/bin/sh
     
    FLAGS= \
    COMMISSIONER=1 \
    JOINER=1 \
    COAP=1 \
    DNS_CLIENT=1 \
    MTD_NETDIAG=1 \
    BORDER_ROUTER=1 \
    MAC_FILTER=1 \
    UDP_PROXY=1 \
    BORDER_AGENT=1 \
    USB=1 \
    
     
    SDK_DIR=`pwd`
    cd ../openthread/
    OT_DIR=`pwd`
    ./script/bootstrap
    ./bootstrap
    make -f examples/Makefile-nrf52840 $FLAGS
    mv $OT_DIR/output/nrf52840/lib/libopenthread-nrf52840-sdk.a $OT_DIR/output/nrf52840/lib/libopenthread-nrf528 40-sdk-usb.a
    mv $OT_DIR/output/nrf52840/lib/libopenthread-nrf52840-softdevice-sdk.a $OT_DIR/output/nrf52840/lib/libopenth read-nrf52840-sdk-softdevice-usb.a
    cp $OT_DIR/output/nrf52840/lib/* $SDK_DIR/external/openthread/lib/gcc/
    cp -r $OT_DIR/output/include/openthread/* $SDK_DIR/external/openthread/include/openthread/
    cp $OT_DIR/examples/platforms/nrf52840/platform-softdevice.h $SDK_DIR/external/openthread/include/openthread /platform/
    cp $OT_DIR/examples/platforms/nrf52840/platform-fem.h $SDK_DIR/external/openthread/include/openthread/platfo rm/
    cp $OT_DIR/examples/platforms/openthread-system.h $SDK_DIR/external/openthread/include/openthread/platform/

    Best Regards,

    Maciej Bożyk

  • Hi Maciej,

    Thanks for your help! 

    Unfortunately we are here again... We decided to start from zero. 

    We downloaded the nRF Thread & Zigbee SDK and clone the OT repo again.

    Then we followed your instructions using the script you provided but this time nothing works... We tried to build the CLI example ( under usb_bootloader folder) as we did before and again Segger Embedded Studio had some dependencies problem that we fixed adding the libraries : 1) libnordicsemi-nrf52840-radio-driver.a 2) libnordicsemi-nrf52840-radio-driver-softdevice.a.

    Done that, we compiled and put the .hex file in the nRF52840 Dongle using nRF connect. This time the device is not recognised by the PC and we cannot open the cli as we did before.

    What could have gone wrong? 

    Do you have any complete example code we can look at some repo? That would be fantastic.

    Thanks for you help and support, 

    Best regards

    Giorgio 

  • Hi Giorgio,

    Did you merge the built .hex file with the soft device .hex? When using the Nordic connect tool to upload the .hex file to the dongle, you need to make sure that the connect tool recognises that both the application (your program, like the CLI example) and the soft device are present inside the .hex file.

    If you have this setup then you can put the dongle in bootloader mode (the tiny button facing away from the USB port) and the red led will start to "breathe". Then connect will recognise the dongle and you can write the .hex file to the dongle.

    Afterwards the dongle will reboot and boot up your application.

    To merge the soft device and your application, you can use the mergehex tool.

    Concerning the CLI example from Nordic. It just doesn't seem to receive the messages that are sent through code instead of manually typing in the commands in the CLI. I would recommend switching to the CLI example inside the OT repo. It supports the same features if you enable them in the makefile but the UDP otFunctions are actually working.

    Hope that helps!

    Jonathan

  • Hi Jonathan,

    Thanks for the reply!

    About the Nordic CLI example... Well, good to know! 

    We will now try with the OT examples from the repo, thank you!

    For the moment, can you confirm that the softdevice .hex that I need to use for the nRF52840 Dongle is located under components/softdevice/s140/hex inside the SDK for Thread and Zigbee? ( the .hex file is called in my case: s140_nrf52_6.1.0_softdevice.hex

    Thanks again, I really appreciate your help!

    Best regards,

    Giorgio

Reply
  • Hi Jonathan,

    Thanks for the reply!

    About the Nordic CLI example... Well, good to know! 

    We will now try with the OT examples from the repo, thank you!

    For the moment, can you confirm that the softdevice .hex that I need to use for the nRF52840 Dongle is located under components/softdevice/s140/hex inside the SDK for Thread and Zigbee? ( the .hex file is called in my case: s140_nrf52_6.1.0_softdevice.hex

    Thanks again, I really appreciate your help!

    Best regards,

    Giorgio

Children
Related