-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zephyr coap client #56970
Zephyr coap client #56970
Conversation
@SeppoTakalo @juhaylinen @plskeggs please review. |
0bd6194
to
e5afa54
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs more thought before being merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good start for use cases where a single request/response at a time is all that is needed.
I wonder if there are use cases for low power IoT devices which would want to POST or PUT multiple items (for example, sensor data readings), and not wait for ACK between each one, but instead handle that at the end. Overlapping transfers could save battery life in that situation.
a84ceeb
to
e8b5cd2
Compare
e8b5cd2
to
afaef4f
Compare
/** | ||
* @brief Internal structure of CoAP client, shouldn't be modified. | ||
*/ | ||
struct coap_client { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation has a stack per CoAP client, if I were to do multiple requests at the same time, I either need to do these sequentially or create a client for each request, which is very costly.
This becomes even more apparent if I need to observe multiple server resources (long lasting requests).
It would be great if a single client could support multiple requests.
I think this is doable if you would move some members from struct coap_client
to struct coap_client_req
to keep track if a single request state. And let the client keep track of al ongoing requests (for example in a linked list).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The multiple request is planned also, and doesn't need changes to the public API.
afaef4f
to
c3800e6
Compare
struct coap_client_request *coap_request; | ||
struct coap_packet request; | ||
k_tid_t tid; | ||
struct k_thread thread; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having to spawn a separate thread for each client context seems like a lot of RAM overhead - couldn't the library have a single thread that would monitor all active requests (i. e. sockets)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any feedback on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will be done in the future, as well as the multi-request version of the client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, if there are plans to improve this in the future then I guess we can accept that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would've liked to have this functionality in this PR, as users will need to update/refactor their code in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't such a change be transparent for the applications? Yes, the application allocates the client context structure, but it's internals should not be used by the app (coap_client_init()
configures the thread).
4e65469
to
c8426f7
Compare
Nice work! Could you please add a reference to this new API to the docs, so that the Doxygen comments are rendered and people are aware that the CoAP client exists? |
Yes, I plan to do that in a separate PR and add also similar usage example as is done with the HTTP-client. |
816c33a
to
d27457d
Compare
3a557ec
to
8cf55f2
Compare
I was planning on adding the documentation to different PR, but as there was still some changes, I pushed the documentation to this PR as well. |
8cf55f2
to
15eea6c
Compare
Thank you @SeppoTakalo for your review comments, I have addressed those now. Please re-review. |
The coap client takes requests and provides responses asynchronously to callback given in a request. Currently supports only 1 request at a time. Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
Add tests for coap client and stubs for isolating the tests. Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
Sample usage and documentation of the CoAP client. Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
15eea6c
to
6e649b4
Compare
@rlubos please re-review. |
This now has 2 approvals with write access, could we get this merged in? @jukkar |
Add an asynchronous coap client.
The coap client processes requests, sends those to server and awaits for response.
Currently supports 1 request at a time.