Skip to content

Commit

Permalink
pkg/libcoap: Add in libcoap CoAP library support
Browse files Browse the repository at this point in the history
Includes a CoAP client and CoAP server example.
  • Loading branch information
mrdeep1 committed Aug 18, 2023
1 parent 4b1b0a9 commit a04974a
Show file tree
Hide file tree
Showing 22 changed files with 1,360 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples/libcoap-client/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if USEMODULE_LIBCOAP
config LIBCOAP_CLIENT_URI
string "CoAP URI to connect to"
default "coap://[fe80::405:5aff:fe15:9b7f]/.well-known/core"
config LIBCOAP_USE_PSK
string "Secret to use for PSK communications"
default "secretPSK"
depends on USEMODULE_TINYDTLS
config LIBCOAP_USE_PSK_ID
string "User ID to use for PSK communications"
default "user_abc"
depends on USEMODULE_TINYDTLS
config LIBCOAP_SERVER_SUPPORT
bool "Set to y if server support is required"
default n
config LIBCOAP_CLIENT_SUPPORT
bool "Set to y if client support is required"
default y
endif # USEMODULE_LIBCOAP
67 changes: 67 additions & 0 deletions examples/libcoap-client/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# name of your application
APPLICATION = libcoap-client

# 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)/../..

# Include packages that pull up and auto-init the link layer.
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
USEMODULE += netdev_default
USEMODULE += auto_init_gnrc_netif

# Activate ICMPv6 error messages
USEMODULE += gnrc_icmpv6_error

# Specify the mandatory networking module for a IPv6 routing node
USEMODULE += gnrc_ipv6_router_default

# Add a routing protocol
USEMODULE += gnrc_rpl
USEMODULE += auto_init_gnrc_rpl

# Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo

# Specify the mandatory networking modules for IPv6 and UDP
USEMODULE += gnrc_ipv6_default
USEMODULE += memarray
USEMODULE += ipv4_addr

# a cryptographically secure implementation of PRNG is needed for tinydtls
# Uncomment the following 3 lines for tinydtls support
CFLAGS += -DWITH_RIOT_SOCK
USEPKG += tinydtls
USEMODULE += prng_sha1prng

# libcoap support
USEPKG += libcoap

# Configure if DNS is required
# USEMODULE += sock_dns

# Support 64 bit ticks
USEMODULE += ztimer64_xtimer_compat

# Add also the shell, some shell commands
USEMODULE += shell
USEMODULE += shell_cmds_default
USEMODULE += ps
USEMODULE += netstats_l2
USEMODULE += netstats_ipv6
USEMODULE += netstats_rpl

# libcoap needs some space
CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(3*THREAD_STACKSIZE_DEFAULT\)

# 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

include $(RIOTBASE)/Makefile.include
49 changes: 49 additions & 0 deletions examples/libcoap-client/Makefile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
BOARD_INSUFFICIENT_MEMORY := \
airfy-beacon \
b-l072z-lrwan1 \
blackpill-stm32f103c8 \
blackpill-stm32f103cb \
bluepill-stm32f030c8 \
bluepill-stm32f103c8 \
bluepill-stm32f103cb \
calliope-mini \
cc2650-launchpad \
cc2650stk \
hifive1 \
hifive1b \
i-nucleo-lrwan1 \
im880b \
lsn50 \
maple-mini \
microbit \
nrf51dk \
nrf51dongle \
nrf6310 \
nucleo-f030r8 \
nucleo-f031k6 \
nucleo-f042k6 \
nucleo-f070rb \
nucleo-f072rb \
nucleo-f103rb \
nucleo-f302r8 \
nucleo-f303k8 \
nucleo-f334r8 \
nucleo-l011k4 \
nucleo-l031k6 \
nucleo-l053r8 \
nucleo-l073rz \
opencm904 \
samd10-xmini \
saml10-xpro \
saml11-xpro \
slstk3400a \
spark-core \
stk3200 \
stm32f030f4-demo \
stm32f0discovery \
stm32f7508-dk \
stm32g0316-disco \
stm32l0538-disco \
stm32mp157c-dk2 \
yunjia-nrf51822 \
#
24 changes: 24 additions & 0 deletions examples/libcoap-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# libcoap client example

This example shows how to configure a client to use libcoap

## Fast configuration (Between RIOT instances):

Preparing the logical interfaces:

sudo ./../../dist/tools/tapsetup/tapsetup --create 2

## Client invocation
For the client:

PORT=tap0 make term
coapc coap://[ip6-address]/some/path

The IP address to connect to needs to be that as returned by libcoap_server,
or that of the tap0 interface, etc.

## Handling the static memory allocation

libcoap for RIOT is using the `sys/memarray` module and therefore there
are certain limits. Said resources are defined in `libcoap/src/coap_mem.c`,
but can be overwritten at compile time.
8 changes: 8 additions & 0 deletions examples/libcoap-client/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CONFIG_LIBCOAP_CLIENT_SUPPORT=y
CONFIG_LIBCOAP_CLIENT_URI="coap://[fe80::405:5aff:fe15:9b7f]/.well-known/core"

CONFIG_LIBCOAP_USE_PSK="secretPSK"
CONFIG_LIBCOAP_USE_PSK_ID="user_abc"

CONFIG_KCONFIG_USEPKG_LIBCOAP=y
# Logging levels are defined in pkg/libcoap using Kconfig
Loading

0 comments on commit a04974a

Please sign in to comment.