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
  • Maybe this is either a limitation or a bug in zephyr's "coap_client" implementation (NCS 2.9.1 / zephyr v3.7.99).

    The "get_free_request" uses "exchange_lifetime_exceeded" and that extends the "usage" of the internal request for "3 * ack_timeout", even after the call of "coap_client_cancel_request"!

    Not sure, if using "pending.params.ack_timeout" and not "pending.timeout" is really well, but that's more a question to the developers of that code and their considerations.

    This limits the number of possible requests per time. Assuming an "ack_timeout" of 2s, each internal request may only be used every 6s. With 6 CONFIG_COAP_CLIENT_MAX_REQUESTS that will result in 1 request per second.    

    I guess, it requires an ticket in the zephyr project to fix it or the get aware, how to handle that case proper.

    (See zephyr discussions 92723 ).

    Edit:

    Just as short term work-around:

    If coap_client_req returns -EAGAIN, that's not a sticky error. If the client delays the next call to coap_client_req it will work. You may need to consider the CONFIG_COAP_CLIENT_MAX_REQUESTS and the 6s to estimate a good value for the delay.

  • Just as info, the outcome of the zephyr discussions 92723 

    The extra timespan was addressed in March this year, but it will take some time to have that in the NCS.

Reply Children
No Data
Related