You are on page 1of 3

Eclipse Leshan is an open source LWM2M programming framework in Java.

This
document is showcases how LWM2M Client(SmartWatchClient or any other
client) that host REST based LWM2M servers can interface with Azure IoT Hub
using Eclipse Leshan. This tutorial uses Leshan version1.0.0-M13.

➢ In this Document, we provide following guidelines for Leshan Installation


and Leshan Client Development using Eclipse IDE:

a. Download and install Java SE 8 JDK (which include JRE)

b. Download and install Eclipse IDE for Java Developer – 4.15.0

c. Download the zip distribution of eclipse/leshan from


https://github.com/eclipse/leshan

d. Extract the zip file into the Eclipse Workspace directory

e. Open Eclipse and import the Leshan project to Eclipse downloaded by


accessing File -> Import-> Maven
-> Existing Maven Projects and specify the directory of the project in the
Eclipse Workspace folder

i. Open leshan-client-demo project: a sample of LWM2M client .

ii. In the package org.eclipse.leshan.client.demo, create classes for your


LWM2M objects extending the BaseInstanceEnabler class. In the leshan-client-
demo project, three object classes are created: MyDevice.java, MyLocation.java
and RandomTemperatureSensor.java. You can use one of these classes as a
template for your new device objects. These Objects are Managable.

Iii. Run the project as Java Application LeshanClientDemo . This device object
registers directly with the LwM2M server i.e,. REST Based Spring Boot
application, The device is connected to the server till it gets De-
registered(LeshanClient stops). Same process of registration can be applied for
any number of devices

f. Under the Installed JREs menu, which is the Execution Environment menu, set
the compatible JRE for JavaSE-1.8.

➢ Developing REST Based LWM2M Server Spring Boot application


a. Open ladapterdemo project: a LWM2M server project.

b. Currently, following list of API's are developed:

GET http://server_ip_address/devices
This API returns a JSON file describing all the clients registered in the Leshan

POST http://server_ip_address/devices/registrations/push
This API pushes a JSON file describing all the clients registered in the Leshan to
Azure IoT Hub.

GET http://server_ip_address/devices/observe
This API returns a JSON file describing the value of a resource

DELETE http://server_ip_address/devices
This API deletes the resource returns the status.

PUT http://server_ip_address/devices
This API updates the value of a resource.

POST http://server_ip_address/devices/updates/push
This API pushes updated value of a resource to Azure IoT Hub.

Note: A device is a data model that consists of three levels.


These are
Object - each Object represent some different concept of data accessible via
the LwM2M Client.

Object Instance - some Objects are described as “single-instance” - such


Objects always have exactly one Instance with identifier 0. or Other Objects
may have multiple Instances;

Resource - each Object Instance of a given Object supports the same set of
Resources, as defined by the Object definition.
For example, a path /3/4/1 refers to Resource ID=1 in Object Instance ID=4 of
Object ID=3.

The required parameters that needs to be passed for the above API's are
configured in Postman.

c. Run the AdapterdemoMainApplication.java as as Spring Boot App.

d. From the Azure portal create an IoT Hub. Once the  IoT Hub is available use
the  connection string in ConnectionBroker.java class. This  connection string is
Used mainly for managing devices. Format of Connection String:
HostName=<HostName>;SharedAccessKeyName=<Key
Name>;SharedAccessKey=<SAS Key>

e. Run ConnectionBroker.java in com.atossyntel.adapterdemo.utils package.


Implementation of the MQTT protocol in ConnectionBrokerMain class is very
straight forward. The broker is at the heart of any publish/subscribe protocol.
The responses sent from Leshan Server are published to Azure IoT Hub using
MQTT protocol.

f. Alternative to above step, we have developed HTTP based RestClient With the
help of which we can publish the response from Leshan Server to Azure IoT
Hub.

You might also like