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

Coap message type, confirmable/non-confirmable

Hello,

I am using the coap Client example from nRF Connect SDK, which uses the Coap utils library https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/net/coap_utils.html

As stated in the documentation, this library only enables non-confirmable communication, since in the source file ncs\nrf\subsys\net\lib\coap_utils\coap_utils.c, the application level function used, coap_send_request(), calls coap_init_request() with hardcoded COAP_TYPE_NON_CON coap_msgtype. I reckon changing this would not help. How can I achieve confirmable communication with the coap client example? Do I need to enable another coap library than coap utils?

The coap server example, which uses the openthread coap api, however, calls otCoapMessageInit()  at application level, which takes an otCoapType aType argument. Thus, it looks like the openthread coap api supports confirmable coap communication. Is this correct? I have not tested this yet.

Another thing, in the header of coap_send_request() in coap_utils.h, it says

 * @retval 0    On success.
 * @retval != 0 On failure.
However, the return value of the functions called from in coap_send_request() is only checked against a negative value. Indeed, according to the headers of the functions called in coap_init_request(), which is called by coap_send_request(), only a negative value should indicate an error. The second and last function returning an error code in coap_send_request() is coap_send_message(), but I cannot find any documentation of the return value of sendto() called by this function. Is the header of coap_send_request() wrong?
I have seen return values such as e.g. 38 and 48 from my coap_send_request() calls, but I am still receiving the packets. So what do these numbers indicate?