Skip to content

Commit 43a3b89

Browse files
committed
unicoap slip setup
use sliptty, automatically set static global ip in main TODO: check with Martine: static address to specific interface? ravdv provided prefix goes to wrong interface?
1 parent 7aa791e commit 43a3b89

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

examples/networking/coap/unicoap_server/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ endif
4444
USEMODULE += unicoap
4545
USEMODULE += unicoap_resources_xfa
4646

47+
USEMODULE += shell
48+
USEMODULE += shell_cmds_default
49+
50+
# on Linux
51+
# sudo ip a a 2001:db8::1 dev sl0 (for sliptty)
52+
# sudo ip r a 2001:db8::2 dev tap0 (for native)
53+
54+
# IPV6_HOST_ADDR ?= 2001:db8::1
55+
# see https://github.com/RIOT-OS/RIOT/pull/20192
56+
57+
# Configure terminal parameters
58+
ifeq (,$(filter native native32 native64, $(BOARD)))
59+
IPV6_PREFIX ?= 2001:db8::/64
60+
USEMODULE += slipdev_stdio
61+
TERMPROG ?= sudo sh $(RIOTTOOLS)/sliptty/start_network.sh
62+
TERMFLAGS ?= -e $(IPV6_PREFIX) $(PORT)
63+
endif
64+
65+
CFLAGS += -DDEBUG_ASSERT_VERBOSE
66+
4767
# This module is needed for CoAP over UDP
4868
USEMODULE += unicoap_driver_udp
4969

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
CONFIG_UNICOAP_DEBUG_LOGGING=n
2-
CONFIG_UNICOAP_ASSIST=n
1+
CONFIG_UNICOAP_DEBUG_LOGGING=y
2+
CONFIG_UNICOAP_ASSIST=y
33
CONFIG_UNICOAP_CREATE_THREAD=y

examples/networking/coap/unicoap_server/main.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
/* This is needed for netifs_print_ipv6 in main below. */
2020
#include "net/netif.h"
21+
#include "shell.h"
22+
23+
#define MAIN_QUEUE_SIZE (4)
24+
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
2125

2226
/* If you need CoAP over DTLS support, you need to include extra dependencies. What's more,
2327
* you'll also need to load a DTLS credential for message encryption and verification.
@@ -194,6 +198,22 @@ UNICOAP_RESOURCE(greeting) {
194198
};
195199

196200
int main(void) {
201+
202+
int res;
203+
ipv6_addr_t addr;
204+
ipv6_addr_from_str(&addr, "2001:db8::2");
205+
206+
gnrc_netif_t *netif = gnrc_netif_get_by_type(NETDEV_SLIPDEV, NETDEV_INDEX_ANY);
207+
if (!netif) {
208+
netif = gnrc_netif_get_by_type(NETDEV_TAP, NETDEV_INDEX_ANY);
209+
}
210+
211+
res = gnrc_netif_ipv6_addr_add(netif, &addr, 64, 0);
212+
if (res < 0) {
213+
printf("error: unable to set addr: %d\n", res);
214+
}
215+
216+
197217
/* By default, unicoap_init() is automatically called for you before main().
198218
* This is because auto_init_unicoap is part of the DEFAULT_MODULE makefile variable.
199219
* You can opt out of this default behavior by setting DISABLE_MODULE += auto_init_unicoap.
@@ -253,7 +273,7 @@ int main(void) {
253273
* at least one DTLS credential. */
254274
#if IS_USED(MODULE_UNICOAP_DRIVER_DTLS)
255275
/* credman is a utility that manages DTLS credentials. */
256-
int res = credman_add(&credential);
276+
res = credman_add(&credential);
257277
if (res < 0 && res != CREDMAN_EXIST) {
258278
/* Here we ignore duplicate credentials. */
259279
printf("app: cannot add credential to system: %d\n", res);
@@ -299,4 +319,8 @@ int main(void) {
299319
printf("app: running unicoap loop on main thread\n");
300320
unicoap_loop_run();
301321
#endif
322+
323+
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
324+
char line_buf[SHELL_DEFAULT_BUFSIZE];
325+
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
302326
}

0 commit comments

Comments
 (0)