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

OpenThread CoAP example

Hello, I'm using the openthread border router (wpantund) along with another end device running the simple_coap_server example that exposes a "light" resource.

I have connectivity to the device and using the firefox copper plugin I can do a "PUT" to: "coap://[IPV6 ADDRESS]/light"

and get back a "2.04 Changed". So it appears I have good connectivity but when I try to pass in a command to the resource I get a 4.04 response. The URI's I have tried are: "coap://[IPV6 ADDRESS]/light/light_on" and "coap://[IPV6 ADDRESS]/light/light_off"

Neither of these change the LED and I get a 4.04 response.

Any ideas what might be happening?

Setup: Raspberry Pi3 running openthread border router --> 52840 dev kit (running ot-ncp-ftd) Another 52840 dev kit running the thread sdk version 10 Thread Simple CoAP Server

  • Hello Danny,

    Thank you for trying out nRF5 SDK for Thread!

    The particular example that you used (simple_coap_server) exposes only two resources:

    • /light
    • /provisioning

    You received 4.04 responses (Not Found) for /light/light_on or /light/light_off resources since they do not exist.

    Simple coap server controls its led using payload of PUT request on /light resource. Accepted payload is:

    • 0 (Turn off the led)
    • 1 (Turn on the led)
    • 2 (Toggle the led)

    Note that you can specify payload also in the copper plugin: Payload section -> Outgoing tab. The difficult part is that Cooper plugin allows only to send ASCII string. However the example expects binary 0, 1 or 2, not character '0' which is binary 48. So i believe the easiest solution to use cooper would be to change light_command_t enum in the main.c to:

    typedef enum
    {
        LIGHT_OFF = '0', // originally was 0, (0 is different than ASCII '0' - which is 48)
        LIGHT_ON,
        LIGHT_TOGGLE
    } light_command_t;
    

    Of course it is possible to add a new resources: /light/light_on and /light/light_off by modyfing SDK's example.

    We will try to change expected commands value to accept also ASCII characters in upcoming releases to make Cooper plugin easier to use.

  • Thanks Lukasz!, that totally solved it. Time to start adding some new resources!

Related