Top Banner
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!
32

Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Jul 16, 2015

Download

Technology

Benjamin Cabé
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 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!

Page 2: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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

Page 3: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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

Page 4: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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

Page 5: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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

Page 6: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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, …

Page 7: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

LWM2M features

● Firmware upgrade (in band or over HTTP)

● Device monitoring and configuration

● Server provisioning (bootstraping)

7

Page 8: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

LWM2M: standard objects

● Device

● Server

● Connectivity monitoring

● Connectivity statistics

● Location

● Firmware

LwM2M objects have a numerical identifier (Device = 3, Location = 6, …)

8

Page 9: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

LWM2M URIs

URLs:

/{object}/{instance}/{resource}

Example: /6/0 = whole position object (binary TLV)/6/0/2 = only the altitude value

9

Page 10: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

LeshanOpen-source Lightweight M2M for Java

Page 11: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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

Page 12: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Features

Client initiated bootstrap

Registration/Deregistration

Read, Write, Create objects

TLV encoding/decoding

OSGi-friendly

Page 13: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Features (cont’d)

DTLS Pre shared key

DTLS Raw public key

Standalone web-UI for testing

Page 14: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Server

Simple Java library

Build using “mvn install”

Based on Californium and Scandium

Under refactoring for accepting other CoAP lib

Page 15: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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");}

Page 16: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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());

Page 17: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Client

Under construction! API will probably change

Create objects, answer to server requests

DTLS supported in master

Check out: leshan-client-example

Page 18: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Next steps

Eclipse.org migrationX.509 DTLSCoAP shim, CoAP TCPStable API for June (inc. client polishing)

And also:JSON content-typeSMSServer initiated bootstrap

Page 19: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Eclipse Wakaama

Lightweight M2M implementation in C

Photo credits: https://www.flickr.com/photos/30126248@N00/2890986348

Page 20: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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

Page 21: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Features

Register, registration update, deregister

Read, write resources

Read, write, create, delete object instances

TLV or plain text

Observe

Page 22: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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!

Page 23: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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

Page 24: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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

Page 25: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Next?

Device initiated bootstrap

More examples:https://github.com/kartben/Wakaama-mbed

Server?

Block transfer?

Page 26: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Hack it into real devices!

… DEMO TIME!

Page 27: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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!)

Page 28: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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

Page 29: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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

Page 30: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

Lua binding

https://github.com/sbernard31/lualwm2m

With DTLS support using:https://github.com/sbernard31/luadtlsbinding on top of TinyDTLS (http://tinydtls.sf.net)

Page 31: Manage all the things, small and big, with open source LwM2M implementations - FOSDEM 2015

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