Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015
-
Upload
benjamin-cabe -
Category
Technology
-
view
2.724 -
download
3
Transcript of Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015
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!
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
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
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
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
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, …
LWM2M features
● Firmware upgrade (in band or over HTTP)
● Device monitoring and configuration
● Server provisioning (bootstraping)
7
LWM2M: standard objects
● Device
● Server
● Connectivity monitoring
● Connectivity statistics
● Location
● Firmware
LwM2M objects have a numerical identifier (Device = 3, Location = 6, …)
8
LWM2M URIs
URLs:
/{object}/{instance}/{resource}
Example: /6/0 = whole position object (binary TLV)/6/0/2 = only the altitude value
9
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
Features
Client initiated bootstrap
Registration/Deregistration
Read, Write, Create objects
TLV encoding/decoding
OSGi-friendly
Server
Simple Java library
Build using “mvn install”
Based on Californium and Scandium
Under refactoring for accepting other CoAP lib
Server API examplepublic 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");}
Server API example
// prepare the new valueLwM2mResource 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());
Client
Under construction! API will probably change
Create objects, answer to server requests
DTLS supported in master
Check out: leshan-client-example
Next steps
Eclipse.org migrationX.509 DTLSCoAP shim, CoAP TCPStable API for June (inc. client polishing)
And also:JSON content-typeSMSServer initiated bootstrap
Eclipse Wakaama
Lightweight M2M implementation in C
Photo credits: https://www.flickr.com/photos/30126248@N00/2890986348
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
Features
Register, registration update, deregister
Read, write resources
Read, write, create, delete object instances
TLV or plain text
Observe
lwm2m_object_t * get_object_device(){ lwm2m_object_t * deviceObj; deviceObj = (lwm2m_object_t *)lwm2m_malloc(sizeof(lwm2m_object_t));
if (NULL != deviceObj) { memset(deviceObj, 0, sizeof(lwm2m_object_t)); deviceObj->objID = 3;
deviceObj->readFunc = prv_device_read; deviceObj->writeFunc = prv_device_write; deviceObj->executeFunc = prv_device_execute; deviceObj->userData = lwm2m_malloc(sizeof(device_data_t));
if (NULL != deviceObj->userData) { ((device_data_t*)deviceObj->userData)->time = 1367491215; strcpy(((device_data_t*)deviceObj->userData)->time_offset, "+01:00"); } else { lwm2m_free(deviceObj); deviceObj = NULL; } }
return deviceObj;}
Create objects!
objArray[0] = get_object_device();if (NULL == objArray[0]){ fprintf(stderr, "Failed to create Device object\r\n"); return -1;}
objArray[1] = get_object_firmware();if (NULL == objArray[1]){ fprintf(stderr, "Failed to create Firmware object\r\n"); return -1;}
objArray[2] = get_test_object();if (NULL == objArray[2]){ fprintf(stderr, "Failed to create test object\r\n"); return -1;}
lwm2mH = lwm2m_init(prv_connect_server, prv_buffer_send, &data);if (NULL == lwm2mH){ fprintf(stderr, "lwm2m_init() failed\r\n"); return -1;}result = lwm2m_configure(lwm2mH, "testlwm2mclient", BINDING_U, NULL, OBJ_COUNT, objArray);...result = lwm2m_start(lwm2mH);
ConfigureWakaama
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%X\r\n", result); return -1; }}
Active loop
Next?
Device initiated bootstrap
More examples:https://github.com/kartben/Wakaama-mbed
Server?
Block transfer?
Spark Core
● Cortex-M3 STM32, ● RAM/ROM 20/128k, 72MHz● WiFi
Wakaama + TinydTLS-0.5
Functions: dTLS (PSK)
LwM2M Objects: device
Footprint:
“empty”-App: 75.6 KB Flash / 13.1 KB RAM
simple-lwm2m: 107 KB Flash / 15.2 KB RAM (overhead = 32KB / 3.1kB!)
U-blox MBed.org
● Cortex-M3 (NXP LPC1768), ● RAM/ROM 20/128k, 96MHz● GPRS
Functions: observe, attribute:
Objects: server, security, device, conn_m, firmware, location
Footprint (RTOS + commandline + lwm2m stack): 84 KB Flash / 22 KB RAM
Arduino Mega
● ATmega2560 ● RAM/ROM 8/256k, 16MHz● Ethernet
Functions: observe, attribute
Objects: server, security, device, conn_m, firmware, location
Footprint (C++ wrapper + simulator + lwm2m stack): 67 KB Flash / 5 KB RAM
Lua binding
https://github.com/sbernard31/lualwm2m
With DTLS support using:https://github.com/sbernard31/luadtlsbinding on top of TinyDTLS (http://tinydtls.sf.net)
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