mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
examples: Add Wakaama LwM2M example application
This commit is contained in:
parent
c52ad2df9e
commit
8d47813487
49
examples/wakaama/Makefile
Normal file
49
examples/wakaama/Makefile
Normal file
@ -0,0 +1,49 @@
|
||||
# name of your application
|
||||
APPLICATION = wakaama
|
||||
|
||||
# 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 += gnrc_netdev_default
|
||||
USEMODULE += auto_init_gnrc_netif
|
||||
# Specify the mandatory networking modules
|
||||
USEMODULE += gnrc_ipv6_router_default
|
||||
USEMODULE += gnrc_sock_udp
|
||||
# Additional networking modules that can be dropped if not needed
|
||||
USEMODULE += gnrc_icmpv6_echo
|
||||
# Add also the shell, some shell commands
|
||||
USEMODULE += shell
|
||||
USEMODULE += shell_commands
|
||||
USEMODULE += ps
|
||||
|
||||
# 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
|
||||
|
||||
# Specific the server URI address (NOTE: Domain names not supported yet)
|
||||
SERVER_URI ?= '"coap://[fd00:dead:beef::1]"'
|
||||
|
||||
ifneq (,$(SERVER_URI))
|
||||
CFLAGS += -DLWM2M_SERVER_URI=$(SERVER_URI)
|
||||
endif
|
||||
|
||||
# NOTE: Add the package for wakaama
|
||||
USEPKG += wakaama
|
||||
# Uncomment to enable Wakaama debug log
|
||||
#CFLAGS += -DLWM2M_WITH_LOGS
|
||||
|
||||
# Uncomment to indicate that the server is a LwM2M bootstrap server
|
||||
# CFLAGS += -DLWM2M_BOOTSTRAP=1
|
||||
|
||||
# NOTE: Use wakaama in client mode
|
||||
CFLAGS += -DLWM2M_CLIENT_MODE
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
60
examples/wakaama/Makefile.ci
Normal file
60
examples/wakaama/Makefile.ci
Normal file
@ -0,0 +1,60 @@
|
||||
BOARD_BLACKLIST := \
|
||||
arduino-duemilanove \
|
||||
arduino-leonardo \
|
||||
arduino-mega2560 \
|
||||
arduino-nano \
|
||||
arduino-uno \
|
||||
atmega1284p \
|
||||
atmega256rfr2-xpro \
|
||||
atmega328p \
|
||||
avr-rss2 \
|
||||
chronos \
|
||||
derfmega128 \
|
||||
derfmega256 \
|
||||
mega-xplained \
|
||||
microduino-corerf \
|
||||
msb-430 \
|
||||
msb-430h \
|
||||
pic32-clicker \
|
||||
pic32-wifire \
|
||||
telosb \
|
||||
waspmote-pro \
|
||||
wsn430-v1_3b \
|
||||
wsn430-v1_4 \
|
||||
z1
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
airfy-beacon \
|
||||
b-l072z-lrwan1 \
|
||||
blackpill \
|
||||
bluepill \
|
||||
calliope-mini \
|
||||
cc2650-launchpad \
|
||||
cc2650stk \
|
||||
hifive1 \
|
||||
hifive1b \
|
||||
i-nucleo-lrwan1 \
|
||||
lsn50 \
|
||||
maple-mini \
|
||||
microbit \
|
||||
nrf51dongle \
|
||||
nrf6310 \
|
||||
nucleo-f030r8 \
|
||||
nucleo-f031k6 \
|
||||
nucleo-f302r8 \
|
||||
nucleo-f303k8 \
|
||||
nucleo-f042k6 \
|
||||
nucleo-f070rb \
|
||||
nucleo-f072rb \
|
||||
nucleo-f302r8 \
|
||||
nucleo-f334r8 \
|
||||
nucleo-l031k6 \
|
||||
nucleo-l053r8 \
|
||||
opencm904 \
|
||||
saml10-xpro \
|
||||
saml11-xpro \
|
||||
spark-core \
|
||||
stm32f030f4-demo \
|
||||
stm32f0discovery \
|
||||
stm32l0538-disco \
|
||||
yunjia-nrf51822
|
96
examples/wakaama/README.md
Normal file
96
examples/wakaama/README.md
Normal file
@ -0,0 +1,96 @@
|
||||
# Wakaama LwM2M example client
|
||||
|
||||
This application starts a
|
||||
[LwM2M](https://wiki.openmobilealliance.org/display/TOOL/What+is+LwM2M) client
|
||||
on the node with instances of the following objects:
|
||||
- [Security object](http://www.openmobilealliance.org/tech/profiles/LWM2M_Security-v1_0.xml)
|
||||
- [Server object](http://www.openmobilealliance.org/tech/profiles/LWM2M_Server-v1_0.xml)
|
||||
- [Device object](http://www.openmobilealliance.org/tech/profiles/LWM2M_Device-v1_0_3.xml)
|
||||
|
||||
The application is based on the Eclipse Wakaama
|
||||
[example client](https://github.com/eclipse/wakaama/tree/master/examples/client)
|
||||
.
|
||||
|
||||
## Usage
|
||||
|
||||
### Setting up a LwM2M Test Server
|
||||
To test the client a LwM2M server where to register is needed.
|
||||
[Eclipse Leshan](https://github.com/eclipse/leshan) demo is a good option for
|
||||
running one locally.
|
||||
|
||||
To run the demo server:
|
||||
```shell
|
||||
wget https://hudson.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-server-demo.jar
|
||||
|
||||
java -jar ./leshan-server-demo.jar
|
||||
```
|
||||
It will output the addresses where it is listening:
|
||||
```
|
||||
INFO LeshanServer - LWM2M server started at coap://0.0.0.0/0.0.0.0:5683 coaps://0.0.0.0/0.0.0.0:5684
|
||||
INFO LeshanServerDemo - Web server started at http://0.0.0.0:8080/.
|
||||
```
|
||||
|
||||
#### Bootstrap server
|
||||
LwM2M provides a bootstrapping mechanism to provide the clients with information
|
||||
to register to one or more servers. To test this mechanism both the previous server and a bootstrap server should be running. Eclipse Leshan also provides a bootstrap server demo.
|
||||
|
||||
By default the bootstrap server option is disabled, it can be enabled by defining
|
||||
`LWM2M_BOOTSTRAP` as 1 (see the Makefile in this application).
|
||||
|
||||
To run the bootstrap server, make sure that the ports it uses are different
|
||||
from the ones of previous server (default are 5683 for CoAP, 5684 for CoAPs,
|
||||
and 8080 for the webserver), and that it corresponds to the one set in
|
||||
`lwm2m.h` as `LWM2M_BSSERVER_PORT`:
|
||||
```shell
|
||||
# download demo
|
||||
wget https://hudson.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-bsserver-demo.jar
|
||||
|
||||
# set CoAP, CoAPs and webserver ports for bootstrap server
|
||||
BS_COAPPORT=5685
|
||||
BS_COAPSPORT=5686
|
||||
BS_WEBPORT=8888
|
||||
|
||||
# run the server
|
||||
java -jar ./leshan-bsserver-demo.jar --coapport ${BS_COAPPORT} \
|
||||
--coapsport ${BS_COAPSPORT} --webport ${BS_WEBPORT}
|
||||
```
|
||||
|
||||
To set up the configuration of the node and the server:
|
||||
1. Click the `Add new client bootstrap configuration` button.
|
||||
2. Fill in the name of the device, it **should** match the one set in
|
||||
`lwm2m.h` as `LWM2M_DEVICE_NAME`.
|
||||
3. Using the `LWM2M Server` tab enter the address where the LwM2M server is
|
||||
listening. For now only `No security` mode can be used.
|
||||
|
||||
### Running the client
|
||||
The address set in `lwm2m.h` as `LWM2M_SERVER_URI` should be reachable
|
||||
from the node, e.g. either running on native with a tap interface or as a mote
|
||||
connected to a
|
||||
[border router](https://github.com/RIOT-OS/RIOT/tree/master/examples/gnrc_border_router).
|
||||
|
||||
Also, if a bootstrap server is being used the macro `LWM2M_BOOTSTRAP` should be
|
||||
defined as 1.
|
||||
|
||||
The server URI for the example is being defined using the variable `SERVER_URI`
|
||||
in the Makefile, and can be changed when compiling.
|
||||
|
||||
#### Compile and run
|
||||
For debugging purposes there are two types of messages that can be enabled:
|
||||
- The lwm2m client adaptation debug can be enabled by setting `ENABLE_DEBUG` in
|
||||
`lwm2m_client.c` and `lwm2m_client_connection.c` to 1
|
||||
- The wakaama internal logging can be enabled by adding `LWM2M_WITH_LOGS` to the
|
||||
CFLAGS (`CFLAGS += -DLWM2M_WITH_LOGS`)
|
||||
|
||||
For memory allocation the TLSF package is being used, with a private heap. If
|
||||
memory usage has to be tweaked the heap size can be modified via the macro
|
||||
`LWM2M_TLSF_BUFFER`.
|
||||
|
||||
To compile run:
|
||||
|
||||
```shell
|
||||
BOARD=<board> make clean all flash term
|
||||
```
|
||||
|
||||
#### Shell commands
|
||||
- `lwm2m start`: Starts the LwM2M by configuring the module and registering to
|
||||
the server.
|
74
examples/wakaama/lwm2m_cli.c
Normal file
74
examples/wakaama/lwm2m_cli.c
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2019 HAW Hamburg
|
||||
*
|
||||
* 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 Wakaama LwM2M Client CLI support
|
||||
*
|
||||
* @author Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "kernel_defines.h"
|
||||
#include "lwm2m_client.h"
|
||||
#include "lwm2m_client_objects.h"
|
||||
#include "lwm2m_platform.h"
|
||||
|
||||
#define OBJ_COUNT (3)
|
||||
|
||||
uint8_t connected = 0;
|
||||
lwm2m_object_t *obj_list[OBJ_COUNT];
|
||||
lwm2m_client_data_t client_data;
|
||||
|
||||
void lwm2m_cli_init(void)
|
||||
{
|
||||
/* this call is needed before creating any objects */
|
||||
lwm2m_client_init(&client_data);
|
||||
|
||||
/* add objects that will be registered */
|
||||
obj_list[0] = lwm2m_client_get_security_object(&client_data);
|
||||
obj_list[1] = lwm2m_client_get_server_object(&client_data);
|
||||
obj_list[2] = lwm2m_client_get_device_object(&client_data);
|
||||
|
||||
if (!obj_list[0] || !obj_list[1] || !obj_list[2]) {
|
||||
puts("Could not create mandatory objects");
|
||||
}
|
||||
}
|
||||
|
||||
int lwm2m_cli_cmd(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1) {
|
||||
goto help_error;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "start")) {
|
||||
/* run the LwM2M client */
|
||||
if (!connected && lwm2m_client_run(&client_data, obj_list, OBJ_COUNT)) {
|
||||
connected = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (IS_ACTIVE(DEVELHELP) && !strcmp(argv[1],"mem")) {
|
||||
lwm2m_tlsf_status();
|
||||
return 0;
|
||||
}
|
||||
|
||||
help_error:
|
||||
if (IS_ACTIVE(DEVELHELP)) {
|
||||
printf("usage: %s <start|mem>\n", argv[0]);
|
||||
}
|
||||
else {
|
||||
printf("usage: %s <start>\n", argv[0]);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
50
examples/wakaama/main.c
Normal file
50
examples/wakaama/main.c
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Beduino Master Projekt - University of Bremen
|
||||
* 2019 HAW Hamburg
|
||||
*
|
||||
* 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 Eclipse Wakaama LwM2M Client
|
||||
*
|
||||
* @author Christian Manal <manal@uni-bremen.de>
|
||||
* @author Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "board.h"
|
||||
#include "msg.h"
|
||||
#include "shell.h"
|
||||
|
||||
#define SHELL_QUEUE_SIZE (8)
|
||||
static msg_t _shell_queue[SHELL_QUEUE_SIZE];
|
||||
|
||||
extern void lwm2m_cli_init(void);
|
||||
extern int lwm2m_cli_cmd(int argc, char **argv);
|
||||
static const shell_command_t my_commands[] = {
|
||||
{ "lwm2m", "Start LwM2M client", lwm2m_cli_cmd },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* initiates LwM2M client */
|
||||
lwm2m_cli_init();
|
||||
|
||||
msg_init_queue(_shell_queue, SHELL_QUEUE_SIZE);
|
||||
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||
shell_run(my_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user