From d4db82c39b11d102f5999b194fcb01733ff8c1ba Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 15 Apr 2022 18:30:02 +0200 Subject: [PATCH] examples/gcoap_fileserver: add CoAP fileserver example --- examples/gcoap_fileserver/Makefile | 35 ++++++++++++++++++ examples/gcoap_fileserver/Makefile.ci | 44 +++++++++++++++++++++++ examples/gcoap_fileserver/main.c | 52 +++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 examples/gcoap_fileserver/Makefile create mode 100644 examples/gcoap_fileserver/Makefile.ci create mode 100644 examples/gcoap_fileserver/main.c diff --git a/examples/gcoap_fileserver/Makefile b/examples/gcoap_fileserver/Makefile new file mode 100644 index 0000000000..364ebfa52f --- /dev/null +++ b/examples/gcoap_fileserver/Makefile @@ -0,0 +1,35 @@ +# name of your application +APPLICATION = gcoap_fileserver + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +# Modules to include: +USEMODULE += shell +USEMODULE += shell_commands + +# enable the fileserver module +USEMODULE += gcoap_fileserver + +# select network modules +USEMODULE += gnrc_ipv6_default +USEMODULE += auto_init_gnrc_netif +USEMODULE += netdev_default +USEMODULE += gnrc_icmpv6_echo + +# enable default file system mount points +USEMODULE += vfs_default +# USEMODULE += vfs_auto_format + +include $(RIOTBASE)/Makefile.include diff --git a/examples/gcoap_fileserver/Makefile.ci b/examples/gcoap_fileserver/Makefile.ci new file mode 100644 index 0000000000..ed67dce176 --- /dev/null +++ b/examples/gcoap_fileserver/Makefile.ci @@ -0,0 +1,44 @@ +BOARD_INSUFFICIENT_MEMORY := \ + arduino-duemilanove \ + arduino-leonardo \ + arduino-mega2560 \ + arduino-nano \ + arduino-uno \ + atmega1284p \ + atmega328p \ + atmega328p-xplained-mini \ + atxmega-a3bu-xplained \ + blackpill \ + bluepill \ + bluepill-stm32f030c8 \ + derfmega128 \ + i-nucleo-lrwan1 \ + mega-xplained \ + microduino-corerf \ + msb-430 \ + msb-430h \ + nucleo-f030r8 \ + nucleo-f031k6 \ + nucleo-f042k6 \ + nucleo-f302r8 \ + nucleo-f303k8 \ + nucleo-f334r8 \ + nucleo-l011k4 \ + nucleo-l031k6 \ + nucleo-l053r8 \ + samd10-xmini \ + saml10-xpro \ + saml11-xpro \ + slstk3400a \ + stk3200 \ + stm32f030f4-demo \ + stm32f0discovery \ + stm32f7508-dk \ + stm32g0316-disco \ + stm32l0538-disco \ + stm32mp157c-dk2 \ + telosb \ + waspmote-pro \ + z1 \ + zigduino \ + # diff --git a/examples/gcoap_fileserver/main.c b/examples/gcoap_fileserver/main.c new file mode 100644 index 0000000000..069c94c653 --- /dev/null +++ b/examples/gcoap_fileserver/main.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Example application for demonstrating the GCoAP file server + * + * @author Benjamin Valentin + * @} + */ + +#include "net/gcoap.h" +#include "net/gcoap/fileserver.h" +#include "shell.h" +#include "vfs_default.h" + +#define MAIN_QUEUE_SIZE (4) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +static const gcoap_fileserver_entry_t _vfs_entry = { + .root = VFS_DEFAULT_DATA, + .resource = "/vfs", +}; + +/* CoAP resources. Must be sorted by path (ASCII order). */ +static const coap_resource_t _resources[] = { + { "/vfs", COAP_GET | COAP_MATCH_SUBTREE, gcoap_fileserver_handler, (void *)&_vfs_entry }, +}; + +static gcoap_listener_t _listener = { + .resources = _resources, + .resources_len = ARRAY_SIZE(_resources), +}; + +int main(void) +{ + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + gcoap_register_listener(&_listener); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +}