-
Notifications
You must be signed in to change notification settings - Fork 2.1k
pkg/wakaama: Add basic LWM2M client implementation #11036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+2,455
−10
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
|
|
||
|
kb2ma marked this conversation as resolved.
|
||
| #### 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: | ||
|
|
||
|
kb2ma marked this conversation as resolved.
|
||
| ```shell | ||
| BOARD=<board> make clean all flash term | ||
| ``` | ||
|
|
||
| #### Shell commands | ||
| - `lwm2m start`: Starts the LwM2M by configuring the module and registering to | ||
| the server. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # include contrib code (platform adaption and client implementation) | ||
| USEMODULE += wakaama_contrib | ||
|
leandrolanzieri marked this conversation as resolved.
|
||
|
|
||
| # this allows us to include our own objects, implemented in the 'objects' | ||
| # folder, by adding 'wakaama_objects_<objectName>' modules | ||
| USEMODULE += wakaama_objects | ||
|
|
||
| # include the 'device' object implementation (mandatory) | ||
| USEMODULE += wakaama_objects_device | ||
|
|
||
| USEMODULE += xtimer | ||
| USEPKG += tlsf | ||
|
|
||
| # If logs for the package are active, we need fmt | ||
| ifneq (,$(filter -DLWM2M_WITH_LOGS,$(CFLAGS))) | ||
| USEMODULE += fmt | ||
| endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| INCLUDES += -I$(PKGDIRBASE)/wakaama/riotbuild | ||
| DIRS += $(RIOTBASE)/pkg/wakaama/contrib | ||
|
|
||
| INCLUDES += -I$(RIOTBASE)/pkg/wakaama/include | ||
| INCLUDES += -I$(PKGDIRBASE)/wakaama |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.