mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
examples/cord_epsim: run registration loop locally
This commit rewrites the example so that the registration loop is run inside the main() function instead of running the standalone submodule of epsim. It also adapts the example application to parse the RD UDP endpoint locally and provide this to epsim's register() function.
This commit is contained in:
parent
ec461661d8
commit
0c5219f603
@ -20,12 +20,10 @@ USEMODULE += auto_init_gnrc_netif
|
||||
USEMODULE += gnrc_ipv6_default
|
||||
|
||||
# Run the simple CoRE resource directory
|
||||
USEMODULE += cord_epsim_standalone
|
||||
USEMODULE += cord_epsim
|
||||
|
||||
# Include the shell for testing purposes
|
||||
USEMODULE += shell
|
||||
USEMODULE += shell_commands
|
||||
USEMODULE += ps
|
||||
# We also use the xtimer for periodic RD entry updates in this example
|
||||
USEMODULE += xtimer
|
||||
|
||||
# Comment this out to disable code in RIOT that does safety checking
|
||||
# which is not needed in a production environment but helps in the
|
||||
@ -35,13 +33,17 @@ CFLAGS += -DDEVELHELP
|
||||
# For debugging and demonstration purposes, we limit the lifetime to the minimal
|
||||
# allowed value of 60s (see draft-ietf-core-resource-directory-11, Table 2)
|
||||
RD_LT ?= 60
|
||||
# Override this variable to set the RD server address (default is the all nodes
|
||||
# multicast address)
|
||||
RD_ADDR ?= \"ff02::1\"
|
||||
RD_PORT ?= 5683
|
||||
|
||||
CFLAGS += -DCORD_LT=$(RD_LT)
|
||||
CFLAGS += -DCORD_SERVER_ADDR=$(RD_ADDR)
|
||||
CFLAGS += -DCORD_SERVER_PORT=$(RD_PORT)
|
||||
|
||||
# If nothing else is defined, we use CoAP default port
|
||||
RD_PORT ?= COAP_PORT
|
||||
CFLAGS += -DRD_PORT=$(RD_PORT)
|
||||
|
||||
# The RD server's address must be defined by the build environment by setting
|
||||
# the RD_ADDR environment variable. Per default, this value is set to the
|
||||
# loopback address for enabling the build tests to successfully build this
|
||||
# example.
|
||||
RD_ADDR ?= \"affe::1\"
|
||||
CFLAGS += -DRD_ADDR=$(RD_ADDR)
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
@ -5,20 +5,23 @@ This example shows how a node can register with a CoRE resource directory using
|
||||
the simple registration procedure as described in
|
||||
draft-ietf-core-resource-directory-15, section 5.3.1.
|
||||
|
||||
The registration process needs an endpoint name as well as a lifetime for the
|
||||
registry entry. These are statically defined during compile time and you can
|
||||
edit these values by overriding `CORD_EP` and `CORD_LT`:
|
||||
```
|
||||
CFLAGS="-DCORD_LT=\"7200\" -DCORD_EP=\"MyNode\"" make all
|
||||
```
|
||||
|
||||
Per default, the node is looking for the CoRE RD at the all nodes link-local
|
||||
multicast address [FF02::1]:5683. To change the target address or port, simply
|
||||
override the `RD_ADDR` and `RD_PORT` variables, e.g.:
|
||||
```
|
||||
RD_ADDR=\\\"::1\\\" RD_PORT=12345 make all
|
||||
```
|
||||
or
|
||||
When running this example, you **must** define the RD server's IPv6 address
|
||||
statically, using the `RD_ADDR` environment variable:
|
||||
```
|
||||
RD_ADDR=\\\"abc:0815::123\\\" make all
|
||||
```
|
||||
Per default, this is set to some random global address (`affe::1`) for compile
|
||||
test reasons. So change it!
|
||||
|
||||
Additionally, you can change the RD server's port by overriding the `RD_PORT`
|
||||
variable:
|
||||
```
|
||||
RD_ADDR=\\\"affe::bee\\\" RD_PORT=12345 make all
|
||||
```
|
||||
|
||||
The registration lifetime is set for demonstration purposes to a rather short
|
||||
time of 60s in this example. You can easily override that value using the
|
||||
`RD_LT` variable:
|
||||
```
|
||||
RD_ADDR=\\\"abc::def\\\" RD_LT=3600 make all ...
|
||||
```
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Freie Universität Berlin
|
||||
* Copyright (C) 2017-2019 Freie Universität Berlin
|
||||
*
|
||||
* 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
|
||||
@ -12,7 +12,7 @@
|
||||
*
|
||||
* @file
|
||||
* @brief Test application demonstrating the simple registration
|
||||
* process to a CoRE RD using gcoap
|
||||
* process to a CoRE RD using gcoap and cord_epsim
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
@ -21,11 +21,12 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "shell.h"
|
||||
#include "net/gcoap.h"
|
||||
#include "net/cord/epsim.h"
|
||||
#include "net/cord/common.h"
|
||||
|
||||
#define BUFSIZE (64U)
|
||||
#define STARTUP_DELAY (3U) /* wait 3s before sending first request*/
|
||||
|
||||
static char riot_info[BUFSIZE];
|
||||
|
||||
@ -66,25 +67,62 @@ static gcoap_listener_t listener = {
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("CoAP simplified RD registration example!\n");
|
||||
puts("Simplified CoRE RD registration example\n");
|
||||
|
||||
/* fill riot info */
|
||||
sprintf(riot_info, "{\"ep\":\"%s\",\"lt\":%u}",
|
||||
cord_common_get_ep(), CORD_LT);
|
||||
|
||||
/* parse RD address information */
|
||||
sock_udp_ep_t rd_ep = {
|
||||
.family = AF_INET6,
|
||||
.netif = SOCK_ADDR_ANY_NETIF,
|
||||
.port = RD_PORT,
|
||||
};
|
||||
|
||||
/* parse RD server address */
|
||||
if (ipv6_addr_from_str((ipv6_addr_t *)&rd_ep.addr.ipv6, RD_ADDR) == NULL) {
|
||||
puts("error: unable to parse RD address from RD_ADDR variable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* register resource handlers with gcoap */
|
||||
gcoap_register_listener(&listener);
|
||||
|
||||
/* print RD client information */
|
||||
puts("RD client information:");
|
||||
printf(" RD addr: %s\n", CORD_SERVER_ADDR);
|
||||
printf(" RD port: %u\n", (unsigned)CORD_SERVER_PORT);
|
||||
printf(" ep: %s\n", cord_common_get_ep());
|
||||
printf(" lt: %is\n", (int)CORD_LT);
|
||||
puts("epsim configuration:");
|
||||
printf(" ep: %s\n", cord_common_get_ep());
|
||||
printf(" lt: %is\n", (int)CORD_LT);
|
||||
printf(" RD address: [%s]:%u\n\n", RD_ADDR, (unsigned)RD_PORT);
|
||||
|
||||
/* run the shell */
|
||||
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||
xtimer_sleep(STARTUP_DELAY);
|
||||
|
||||
while (1) {
|
||||
int res = cord_epsim_state();
|
||||
switch (res) {
|
||||
case CORD_EPSIM_OK:
|
||||
puts("state: registration active");
|
||||
break;
|
||||
case CORD_EPSIM_BUSY:
|
||||
puts("state: registration in progress");
|
||||
break;
|
||||
case CORD_EPSIM_ERROR:
|
||||
default:
|
||||
puts("state: not registered");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("updating registration with RD [%s]:%u\n", RD_ADDR,
|
||||
(unsigned)RD_PORT);
|
||||
res = cord_epsim_register(&rd_ep);
|
||||
if (res == CORD_EPSIM_BUSY) {
|
||||
puts("warning: registration already in progress");
|
||||
}
|
||||
else if (res == CORD_EPSIM_ERROR) {
|
||||
puts("error: unable to trigger simple registration process");
|
||||
}
|
||||
xtimer_sleep(CORD_UPDATE_INTERVAL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user