This blog is to share how to setup the LwM2M Server and run with Nordic nRF9160 DK board. I would use Eclipse LESHAN LwM2M server for demo.

Basically, when you would like to connect to the cloud, it has multiple protocols and server which you may hear before such as, COAP, LwM2M, MQTT, TCP, UDP, HTTP. All of these terms are extremely hot and popular on the internet of things industry. But what are they? I would like to have a quick overview and give for introduction.

Basically, LwM2M and COAP are at the top of UDP. MQTT and HTTP are on the top of TCP. According to the paper “UDP and TCP performance investigation in energy efficient“, UDP is much fit on the low power connectivity solution.

  • TCP will consume slightly more bandwidth than UDP.
  • Everything that is transmitted in TCP must be ack’ed to ensure integrity of the connection. UDP does not do that.
  • TCP has a slightly larger per-packet header than UDP.
  • TCP has optional keep-alives that can be turned on, which UDP does not have. So, there may small amounts of network traffic being used to keep TCP connections alive during idle periods when no application data is being transmitted.

Thus, I would give more details how to use the LWM2M in this blog.


LwM2M

OMA Lightweight M2M is a protocol from the Open Mobile Alliance for M2M or IoT device management.

  • On top of CoAP
  • UDP and SMS transport layer support
  • Simple Object based resource model
  • Basic M2M functionalities: LWM2M Server, Access Control, Device, Connectivity, Firmware Update, Location, Connectivity Statistics
  • DTLS based security

Details of the LwM2M can be found at https://omaspecworks.org/what-is-oma-specworks/iot/lightweight-m2m-lwm2m/.

LwM2M Resource Links

LwM2M v1.0 features (highlight)

  • Simple resource model with the core set of objects and resources defined in the
    specification. The full list of registered objects can be found in the LwM2M
    registry.
  • Operations for creation, update, deletion, and retrieval of resources.
  • Asynchronous notifications of resource changes.
  • Support for several serialization formats, namely TLV, JSON, Plain Text and binary
    data formats and the core set of LightweightM2M Objects.
    UDP and SMS transport support.
  • Communication security based on the DTLS protocol supporting different types of
    credentials.
  • Queue Mode offers functionality for a LwM2M Client to inform the LwM2M
    Server that it may be disconnected for an extended period of time and also when
    it becomes reachable again.
  • Support for use of multiple LwM2M Servers.
  • Provisioning of security credentials and access control lists by a dedicated
    LwM2M bootstrap-server.

LwM2M v1.1 features (highlight)

  • Improved support for Public Key Infrastructure (PKI) deployments.
  • Introduction of enhanced registration sequence mechanisms by the LwM2M Client to
  • LwM2M Server(s).
  • Support for LwM2M over TCP/TLS to better support firewall and NAT traversal.
  • Support for application layer security for LwM2M based on OSCORE.
  • Better support of LwM2M over Low Power WANs, including 3GPP CIoT & LoRaWAN.
  • Extended LwM2M commands to enable Resource Instance level access.
  • Performance improvement for retrieving and updating Resources of multiple objects.
  • Support for JSON using SenML with CBOR serialization for compressed payload with highly efficient transmission.

OMA LwM2M uses the object or/and Resource identifier: (Object ID) to communicate. The concept of Object ID is very similar to the BLE Profile. You may need to register your OWN object ID if need to proprietary information.

http://www.openmobilealliance.org/wp/OMNA/LwM2M/LwM2MRegistry.html

To register a new (Object ID) or (Resource ID). Your submission will be redirected to GitHub Issues in lwm2m-registry.

OMA has developed an editor for creating LwM2M Objects & Resources.


Inside Nordic nRF Connect SDK, it has the example of the LwM2M client.

nRF9160: LwM2M Client

The LwM2M Client demonstrates how to use Lightweight Machine to Machine (LwM2M) protocol to connect an nRF9160 DK to an LwM2M server such as Leshan Demo Server via LTE. Once connected, the device can be queried to obtain GPS and sensor data, and to retrieve information about the modem.

Overview

LwM2M is an application layer protocol based on CoAP/UDP. It is designed to expose various resources for reading, writing and executing via an LwM2M server in a very lightweight environment. The nRF9160 sample sends data such as button and switch states, accelerometer data (the physical orientation of the device), temperature and GPS position. It can also receive activation commands such as buzzer activation and light control.

Button statesDOWN/UP
Switch statesON/OFF
Accelerometer dataFLIP
TemperatureTEMP
GPS coordinatesGPS
BuzzerTRIGGER
Light controlON/OFF
Leshan

Eclipse Leshan™ is an OMA Lightweight M2M server and client Java implementation.

  • Eclipse project since 2014
  • Modular Java libraries
  • Based on Californium CoAP implementation
  • Based on Scandium DTLS implementation
  • IPSO objects support
  • Web Interface, ease of use
  • IPv4 and/or IPv6 access

How to configure the Leshan server

Check the nRF9160 DK board (IMEI number)

The following instructions describe how to register your device and these instructions are specific to Leshan Demo Server:

  1. Open the Leshan Demo Server web UI.
  2. Click on Security in the upper-right corner.
  3. Click on Add new client security configuration.
  4. Enter the following data and click Create:
    • Client endpoint – nrf-{your Device IMEI}
    • Security mode – Pre-Shared Key
    • Identity: – nrf-{your Device IMEI}
    • Key – 000102030405060708090a0b0c0d0e0f
  5. Build and run the LwM2M Client sample.

On running the SES project, from the RTT log, you can check on the connection between LwM2M server.

You need to add the configuration as below.

# Set LwM2M Server IP address here
CONFIG_APP_LWM2M_SERVER="leshan.eclipseprojects.io"
CONFIG_LWM2M_LOG_LEVEL_DBG=y

Here is the RTT Log on the SES,

On the leshan server, you can find that the board is connected the server.

Welcome to give me any comment and feedback.

If you have interest, you can find another document how to run the LwM2M on the STM nuclear board.

https://www.st.com/content/dam/technology-tour-2017/session-1_track-5_oma-lwm2m.pdf