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 Reply
  • Hi,

    I don't know which problem causes the Nordic CLI Example to not receive the messages. We switched to the OpenThread CLI example that you can build with the nRF52840 (if that is the board you are using) makefile that is available in the official OpenThread github repo. This CLI does support the UDP communication from within the code, instead of manually sending messages through the CLI.

    Hope that helped!

    Kind regards,

    Jonathan

Children
Related