LwM2M is a standard for device management that solves many of the issues M2M and IoT solutions makers have faced in the past (or, let's be realistic, are still facing), with custom protocols or even standards like OMA-DM: complex workflows, high bandwidth usage, lack of open-source implementations... Join this talk to get an overview of the LwM2M protocol, and to learn how you can start managing an embedded device with Eclipse Wakaama (yes, it fits in an Arduino, and yes, there will be a live demo!), or build your own device management server with Eclipse Leshan.
Manage devices with open source LwM2M implementations
1. Manage all the things,
small and big,
with open source
LwM2M implementations
Benjamin Cabé* – Eclipse Foundation
* many thanks to Julien Vermillard for most of the slides!
2. Device Management
● Configure the device
○ Reboot
○ Update APN, current date/time, …
● Update the software (and firmware)
● Manage the software
○ Change settings
○ Access logs
● Monitor and gather connectivity statistics
○ Amount of sent/received data
○ Number of SMS received/sent
2
3. Device Management
3
Device Management server
(not necessarily the server used for
IoT application data)
● Has security credentials for
devices on the field (X.509
certificate, public key, …)
● Provides high-level API for
batch updates
● May integrate with IT backendIoT Device
● Runs a device management
agent, usually in the firmware
● Embeds a private/public key
pair to cipher communication
● Has DM server’s public key to
authenticate it is talking to
intended server
4. D.M. standards protocols
● Usual suspects:
○ TR-069
○ OMA-DM
○ Lightweight M2M
● Goals: provide a way to manage fleets of
devices that is application-agnostic
4
5. Lightweight M2M
● A new Open Mobile Alliance standard
● An OMA-DM successor for M2M targets
● Built on top of CoAP
○ much lighter than OMA-DM or TRS-069
○ enables the use of SMS for wakeup (or any REST
interaction really!)
5
6. Lightweight M2M (LwM2M)
● An Open Mobile Alliance standard
● A « reboot » of OMA-DM for M2M
● Built on top of CoAP
○ much lighter than OMA-DM or TRS-069
○ enables the use of SMS for wakeup (or any
REST interaction really!)
● REST API for Device Management
● Standard objects for Security, Location,
Firmware, …
○ and also: IPSO Smart Objects, 3rd
party, …
7. LWM2M features
● Firmware upgrade (in band or over HTTP)
● Device monitoring and configuration
● Server provisioning (bootstraping)
7
8. LWM2M: standard objects
● Device
● Server
● Connectivity monitoring
● Connectivity statistics
● Location
● Firmware
LwM2M objects have a numerical identifier
(Device = 3, Location = 6, …)
8
11. Leshan
A Java library for implementing LwM2M servers
(and clients)
Friendly for any Java developer (no framework,
few dependencies)
But also a Web UI for discovering and testing the
protocol
14. Server
Simple Java library
Build using “mvn install”
Based on Californium and Scandium
Under refactoring for accepting other CoAP lib
15. Server API example
public void start() {
// Build LWM2M server
LeshanServerBuilder builder = new LeshanServerBuilder();
lwServer = builder.build();
lwServer.getClientRegistry().addListener(new ClientRegistryListener() {
@Override
public void registered(Client client) {
System.out.println("New registered client with endpoint: " +
client.getEndpoint());
}
@Override
public void updated(Client clientUpdated) {
System.out.println("Registration updated");
}
@Override
public void unregistered(Client client) {
System.out.println("Registration deleted");
}
});
// start
lwServer.start();
System.out.println("Demo server started");
}
16. Server API example
// prepare the new value
LwM2mResource currentTimeResource = new LwM2mResource(13,
Value.newDateValue(new Date()));
// send a write request to a client
WriteRequest writeCurrentTime = new WriteRequest(client, 3, 0, 13,
currentTimeResource, ContentFormat.TEXT, true);
ClientResponse response = lwServer.send(writeCurrentTime);
System.out.println("Response to write request from client " +
client.getEndpoint() + ": " + response.getCode());
17. Client
Under construction! API will probably change
Create objects, answer to server requests
DTLS supported in master
Check out: leshan-client-example
18. Next steps
Eclipse.org migration
X.509 DTLS
CoAP shim, CoAP TCP
Stable API for June (inc. client polishing)
And also:
JSON content-type
SMS
Server initiated bootstrap
20. Wakaama
A C client and server implementation of LwM2M
Not a shared library (.so/.dll)
POSIX compliant and embedded friendly
Plug your own IP stack and DTLS implementation
23. objArray[0] = get_object_device();
if (NULL == objArray[0])
{
fprintf(stderr, "Failed to create Device objectrn");
return -1;
}
objArray[1] = get_object_firmware();
if (NULL == objArray[1])
{
fprintf(stderr, "Failed to create Firmware objectrn");
return -1;
}
objArray[2] = get_test_object();
if (NULL == objArray[2])
{
fprintf(stderr, "Failed to create test objectrn");
return -1;
}
lwm2mH = lwm2m_init(prv_connect_server, prv_buffer_send, &data);
if (NULL == lwm2mH)
{
fprintf(stderr, "lwm2m_init() failedrn");
return -1;
}
result = lwm2m_configure(lwm2mH, "testlwm2mclient", BINDING_U, NULL,
OBJ_COUNT, objArray);
...
result = lwm2m_start(lwm2mH);
Configure
Wakaama
24. while (0 == g_quit)
{
struct timeval tv;
tv.tv_sec = 60;
tv.tv_usec = 0;
/*
* This function does two things:
* - first it does the work needed by liblwm2m (eg. (re)sending some packets).
* - Secondly it adjust the timeout value (default 60s) depending on the
* state of the transaction (eg. retransmission) and the
* time between the next operation
*/
result = lwm2m_step(lwm2mH, &tv);
if (result != 0)
{
fprintf(stderr, "lwm2m_step() failed: 0x%Xrn", result);
return -1;
}
}
Active loop
31. How to help?
Use it! Report bugs, issue, missing features
Write documentation
Talk about Wakaama and Leshan, they are cool!
Contribute code
Questions?
https://dev.eclipse.org/mailman/listinfo/leshan-dev
https://dev.eclipse.org/mailman/listinfo/wakaama-dev