diff --git a/examples/nanocoap_server/Makefile b/examples/nanocoap_server/Makefile index 7f2520df74..265d73c6f0 100644 --- a/examples/nanocoap_server/Makefile +++ b/examples/nanocoap_server/Makefile @@ -18,6 +18,7 @@ USEMODULE += sock_udp USEMODULE += gnrc_icmpv6_echo USEMODULE += nanocoap_sock +USEMODULE += nanocoap_server USEMODULE += xtimer diff --git a/examples/nanocoap_server/coap_handler.c b/examples/nanocoap_server/coap_handler.c index 09ea785ed2..8a7e8d08f8 100644 --- a/examples/nanocoap_server/coap_handler.c +++ b/examples/nanocoap_server/coap_handler.c @@ -166,14 +166,18 @@ ssize_t _sha256_handler(coap_pkt_t* pkt, uint8_t *buf, size_t len, coap_request_ return pkt_pos - (uint8_t*)pkt->hdr; } -/* must be sorted by path (ASCII order) */ -const coap_resource_t coap_resources[] = { - COAP_WELL_KNOWN_CORE_DEFAULT_HANDLER, - { "/echo/", COAP_GET | COAP_MATCH_SUBTREE, _echo_handler, NULL }, - { "/riot/board", COAP_GET, _riot_board_handler, NULL }, - { "/riot/value", COAP_GET | COAP_PUT | COAP_POST, _riot_value_handler, NULL }, - { "/riot/ver", COAP_GET, _riot_block2_handler, NULL }, - { "/sha256", COAP_POST, _sha256_handler, NULL }, +NANOCOAP_RESOURCE(echo) { + .path = "/echo/", .methods = COAP_GET | COAP_MATCH_SUBTREE, .handler = _echo_handler +}; +NANOCOAP_RESOURCE(board) { + .path = "/riot/board", .methods = COAP_GET, .handler = _riot_board_handler +}; +NANOCOAP_RESOURCE(value) { + .path = "/riot/value", .methods = COAP_GET | COAP_PUT | COAP_POST, .handler = _riot_value_handler +}; +NANOCOAP_RESOURCE(ver) { + .path = "/riot/ver", .methods = COAP_GET, .handler = _riot_block2_handler +}; +NANOCOAP_RESOURCE(sha256) { + .path = "/sha256", .methods = COAP_POST, .handler = _sha256_handler }; - -const unsigned coap_resources_numof = ARRAY_SIZE(coap_resources);