From 88789454dd1e7e24481e229295cee285d0403495 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 23 Feb 2023 00:30:34 +0100 Subject: [PATCH] examples/nanocoap_server: enable fileserver for large boards --- examples/nanocoap_server/Makefile | 19 ++++++++++++++++++- examples/nanocoap_server/coap_handler.c | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/examples/nanocoap_server/Makefile b/examples/nanocoap_server/Makefile index 265d73c6f0..4d2fe9afc2 100644 --- a/examples/nanocoap_server/Makefile +++ b/examples/nanocoap_server/Makefile @@ -18,7 +18,7 @@ USEMODULE += sock_udp USEMODULE += gnrc_icmpv6_echo USEMODULE += nanocoap_sock -USEMODULE += nanocoap_server +USEMODULE += nanocoap_resources USEMODULE += xtimer @@ -43,6 +43,23 @@ ifneq (,$(filter $(BOARD),$(LOW_MEMORY_BOARDS))) USEMODULE += prng_minstd endif +# Enable fileserver for boards with plenty of memory +HIGH_MEMORY_BOARDS := native same54-xpro mcb2388 + +ifneq (,$(filter $(BOARD),$(HIGH_MEMORY_BOARDS))) + USEMODULE += gcoap_fileserver + USEMODULE += vfs_default + + # we don't want to run GCoAP + CFLAGS += -DCONFIG_GCOAP_NO_AUTO_INIT=1 + CFLAGS += -DCONFIG_NANOCOAP_SERVER_WELL_KNOWN_CORE=1 + + # always enable auto-format for native + ifeq ($(BOARD),native) + USEMODULE += vfs_auto_format + endif +endif + # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 diff --git a/examples/nanocoap_server/coap_handler.c b/examples/nanocoap_server/coap_handler.c index 8a7e8d08f8..6bffe8b224 100644 --- a/examples/nanocoap_server/coap_handler.c +++ b/examples/nanocoap_server/coap_handler.c @@ -181,3 +181,23 @@ NANOCOAP_RESOURCE(ver) { NANOCOAP_RESOURCE(sha256) { .path = "/sha256", .methods = COAP_POST, .handler = _sha256_handler }; + +/* we can also include the fileserver module */ +#ifdef MODULE_GCOAP_FILESERVER +#include "net/gcoap/fileserver.h" +#include "vfs_default.h" + +NANOCOAP_RESOURCE(fileserver) { + .path = "/vfs", + .methods = COAP_GET +#if IS_USED(MODULE_GCOAP_FILESERVER_PUT) + | COAP_PUT +#endif +#if IS_USED(MODULE_GCOAP_FILESERVER_DELETE) + | COAP_DELETE +#endif + | COAP_MATCH_SUBTREE, + .handler = gcoap_fileserver_handler, + .context = VFS_DEFAULT_DATA +}; +#endif