OpenThread COAP Client to a public server over Internet

Hello,

I am trying to make a Thread COAP Client on nRF52840 DK work with coap.me public server. I have created a Border Router with a Raspberry Pi and a nRF52 dongle and I am sure that it works as I can ping and run COAP CLI commands successfully with the OpenThread CLI sample. I can COAP GET and PUT to coap.me.

The coap.me IPv6 address was converted by me with the well known 64:ff9b::/96 prefix. The path was added to the border router as I can see with ot netdata show. 

The problem is with the COAP Client sample provided. I modified the destination IPv6 address to be the same I use with the CLI sample and the URI path to "coap://coap.me:5683/hello". I have also tried just "hello". No luck so far. 

As I said the CLI sample works fine: I get a response which is "world". Here the CLI commands I use after having joined the Thread network:

ot coap start

ot coap get 64:ff9b:0:0:0:0:8666:da12 hello 

NOTE: in my COAP client program the Thread network is joined automatically as I have added the following options:

CONFIG_OPENTHREAD_JOINER=y
CONFIG_OPENTHREAD_JOINER_AUTOSTART=y
CONFIG_OPENTHREAD_JOINER_PSKD="J01NME"

Indeed I can ping the Border router IPV6 address from my board running the modified COAP Client and vice-versa so they see each other. 

Can you please help to understand why my program directly derived from your COAP client sample does not work while CLI works fine?

Thank you.

Marco

Parents
  • Hi Marco,

    I still need to work on some issues with my OTBR.

    If your CLI command "ot coap get 64:ff9b:0:0:0:0:8666:da12 hello" works on your setup, you can test with the following coap client sample provided by our developer: GitHub - canisLupus1313/ot-sensor

    It basically send "hello" GET request to coap.me and prints out the reply "world". Please remember to modify the following configuration to join your OTBR-formed thread network.

    CONFIG_OPENTHREAD_NETWORKKEY="00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff"
    CONFIG_OPENTHREAD_NETWORK_NAME="OpenThread-7cf7"
    CONFIG_OPENTHREAD_XPANID="3b:78:ce:62:9c:bc:8e:23"
    CONFIG_OPENTHREAD_PANID=31991

    Best regards,

    Charlie

Reply
  • Hi Marco,

    I still need to work on some issues with my OTBR.

    If your CLI command "ot coap get 64:ff9b:0:0:0:0:8666:da12 hello" works on your setup, you can test with the following coap client sample provided by our developer: GitHub - canisLupus1313/ot-sensor

    It basically send "hello" GET request to coap.me and prints out the reply "world". Please remember to modify the following configuration to join your OTBR-formed thread network.

    CONFIG_OPENTHREAD_NETWORKKEY="00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff"
    CONFIG_OPENTHREAD_NETWORK_NAME="OpenThread-7cf7"
    CONFIG_OPENTHREAD_XPANID="3b:78:ce:62:9c:bc:8e:23"
    CONFIG_OPENTHREAD_PANID=31991

    Best regards,

    Charlie

Children
  • Hi Charlie,

    yes the CLI command works fine. The sample code you provided does exactly what I am trying to do. It looks the same of my code but I am gonna try it out to see if that works in my environment.

    I'll let you know.

    Thanks.

  • Hi Charlie, 

    I tried the code shared by your developer and it works fine! I do not know what the difference is with my original code so I'll look into it. Anyway I guess I can consider this issue solved for now.

    Thank you for your help. 

  • Hi Marco and/or Charlie,

    Thanks for this thread. I am also trying the same - CoAP Client to CoAP server running in OTBR (Raspberry pi) at Ipv4 side for internet view. I am also trying to get data via UART into CoAP-client and then send it to CoAP-Server in OTBR. Facing many issues.   

    If you can share your codes and/or link to your codes, it will be helpful.  

    Thanks in advance. 

    Arun

  • Hi Arun, I can't share my code for contract reasons as I am working for a customer of mine. Anyway the source code shared above Charlie is still available and it is what I based my application on. However I am using IPv6 address as I could not make it work on IPv4 as you need. So I suggest you to obtain the IPv6 address from the server IPv4 one.

    bool COMM_getIpv6Address( uint8_t *ipv4_addr, struct in6_addr *ipv6_addr )
    {
    int i;
    otIp4Address tmp_ipv4_addr;
    otIp6Address synt_ipv6_addr;
    struct openthread_context *ot = ot_context;
    
    for (i=0; i<4; i++)
    {
    tmp_ipv4_addr.mFields.m8[i] = ipv4_addr[i];
    }
    
    if (OT_ERROR_NONE != otNat64SynthesizeIp6Address(
    ot->instance,
    (const otIp4Address *)&tmp_ipv4_addr,
    &synt_ipv6_addr))
    {
    LOG_ERR("ERROR otNat64SynthesizeIp6Address() function!");
    return false;
    }
    
    for (i=0; i<16; i++)
    {
    ipv6_addr->s6_addr[i] = synt_ipv6_addr.mFields.m8[i];
    }
    
    return true;
    }
    The Border Router must have the NAT64 (or equivalent) enabled and I think that latest OpenThread Border Router release has it already enabled by default.
    I hope it helps.
    Cheers.
    Marco
  • Thanks Marco,

    Since I am a beginner, pls also help which header files are required and how to define all variables.

    Also - where do I give my OTBR IPv4 address in this? 

    Thanks in advance for your help. 

    Regards

    Arun

Related