Skip to content

Commit

Permalink
examples/nanocoap_server: add nanocoap_ws support
Browse files Browse the repository at this point in the history
And test this on native with CoAP over WebSocket+YOLO
  • Loading branch information
maribu committed Jan 7, 2025
1 parent 08ae545 commit 6ba6163
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/nanocoap_server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ ifneq (,$(filter $(BOARD),$(HIGH_MEMORY_BOARDS)))
endif

USEMODULE += nanocoap_server_ws
USEMODULE += nanocoap_ws_udp_yolo

# async TCP is not supported on GNRC yet
ifeq ($(NETWORK_STACK),lwip)
Expand Down
12 changes: 12 additions & 0 deletions examples/nanocoap_server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
static nanocoap_tcp_server_ctx_t tcp_ctx;
#endif

#if MODULE_NANOCOAP_SERVER_WS && MODULE_NANOCOAP_WS_UDP_YOLO
static coap_ws_over_udp_yolo_init_arg_t _ws_ctx;
#endif

int main(void)
{
puts("RIOT nanocoap example application");
Expand All @@ -52,12 +56,20 @@ int main(void)

#if MODULE_NANOCOAP_SERVER_TCP
nanocoap_server_tcp(&tcp_ctx, EVENT_PRIO_MEDIUM, NULL);
printf("CoAP+TCP on PORT %u\n", (unsigned)tcp_ctx.local.port);
#endif

#if MODULE_NANOCOAP_SERVER_WS && MODULE_NANOCOAP_WS_UDP_YOLO
sock_udp_ep_t local_ws = { .port = 1337, .family = AF_INET6 };
nanocoap_server_ws(&coap_ws_over_udp_yolo, &_ws_ctx, &local_ws, sizeof(local_ws));
printf("CoAP+YOLO on PORT %u\n", (unsigned)local_ws.port);
#endif

#if MODULE_NANOCOAP_UDP
/* initialize nanocoap server instance */
uint8_t buf[COAP_INBUF_SIZE];
sock_udp_ep_t local = { .port=COAP_PORT, .family=AF_INET6 };
printf("CoAP (UDP) on PORT %u\n", (unsigned)local.port);
nanocoap_server_udp(&local, buf, sizeof(buf));
#endif

Expand Down

0 comments on commit 6ba6163

Please sign in to comment.