Skip to content

Commit

Permalink
examples/nanocoap_server: enable fileserver for large boards
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Feb 28, 2023
1 parent 4b4c36e commit 8d9a464
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
18 changes: 17 additions & 1 deletion examples/nanocoap_server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ USEMODULE += sock_udp
USEMODULE += gnrc_icmpv6_echo

USEMODULE += nanocoap_sock
USEMODULE += nanocoap_server
USEMODULE += nanocoap_resources

USEMODULE += xtimer

Expand All @@ -43,6 +43,22 @@ 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

# 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

Expand Down
20 changes: 20 additions & 0 deletions examples/nanocoap_server/coap_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8d9a464

Please sign in to comment.