No Matches
LwM2M - Lightweight Machine to Machine

LwM2M implementation based on the Wakaama package. More...

Detailed Description

LwM2M implementation based on the Wakaama package.

Lightweight Machine to Machine is a device management protocol designed for sensor networks, designed for remote management of M2M devices and related service enablement. It defines an extensible resource and data model and builds top of CoAP. LwM2M has been specified by the OMA SpecWorks Device Management Working Group. The specification is freely available here.

For a list of the supported objects see LwM2M Object implementations. The client implementation is based on the Eclipse Wakaama project


A LwM2M Client organizes resources as object instances. The LwM2M engine is independent of the objects that the client exposes, but it needs at least 3 mandatory ones: Device object, Security object and a Server object.

#include "lwm2m_client.h"
#include "objects/device.h"
#include "net/credman.h"
// hold references to object handles
lwm2m_object_t *obj_list[3];
// LwM2M Client instance
lwm2m_client_data_t client_data;
// short ID for internal reference of the server
int main(void)
// initiate the LwM2M Client
// arguments for instantiating a security object
.server_uri = "coap://[fd00:dead:beef::1]:5683",
.security_mode = LWM2M_SECURITY_MODE_NONE,
.is_bootstrap = false,
.client_hold_off_time = 5,
.bootstrap_account_timeout = 0
// get the Security object handle
obj_list[0] = lwm2m_object_security_init(&client_data);
// create a new Security object instance
if (res < 0) {
puts("Could not instantiate the security object");
// get the Server object handle (only single instance for now)
obj_list[1] = lwm2m_client_get_server_object(&client_data, CONFIG_LWM2M_SERVER_SHORT_ID);
// device object has a single instance. All the information for now is defined at compile-time
obj_list[2] = lwm2m_object_device_get();
// run the LwM2M client
lwm2m_client_run(&client_data, obj_list, ARRAY_SIZE(obj_list);
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition container.h:83
(D)TLS credentials management module definitions
void lwm2m_client_init(lwm2m_client_data_t *client_data)
Initializes a LwM2M client.
lwm2m_context_t * lwm2m_client_run(lwm2m_client_data_t *client_data, lwm2m_object_t *obj_list[], uint16_t obj_numof)
Starts a LwM2M client.
No security mode.
Definition security.h:199
lwm2m_object_t * lwm2m_object_security_init(lwm2m_client_data_t *client_data)
Initialize the Security object.
int lwm2m_object_security_instance_create(const lwm2m_obj_security_args_t *args, int32_t instance_id)
Create a new Security instance and add it to the object list.
Definitions and public API for a LwM2M client using Wakaama.
Public API and definitions for the helper functions to interact with basic objects from a LwM2M clien...
lwm2m_object_t * lwm2m_client_get_server_object(lwm2m_client_data_t *client_data, int server_id)
Creates a LwM2M server object with the default configuration from net/lwm2m.h.
LwM2M client descriptor.
Arguments for a new Security object instance creation (lwm2m_object_security_instance_create).
Definition security.h:311
uint16_t server_id
Server's short ID the instance is associated to.
Definition security.h:315

The LwM2M Client will connect to the specified LwM2M server and register itself. After that, the server will be able to perform Read, Write, Create, Delete, Execute and Observe operations on the resources.

DTLS support

With the configuration above plain CoAP is used. To secure the connection with the LwM2M Server, a credential is needed in the Security object instance. To enable DTLS support add the module wakaama_client_dtls. This uses the DTLS sock API, so you will need to select an implementation of it (e.g. USEPKG += tinydtls). Currently Pre-Shared Key (PSK) and Raw Public Key (RPK) modes are supported.

To see how to use DTLS credentials, go to the usage section of Security LwM2M object.

Using a LwM2M Bootstrap Server

A bootstrap server gives a LwM2M deployment more flexibility. Information on how to connect to the LwM2M bootstrap server is defined at compile-time in the client (including URI and potentially needed credentials). The client connects to the bootstrap server on boot, which installs on the node the information needed to connect to the LwM2M servers.

To enable bootstrap support, set the LWM2M_BOOTSTRAP option on Kconfig or set the CFLAG CONFIG_LWM2M_BOOTSTRAP=1. You will also need to specify during the security object instantiation that the information corresponds to a bootstrap server. DTLS is also supported for the bootstrap server:

.server_id = 1,
.server_uri = "coaps://[fd00:dead:beef::1]:5684",
.pub_key_or_id = psk_id,
.pub_key_or_id_len = sizeof(psk_id) - 1,
.secret_key = psk_key,
.secret_key_len = sizeof(psk_key) - 1,
.is_bootstrap = true,
.client_hold_off_time = 5,
.bootstrap_account_timeout = 0
Pre-Shared keys mode.
Definition security.h:184

Keep into account, that some Sock DTLS implementations may need some extra configuration to handle multiple connections. See the example/wakaama Makefile.


 Common LwM2M Object functionalities
 Common functionalities to interact with LwM2M objects.
 LwM2M Client using Wakaama
 Wakaama adaption to RIOT for implementing a LwM2M client.
 LwM2M Object implementations
 Implementations of LwM2M objects using Wakaama.
 Platform adaption for Wakaama package
 Adaption of Wakaama LwM2M package to RIOT.
 Wakaama LwM2M Client configuration
 Configuration options for the LwM2M client implementation based on the Wakaama package.