From 2b1ec9f270ccef5d3be78de710900463b906e297 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Tue, 22 Sep 2026 20:05:49 +0100 Subject: [PATCH] coap-client: Always define a token when doing a subscribe Some servers insist there being a token when a subscription Observe is initiated. --- examples/coap-client.c | 9 ++++++++- man/coap-client.txt.in | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/coap-client.c b/examples/coap-client.c index 1d3164bf..391bd98c 100644 --- a/examples/coap-client.c +++ b/examples/coap-client.c @@ -637,7 +637,8 @@ usage(const char *program, const char *version) { "\t \t\ttls_engine_conf_file contains TLS ENGINE configuration.\n" "\t \t\tSee coap-tls-engine-conf(5) for definitions.\n" "\t-s duration\tSubscribe to / Observe resource for given duration\n" - "\t \t\tin seconds\n" + "\t \t\tin seconds. If '-T token' is not used, then the initial\n" + "\t \t\ttoken is defined as non empty\n" "\t-t type\t\tContent format for given resource for PUT/POST\n" "\t-v num \t\tVerbosity level (default 4, maximum is 8) for general\n" "\t \t\tCoAP logging\n" @@ -2324,6 +2325,12 @@ main(int argc, char **argv) { } } + if (doing_observe && the_token.length == 0) { + /* Some servers insist on a token when doing observe */ + the_token.length = 1; + the_token.s[0] = 0x01; /* a token */ + } + session = get_session(ctx, node_str[0] ? node_str : NULL, port_str[0] ? port_str : NULL, diff --git a/man/coap-client.txt.in b/man/coap-client.txt.in index 23f213f8..88d054ee 100644 --- a/man/coap-client.txt.in +++ b/man/coap-client.txt.in @@ -119,7 +119,8 @@ OPTIONS - General *-s* duration:: Subscribe to / observe the resource specified by URI for the given - 'duration' in seconds. + 'duration' in seconds. If *-T token* is not used, then the initial token is + defined as non empty. *-t* type:: Content format for given resource for PUT/POST. 'type' must be either