Skip to content

Commit

Permalink
examples/nanocoap_server: define CoAP resources as XFA
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Feb 21, 2023
1 parent 1fb9a75 commit e7a97fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/nanocoap_server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ USEMODULE += sock_udp
USEMODULE += gnrc_icmpv6_echo

USEMODULE += nanocoap_sock
USEMODULE += nanocoap_server_xfa

USEMODULE += xtimer

Expand Down
16 changes: 5 additions & 11 deletions examples/nanocoap_server/coap_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,8 @@ 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 },
};

const unsigned coap_resources_numof = ARRAY_SIZE(coap_resources);
ADD_COAP_RESOURCE(_echo) { "/echo/", COAP_GET | COAP_MATCH_SUBTREE, _echo_handler, NULL };
ADD_COAP_RESOURCE(_board) { "/riot/board", COAP_GET, _riot_board_handler, NULL };
ADD_COAP_RESOURCE(_value) { "/riot/value", COAP_GET | COAP_PUT | COAP_POST, _riot_value_handler, NULL };
ADD_COAP_RESOURCE(_ver) { "/riot/ver", COAP_GET, _riot_block2_handler, NULL };
ADD_COAP_RESOURCE(_sha256) { "/sha256", COAP_POST, _sha256_handler, NULL };

0 comments on commit e7a97fb

Please sign in to comment.