Send/receive message from/to thread Device and global address using OpenThread API

I am currently working on establishing thread network using nRF5340DK to send/receive data between thread device(client) and global network(server). I was successful in setting up the network and able to ping the devices.

But I really don't know, how could I send packets of data from the thread device to cloud server or global network using OpenThread API calls from my application. Can someone guide me on this or share some useful examples or reference to send some messages(UDP or TCP/IP) from thread device.

Below diagram is my network configuration. Here the OTBR is connected to Ethernet. 

Note: Final goal is to send/receive data from Thread Device to Blockchain Node(Global network) via OTBR. 

Thanks and Regards

Vipin Das

  • Hi Vipin,

    CoAP/UDP is normally used on top of the Thread network by your application.

    You can refer to the sample mentioned here: (+) OpenThread COAP Client to a public server over Internet - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)

    Best regards,

    Charlie

  • Hi Charlie, 

    Thanks for your reply. I will take a look at the samples you mentioned. 

    I have few more questions. 

    • Is there any way I can use TCP+SSL on Thread end device(nRF5340DK) instead of UDP. 
    • I am not quite successful in pinging a global address from my thread end device. I followed many Q&A discussions and also some other discussions as well. Could you please give some insights on that. I did set the route/prefix for global addressing. Current route output is 

    pi@pi:~ $ sudo ip -6 route
    ::1 dev lo proto kernel metric 256 pref medium
    fd11:22::/64 dev wpan0 proto kernel metric 256 pref medium
    fd70:77a5:30f0:1437::/64 dev eth0 proto kernel metric 256 expires 1603sec pref medium
    fdde:ad00:beef::/64 dev wpan0 proto kernel metric 256 pref medium
    fe80::/64 dev eth0 proto kernel metric 256 pref medium
    fe80::/64 dev wlan0 proto kernel metric 256 pref medium
    fe80::/64 dev wpan0 proto kernel metric 256 pref medium
    pi@pi:~ $ 

    pi@pi:~ $ sudo ot-ctl netdata show
    Prefixes:
    fd11:22:0:0::/64 paros med 6000
    Routes:
    fd83:b72e:262d:2:0:0::/96 sn low 6000
    fd70:77a5:30f0:1437::/64 s med 6000
    Services:
    44970 5d fddead00beef0000869fa0cfca6b6ce3d11f s 6000
    44970 01 3a000500000e10 s 6000
    Done
    pi@pi:~ $ 

    • I am bit confused with ifconfig up / thread start commands done in BR side as well as End device side. Could you please tell me what I should do to make RPi+Dongle side as Router only and nRF5340 side as Child. Few times I noticed in my configuration that BR side as well as End device side as leader. 

    Looking forward to your reply. 

    Thanks 

    Vipin Das

  • Hi Vipin,

    vipin das said:
    Is there any way I can use TCP+SSL on Thread end device(nRF5340DK) instead of UDP. 

    Yes, you can find solutions mentioned in (+) Error -22 in mqtt_connect() - nRF52840dk with Azure IoT Hub using OpenThread and TCP - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)

    vipin das said:
    I am not quite successful in pinging a global address from my thread end device.

    Looks like your NAT64 prefix is already set to fd83:b72e:262d:2:0:0::/96. Which is the feedback when you run the ping command?

    I recently followed Thread Border Router - Bidirectional IPv6 Connectivity and DNS-Based Service Discovery (openthread.io) to set up an OTBR and formed a Thread network through Web GUI with default setting. Run the following commands on OpenThread CLI device, the ping command to 8.8.8.8 just works.

    ot networkkey 00112233445566778899aabbccddeeff 
    ot networkkey 00112233445566778899aabbccddeeff
    Done
    ot ifconfig up
    ot ifconfig up
    Done
    ot thread start
    ot thread start
    ot state
    ot state
    detached
    Done
    ot state
    ot state
    child
    Done
    ot state
    ot state
    child
    Done
    ot state router
    ot state router
    Done
    ot state
    ot state
    router
    Done
    ot netdata show
    ot netdata show
    Prefixes:
    fd8e:964d:9d85:1::/64 paos low 3000
    Routes:
    fd11:1111:1122:2222::/64 s med 3000
    fd8e:964d:9d85:2:0:0::/96 sn low 3000
    Services:
    44970 01 32000500000e10 s 3000
    44970 5d fd35e07c0372271ee4a005368966fa59d11f s 3000
    Done
    ot ping 8.8.8.8
    ot ping 8.8.8.8
    Pinging synthesized IPv6 address: fd8e:964d:9d85:2:0:0:808:808
    16 bytes from fd8e:964d:9d85:2:0:0:808:808: icmp_seq=1 hlim=53 time=38msua
    
    1 packets transmitted, 1 packets received. Packet loss = 0.0%. Round-trip min/avg/max = 38/38.0/38 ms.
    Done

    vipin das said:
    I am bit confused with ifconfig up / thread start commands done in BR side as well as End device side. Could you please tell me what I should do to make RPi+Dongle side as Router only and nRF5340 side as Child. Few times I noticed in my configuration that BR side as well as End device side as leader. 

    You need to form the network on OTBR first, then turn on and configure the child device to join the formed network, it will become child first then turn to router, you can also set its role with "ot state router".

    Best regards,

    Charlie

  • Hi Charlie, 

    Happy New Year!!!

    Thank you for your answers and sorry for late reply. 

    I setup the OTBR as per the page and formed the network. And followed the steps as mentioned by you. But I still have some issues. Below is my output from the OT CLI end device terminal. 

    uart:~$ ot networkkey
    d6af7ff1a2fcf42743fd7a6989911d67
    Done
    uart:~$ 
    uart:~$ ot ifconfig up
    Done
    uart:~$ 
    uart:~$ ot thread start
    Done
    uart:~$ 
    uart:~$ ot state
    leader
    Done
    uart:~$ 
    uart:~$ ot state child
    Done
    uart:~$ 
    uart:~$ 
    uart:~$ ot state
    leader
    Done
    uart:~$ 
    uart:~$ ot state router
    Done
    uart:~$ 
    uart:~$ ot state router
    Done
    uart:~$ 
    uart:~$ 
    uart:~$ 
    uart:~$ ot state
    leader
    Done
    uart:~$ 
    uart:~$ 
    uart:~$ ot netdata show
    Prefixes:
    fd11:22:0:0::/64 paros med 2400
    Routes:
    fd1f:8fda:e9e0:2:0:0::/96 sn low 2400
    fd70:77a5:30f0:1437::/64 s med 2400
    Services:
    44970 5d fddead00beef00000cd8cbff1e5c562fd11f s 2400
    44970 01 76000500000e10 s 2400
    Done
    uart:~$ 
    uart:~$ ot ping 8.8.8.8
    Error 6: Parse
    uart:~$ 
    uart:~$ ot ping 2001:4860:4860:0:0:0:0:8888
    1 packets transmitted, 0 packets received. Packet loss = 100.0%.
    Done
    uart:~$ 

    Output of OTBR:

    pi@pi:~ $ sudo ot-ctl state
    router
    Done
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ sudo ot-ctl ipaddr
    fdde:ad00:beef:0:0:ff:fe00:fc11
    fdde:ad00:beef:0:0:ff:fe00:fc38
    fd11:22:0:0:5734:5484:47b:792d
    fdde:ad00:beef:0:0:ff:fe00:fc10
    fdde:ad00:beef:0:0:ff:fe00:2400
    fdde:ad00:beef:0:cd8:cbff:1e5c:562f
    fe80:0:0:0:1c0e:8cf:728e:e245
    Done
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ sudo ot-ctl networkkey
    d6af7ff1a2fcf42743fd7a6989911d67
    Done
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ sudo ot-ctl state
    router
    Done
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ 
    pi@pi:~ $ sudo ot-ctl netdata show
    Prefixes:
    fd11:22:0:0::/64 paros med 2400
    Routes:
    fd1f:8fda:e9e0:2:0:0::/96 sn low 2400
    fd70:77a5:30f0:1437::/64 s med 2400
    Services:
    44970 5d fddead00beef00000cd8cbff1e5c562fd11f s 2400
    44970 01 76000500000e10 s 2400
    Done
    pi@pi:~ $ 
    

    Could you please tell me what could be possibly wrong in my case. 

    Regards

    Vipin Das 

  • Hi Vipin,

    It looks fd1f:8fda:e9e0:2:0:0::/96 should be used when converting your IPv4 address to IPv6.

    What if you ping  fd1f:8fda:e9e0:2:0:0:808:808 directly?

    Best regards,

    Charlie

Related