COAP_CLIENT_LIB request issue

Hi.

I'm using nrf Connect SDK v3.0.1 and Zephyr v4.0.99 to implement a IoT device which connects to a Thingsboard server with CoAP. With the COAP_CLIENT Lib I want to download data in 945 chunks of 512 byte size.

I've used the coap_download example as a template for my implementation. I create the request and send it to the library with coap_client_req(). When the server responds, the callback function gets called in which I process the data (copy it to a queue in my case) and give a sem to tell the coap thread to cancel the request (coap_client_cancel_request()). This works as many times as I have configured in CONFIG_COAP_CLIENT_MAX_REQUESTS. After that the lib reports an error "No more free requests".

It looks for me that the cancel of the request didn't work. But maybe I didn't understand the usage of the COAP_CLIENT lib.
Are there any hints to use it correctly?

Thanks
BR
Christian

Parents
  • Hi Christian,

    Thanks for reaching out!

    CONFIG_COAP_CLIENT_MAX_REQUESTS is not a counter of how many requests you may send during the program’s lifetime. It is the number of simultaneous exchanges a single coap_client instance is allowed to keep in its internal array (client->requests[]).

    If every time you call coap_client_req() the previous exchange has not been released yet, a new slot is taken.

    When all CONFIG_COAP_CLIENT_MAX_REQUESTS slots are still marked as “busy”, the library prints “No more free requests” .

    A slot is released after the library has delivered the last fragment of the response to the application and
    your response-callback has returned.

    Without looking at you code I guess the main thing you are not doing correctly is that you start a new request for every 512-byte chunk?

    I hope this helps push you in the right direction.

    Best regards,

    Benjamin

Reply
  • Hi Christian,

    Thanks for reaching out!

    CONFIG_COAP_CLIENT_MAX_REQUESTS is not a counter of how many requests you may send during the program’s lifetime. It is the number of simultaneous exchanges a single coap_client instance is allowed to keep in its internal array (client->requests[]).

    If every time you call coap_client_req() the previous exchange has not been released yet, a new slot is taken.

    When all CONFIG_COAP_CLIENT_MAX_REQUESTS slots are still marked as “busy”, the library prints “No more free requests” .

    A slot is released after the library has delivered the last fragment of the response to the application and
    your response-callback has returned.

    Without looking at you code I guess the main thing you are not doing correctly is that you start a new request for every 512-byte chunk?

    I hope this helps push you in the right direction.

    Best regards,

    Benjamin

Children
Related