-
Notifications
You must be signed in to change notification settings - Fork 424
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
Persisting observers #1012
Comments
Thanks for raising this. A CoAP application (client or server) needs to know where to send a packet (response or request) and it gets this information for the So in the case of sending off a "unsolicited response - i.e availability/state notifications" libcoap will require a However, once an IP tuple is established (or configured) between two CoAP endpoints, there is nothing that says only one end can be the client and the other the server. Both ends can act as a client/server in their own rights - the client/server relationship between the 2 ends can swap over at any time (even running concurrently with multiplexed requests/responses) - either end can send a request at any time with the other end responding. So with 1 of the 2 endpoints (Endpoint A - who is your rebooting device) being able to act as both a CoAP client and a CoAP server uses the CoAP client request functionality sends out a request message to the other endpoint (Endpoint B) acting as a CoAP server on a defined port who receives (and potentially acknowledges) the request. At this point, Endpoint B can elect to run as a client and send off a request to get whatever information is normally provided by Endpoint A using the same coap_session_t session. If Endpoint A uses PUT or POST for the "availability/state notifications" (as a client request), the appropriate data can be easily conveyed for Endpoint B to log/act upon etc. Endpoint A can also send out the "availability/state notifications" to a multicast address giving even more configuration flexibility. Doing things this way requires no changes to the libcoap API. I hope this helps. |
Dear Jon, thanks for your reply! I am aware of the duality of CoAP endpoints. Just changing the the notification to a request to convey the information is not an option. My challenge is that I do not have enough time to do the coding myself, but the developers cannot find it out by themselves. So I was hoping for a good initial pointer from the maintainers to derive a rough "HOWTO". So what I understand is that it should be enough to allocate a
|
To set up the Server There is a
Assuming that you only intend to observe a GET, you will need a |
Cool, thanks a lot for this run-through! I will check it against the code and try to hand it over. I will try to come back with results/observations. |
I've been having a further think about this. This would only work if (D)TLS and TCP are not being used. If the raw GET observe subscription packet (as seen on the wire) along with the 5-tuple of the request is kept, then this can be used to set up the server A secondary issue is that the unsolicited response Observe value should continue to be incremented even over a reboot. RFC7641 4.4 Reordering. In In Create a new function to set up the above callback handlers (need to be stored in Create a new callback handler for saving every n'th unsolicited observe value Create a new function This function would parse packet ( If this works for your requirements, it should not take me that long to knock up something for you to test. |
Thought so. I my case, security is enabled via OSCORE -- will see if something is required for that. For DTLS, it could be interesting to persist long-lasting sessions with connection identifier, I guess. For TCP, I am not sure if there is a "call home" option, where a server-initiated connection could inform about availability and the client simply re-observes.
Okay, have a function to set these callbacks globally and in What do you mean by "need to be stored in coap_context_t"?
Why pass the |
https://www.rfc-editor.org/rfc/rfc8613#appendix-B.2 would cover that, but Appendix B.2 may get superseded.
Possible I guess, but would need some work.
Could be done - as well as for UDP, but what the "response" trigger message is is not immediately obvious.
The handler locations need to be stored somewhere - in the CoAP context structure coap_context_t.
Yes, I realized this morning that this needs to be defined at the resource or session level (so new client observe requests are treated the same way) or perhaps at the coap_context level - so would define this at the context level at same time as the other callback handlers. In addition, libcoap just implements incrementing the observe value for each unsolicited response, rather that based on a clock tick. Probably helps here as clock ticks may get reset to 0 on a reboot. |
Apart from any OSCORE additions required, for the UDP case, I think that this should be the public API
It would be the responsibility of the server application to set up all of the resources (including any dynamically allocated ones) before |
Please see PR #1019 which support this persist observe functionality for UDP and OSCORE over UDP. Please check it out and let us know if something is not working, missing or needs clarification documentation etc. |
Dear Jon, thanks a lot for this work -- also impressive speed! |
@mkovatsc Any updates on this, or can it be closed now? |
Closing this issue for now. |
Some applications including IoT standards such as KNX IoT require that observe relationships can survive reboots of the device. Examples for uses cases are availability notifications (device is up, connected, and operational again) or state notifications over a firmware update cycle (which naturally requires a reboot).
Persisting observe relationships is also related to "unsolicited notifications": Setting up an observe relationship without a request ever arriving at the server is conceptionally similar to recovering previous observe relationships from non-volatile storage / flash during boot.
After looking into this issue, it looks to me like libcoap currently does not provide an API to do this and the dependency on context/session structs makes it hard to implement this from the application side.
The only way to realize persisting observers I have seen so far is to fully replace the observe support of libcoap with a custom one. This approach makes it easy to store and recover (or set up) observe relationships locally, but it must reimplement the resource state change and notification mechanisms.
Is there a way to persist observers or at least to register them locally without an incoming request with its context/session structs? Any pointers that could be given?
The ideal solution would be to add this support (also covering "unsolicited notifications") through the libcoap API.
The text was updated successfully, but these errors were encountered: