diff --git a/examples/riot/Makefile b/examples/riot/Makefile index 5e03bbf2..a17e5795 100644 --- a/examples/riot/Makefile +++ b/examples/riot/Makefile @@ -50,18 +50,20 @@ pkg: fi examples: - rm -rf RIOT/examples/networking/libcoap/libcoap_client && mkdir -p RIOT/examples/networking/libcoap/libcoap_client - cd examples_libcoap_client && cp -r * ../RIOT/examples/networking/libcoap/libcoap_client - rm -rf RIOT/examples/networking/libcoap/libcoap_server && mkdir -p RIOT/examples/networking/libcoap/libcoap_server - cd examples_libcoap_server && cp -r * ../RIOT/examples/networking/libcoap/libcoap_server + rm -rf RIOT/examples/networking/libcoap/libcoap_client && \ + rm -rf RIOT/examples/networking/coap/libcoap_client && mkdir -p RIOT/examples/networking/coap/libcoap_client + cd examples_libcoap_client && cp -r * ../RIOT/examples/networking/coap/libcoap_client + rm -rf RIOT/examples/networking/libcoap/libcoap_server && \ + rm -rf RIOT/examples/networking/coap/libcoap_server && mkdir -p RIOT/examples/networking/coap/libcoap_server + cd examples_libcoap_server && cp -r * ../RIOT/examples/networking/coap/libcoap_server rm -rf RIOT/tests/pkg/libcoap && mkdir -p RIOT/tests/pkg/libcoap cd tests_pkg_libcoap && cp -r * ../RIOT/tests/pkg/libcoap client: RIOT pkg examples - $(MAKE) -C RIOT/examples/networking/libcoap/libcoap_client/ RIOT_CI_BUILD=1 + $(MAKE) -C RIOT/examples/networking/coap/libcoap_client/ RIOT_CI_BUILD=1 server: RIOT pkg examples - $(MAKE) -C RIOT/examples/networking/libcoap/libcoap_server/ RIOT_CI_BUILD=1 + $(MAKE) -C RIOT/examples/networking/coap/libcoap_server/ RIOT_CI_BUILD=1 tests: RIOT pkg examples $(MAKE) -C RIOT/tests/pkg/libcoap/ RIOT_CI_BUILD=1 @@ -71,6 +73,6 @@ run_tests: clean: rm -rf RIOT/pkg/libcoap - rm -rf RIOT/examples/libcoap-client - rm -rf RIOT/examples/libcoap-server + rm -rf RIOT/examples/networking/coap/libcoap-client + rm -rf RIOT/examples/networking/coap/libcoap-server rm -rf RIOT/tests/pkg/libcoap diff --git a/examples/riot/examples_libcoap_client/README.md b/examples/riot/examples_libcoap_client/README.md index eaa7456e..d95caf36 100644 --- a/examples/riot/examples_libcoap_client/README.md +++ b/examples/riot/examples_libcoap_client/README.md @@ -6,13 +6,17 @@ This example shows how to configure a client to use libcoap Preparing the logical interfaces: - sudo ./../../dist/tools/tapsetup/tapsetup --create 2 +```shell +sudo ./../../dist/tools/tapsetup/tapsetup --create 2 +``` ## Client invocation For the client: - PORT=tap0 make term - coapc coap://[ip6-address]/some/path +```shell +PORT=tap0 make term +coapc coap://[ip6-address]/some/path +``` The IP address to connect to needs to be that as returned by libcoap_server, or that of the tap0 interface, etc. diff --git a/examples/riot/examples_libcoap_client/app.config b/examples/riot/examples_libcoap_client/app.config index e25b135c..b23a479a 100644 --- a/examples/riot/examples_libcoap_client/app.config +++ b/examples/riot/examples_libcoap_client/app.config @@ -6,3 +6,4 @@ CONFIG_LIBCOAP_USE_PSK="secretPSK" CONFIG_LIBCOAP_USE_PSK_ID="user_abc" # Logging levels are defined in pkg/libcoap using Kconfig +CONFIG_LIBCOAP_LOG_INFO=y diff --git a/examples/riot/examples_libcoap_client/client_coap.c b/examples/riot/examples_libcoap_client/client_coap.c index 0574900e..458c94be 100644 --- a/examples/riot/examples_libcoap_client/client_coap.c +++ b/examples/riot/examples_libcoap_client/client_coap.c @@ -53,10 +53,10 @@ static int is_mcast = 0; unsigned int wait_seconds = DEFAULT_WAIT_TIME; /* default timeout in seconds */ -static coap_response_t message_handler(coap_session_t *session, - const coap_pdu_t *sent, - const coap_pdu_t *received, - const coap_mid_t id) +static coap_response_t response_handler(coap_session_t *session, + const coap_pdu_t *sent, + const coap_pdu_t *received, + const coap_mid_t id) { const uint8_t *data; size_t len; @@ -204,7 +204,8 @@ void client_coap_init(int argc, char **argv) memset(&dtls_psk, 0, sizeof(dtls_psk)); dtls_psk.version = COAP_DTLS_CPSK_SETUP_VERSION; - snprintf(client_sni, sizeof(client_sni), "%*.*s", (int)uri.host.length, (int)uri.host.length, uri.host.s); + snprintf(client_sni, sizeof(client_sni), "%*.*s", (int)uri.host.length, + (int)uri.host.length, uri.host.s); dtls_psk.client_sni = client_sni; dtls_psk.psk_info.identity.s = (const uint8_t *)COAP_USE_PSK_ID; dtls_psk.psk_info.identity.length = strlen(COAP_USE_PSK_ID); @@ -224,7 +225,7 @@ void client_coap_init(int argc, char **argv) goto fail; } - coap_register_response_handler(main_coap_context, message_handler); + coap_register_response_handler(main_coap_context, response_handler); coap_register_nack_handler(main_coap_context, nack_handler); /* construct CoAP message */ diff --git a/examples/riot/examples_libcoap_server/README.md b/examples/riot/examples_libcoap_server/README.md index ed6458c6..2b179efd 100644 --- a/examples/riot/examples_libcoap_server/README.md +++ b/examples/riot/examples_libcoap_server/README.md @@ -6,17 +6,23 @@ This example shows how to configure a server to use libcoap Preparing the logical interfaces: - sudo ./../../dist/tools/tapsetup/tapsetup --create 2 +```shell +sudo ./../../dist/tools/tapsetup/tapsetup --create 2 +``` ## Server invocation For the server: - PORT=tap0 make term - coaps {stop|start} +```shell +PORT=tap0 make term +coaps {stop|start} +``` The server supports requests for - coap://[ip]/time?ticks - coap://[ip]/.well-known/core +```shell +coap://[ip]/time?ticks +coap://[ip]/.well-known/core +``` ## Handling the static memory allocation diff --git a/examples/riot/examples_libcoap_server/app.config b/examples/riot/examples_libcoap_server/app.config index d1b78829..de9864dc 100644 --- a/examples/riot/examples_libcoap_server/app.config +++ b/examples/riot/examples_libcoap_server/app.config @@ -3,6 +3,7 @@ CONFIG_LIBCOAP_SERVER_SUPPORT=y CONFIG_LIBCOAP_USE_PSK="secretPSK" # Logging levels are defined in pkg/libcoap using Kconfig +CONFIG_LIBCOAP_LOG_INFO=y CONFIG_DTLS_PEER_MAX=2 CONFIG_DTLS_HANDSHAKE_MAX=2 diff --git a/examples/riot/examples_libcoap_server/server_coap.c b/examples/riot/examples_libcoap_server/server_coap.c index d38d99aa..5a0d9c8c 100644 --- a/examples/riot/examples_libcoap_server/server_coap.c +++ b/examples/riot/examples_libcoap_server/server_coap.c @@ -98,26 +98,13 @@ static void init_coap_resources(coap_context_t *ctx) coap_resource_set_get_observable(r, 1); time_resource = r; coap_register_handler(r, COAP_REQUEST_GET, hnd_get_time); -#if 0 - coap_register_handler(r, COAP_REQUEST_PUT, hnd_put_time); - coap_register_handler(r, COAP_REQUEST_DELETE, hnd_delete_time); -#endif coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0); - /* coap_add_attr(r, coap_make_str_const("title"), - coap_make_str_const("\"Internal Clock\""), 0); */ + coap_add_attr(r, coap_make_str_const("title"), + coap_make_str_const("\"Internal Clock\""), 0); coap_add_attr(r, coap_make_str_const("rt"), coap_make_str_const("\"ticks\""), 0); coap_add_attr(r, coap_make_str_const("if"), coap_make_str_const("\"clock\""), 0); coap_add_resource(ctx, r); -#if 0 - if (coap_async_is_supported()) { - r = coap_resource_init(coap_make_str_const("async"), 0); - coap_register_handler(r, COAP_REQUEST_GET, hnd_get_async); - - coap_add_attr(r, coap_make_str_const("ct"), coap_make_str_const("0"), 0); - coap_add_resource(ctx, r); - } -#endif return; error: diff --git a/examples/riot/pkg_libcoap/Kconfig b/examples/riot/pkg_libcoap/Kconfig index 85f1c297..a97d5800 100644 --- a/examples/riot/pkg_libcoap/Kconfig +++ b/examples/riot/pkg_libcoap/Kconfig @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2019 HAW Hamburg +# SPDX-FileCopyrightText: 2019 HAW Hamburg # SPDX-License-Identifier: BSD-2-Clause menu "libcoap" diff --git a/examples/riot/pkg_libcoap/Makefile b/examples/riot/pkg_libcoap/Makefile index b0b4fc42..d147588a 100644 --- a/examples/riot/pkg_libcoap/Makefile +++ b/examples/riot/pkg_libcoap/Makefile @@ -1,7 +1,7 @@ PKG_NAME=libcoap PKG_URL=https://github.com/obgm/libcoap -# develop branch as of 19th May 2026 -PKG_VERSION=db7b7e82079dda6819f023ffe7e62ea4ace69fb4 +# develop branch as of 20th July 2026 +PKG_VERSION=1122bf9fb936a50e1f35c66cab7b0b5f5832d25c PKG_LICENSE=BSD-2-Clause LIBCOAP_BUILD_DIR=$(BINDIR)/pkg/$(PKG_NAME) diff --git a/examples/riot/pkg_libcoap/Makefile.libcoap b/examples/riot/pkg_libcoap/Makefile.libcoap index 734f8959..c5245b4d 100644 --- a/examples/riot/pkg_libcoap/Makefile.libcoap +++ b/examples/riot/pkg_libcoap/Makefile.libcoap @@ -20,6 +20,7 @@ SRC := coap_address.c \ coap_net.c \ coap_netif.c \ coap_notls.c \ + coap_openhitls.c\ coap_openssl.c\ coap_option.c \ coap_oscore.c \ @@ -33,8 +34,10 @@ SRC := coap_address.c \ coap_strm_riot.c \ coap_subscribe.c \ coap_threadsafe.c \ + coap_time.c \ coap_tinydtls.c \ coap_uri.c \ + coap_wolfssl.c \ coap_ws.c ifneq (,$(filter libcoap_tinydtls,$(USEMODULE))) diff --git a/examples/riot/tests_pkg_libcoap/README.md b/examples/riot/tests_pkg_libcoap/README.md index 83d68502..5eff2877 100644 --- a/examples/riot/tests_pkg_libcoap/README.md +++ b/examples/riot/tests_pkg_libcoap/README.md @@ -4,4 +4,8 @@ This test is to check that the libcoap client and server logic talk to each other. The client request generates a CoAP request, which is sent to the server -who responds back to the client. +who responds back to the client with the following + +``` +This is DTLS loopback test client/server made with libcoap's response +``` diff --git a/examples/riot/tests_pkg_libcoap/libcoap-test.c b/examples/riot/tests_pkg_libcoap/libcoap-test.c index e0929d12..2cf5d0e4 100644 --- a/examples/riot/tests_pkg_libcoap/libcoap-test.c +++ b/examples/riot/tests_pkg_libcoap/libcoap-test.c @@ -149,10 +149,10 @@ static int resolve_address(const char *host, const char *service, return ret; } -static coap_response_t message_handler(coap_session_t *session, - const coap_pdu_t *sent, - const coap_pdu_t *received, - const coap_mid_t id) +static coap_response_t response_handler(coap_session_t *session, + const coap_pdu_t *sent, + const coap_pdu_t *received, + const coap_mid_t id) { const uint8_t *data; size_t len; @@ -249,7 +249,7 @@ static int coap_client_init(coap_context_t *ctx) goto fail; } - coap_register_response_handler(ctx, message_handler); + coap_register_response_handler(ctx, response_handler); /* construct CoAP message */ pdu = coap_pdu_init(COAP_MESSAGE_CON,