[riot-notifications] [RIOT-OS/RIOT] net/gcoap: add functions to read and set the next message id (#16730)

János Brodbeck notifications at github.com
Fri Aug 13 18:12:30 CEST 2021


### Contribution description

This PR adds two new functions to gcoap, which allow to read the next message ID and to set it to a given value.
Currently, the next message ID is randomly generated while init, but that is not always wanted. I need to set it manually.

I intentionally named the function "read" to make it indirectly clear that this is not part of the regular use-case of gcoap. Well, I hope it does that with this naming :D
### Testing procedure
Apply this small patch for the gcoap example:
```
diff --git a/examples/gcoap/gcoap_cli.c b/examples/gcoap/gcoap_cli.c
index f089a65c7b..ab3080b947 100644
--- a/examples/gcoap/gcoap_cli.c
+++ b/examples/gcoap/gcoap_cli.c
@@ -328,6 +328,7 @@ int gcoap_cli_cmd(int argc, char **argv)
 #endif
         printf(" CLI requests sent: %u\n", req_count);
         printf("CoAP open requests: %u\n", open_reqs);
+        printf("Next message ID: %u\n", gcoap_read_next_message_id());
         printf("Configured Proxy: ");
         if (_proxied) {
             char addrstr[IPV6_ADDR_MAX_STR_LEN];
@@ -488,6 +489,6 @@ void gcoap_cli_init(void)
         printf("gcoap: cannot add credential to DTLS sock: %d\n", res);
     }
 #endif
-
+    gcoap_set_next_message_id(10);
     gcoap_register_listener(&_listener);
 }
 ```
 
 1) `coap info` shows the next message ID. It is set to 10 by default with this patch.
 2) Send a request to a server (request does not need to succeed)
 3) Next message ID should be 11

### Issues/PRs references
You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/16730

-- Commit Summary --

  * net/gcoap: add functions to read and set the next message id

-- File Changes --

    M sys/include/net/gcoap.h (18)
    M sys/net/application_layer/gcoap/gcoap.c (10)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/16730.patch
https://github.com/RIOT-OS/RIOT/pull/16730.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16730
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210813/d4bea9be/attachment-0001.htm>


More information about the notifications mailing list