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

CoAP, CoAPS and UDP

Hi,

I use example projects  Thread: CoAP Client and  Thread: CoAP Server . I can send and receive data over CoAP. My purpose is to use CoAP, CoAPS and UDP tohether. If client send UDP message, server can reply with UDP payload or client send CoAPs, server reply same manner. How can I accomplish to send CoAPs and UDP data?

Parents
  • Hi,

    Support for CoAP, CoAPS, and UDP is all part of the prebuilt OpenThread libraries.

    You can find the API reference in our infocenter:

    All these APIs can be used in the application by including the corresponding header file, e.g:

    • #include <openthread/coap.h>
    • #include <openthread/coaps.h>
    • #include <openthread/udp.h>

    You can have a look at the use of the CoAP API usage in "examples\thread\app_utils\thread_coap_utils.c / thread_coap_utils.h"

    Best regards,
    Jørgen

  • Hey,

    i did something very similar. I modified the CoAP examples, so i can used it for plain UDP transport.

    Sending is working... fine.

    If i send a message to my device my connected receiver callback is triggered, also fine. The otMessageInfo  shows the correct sender and receiver IPv6 addresses.

    But the message-pointer is pointing anywhere.

    static bool UDPReceiverCallback(void *aContext, otMessage* aMessage, const otMessageInfo *aMessageInfo) {
      volatile otMessage* receivedMessage = aMessage;
      uint8_t buffer[64];  
      volatile uint32_t x =  aMessage->mNext;
      memcpy(&buffer, aMessage->mNext, 64);
      volatile otMessageInfo receivedMessageInfo = *(aMessageInfo);
     
      dk_set_led_on(DONGLE_GREEN_MULTI_LED);
    }

    I just send a simple string "Hello".



    How do i handle the message? Is there any example?

    I just want to reconstruct the "Hello" string

    regards,

    Sören

Reply
  • Hey,

    i did something very similar. I modified the CoAP examples, so i can used it for plain UDP transport.

    Sending is working... fine.

    If i send a message to my device my connected receiver callback is triggered, also fine. The otMessageInfo  shows the correct sender and receiver IPv6 addresses.

    But the message-pointer is pointing anywhere.

    static bool UDPReceiverCallback(void *aContext, otMessage* aMessage, const otMessageInfo *aMessageInfo) {
      volatile otMessage* receivedMessage = aMessage;
      uint8_t buffer[64];  
      volatile uint32_t x =  aMessage->mNext;
      memcpy(&buffer, aMessage->mNext, 64);
      volatile otMessageInfo receivedMessageInfo = *(aMessageInfo);
     
      dk_set_led_on(DONGLE_GREEN_MULTI_LED);
    }

    I just send a simple string "Hello".



    How do i handle the message? Is there any example?

    I just want to reconstruct the "Hello" string

    regards,

    Sören

Children
No Data
Related