nRF9160: LwM2M Client

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

Overview

Lightweight Machine to Machine (LwM2M) is an application layer protocol based on CoAP/UDP, and 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 state, accelerometer data (the device’s physical orientation), temperature and GPS position. It can also receive actuation commands such as buzzer activation and light control.

Button states

DOWN/UP

Switch states

ON/OFF

Accelerometer data

FLIP

Temperature

TEMP

GPS coordinates

GPS

Buzzer

TRIGGER

Light control

ON/OFF

Requirements

  • The following development board:

  • The sample is configured to compile and run as a non-secure application on nRF91’s Cortex-M33. Therefore, it automatically includes the nRF9160: Secure Partition Manager that prepares the required peripherals to be available for the application.

  • an LwM2M server IP address available on the internet

Building and Running

There are configuration files for various setups in the samples/nrf9160/lwm2m_client directory:

  • prj.conf This is the standard default config.

The easiest way to setup this sample application is to build and run it on the nRF9160-DK board using the default configuration prj.conf.

You will need to tell the sample what LwM2M server to use by editing the following line in the configuration you’ve chosen:

CONFIG_APP_LWM2M_SERVER="{IP address of LwM2M server}"

Build the sample:

This sample can be found under samples/nrf9160/lwm2m_client in the nRF Connect SDK folder structure.

The sample is built as a non-secure firmware image for the nrf9160_pca10090ns board. Because of this, it automatically includes the nRF9160: Secure Partition Manager.

See Building and programming a sample application for information about how to build and program the application.

DTLS Support

The sample has DTLS security enabled by default. The following information will need to be entered into the LwM2M server before you can make a successful connection: client endpoint, identity and pre-shared key.

The following are instructions specific to Leshan Demo Server:

- Open up the Leshan Demo Server web UI
- Click on "Security" in the upper-right
- Click on "Add new client security configuration"
- Enter the following data:

Client endpoint: nrf-{Your Device IMEI}

Security mode: Pre-Shared Key

Identity: nrf-{Your Device IMEI}

Key: 000102030405060708090a0b0c0d0e0f

  • Start the Zephyr sample

Connecting to the LwM2M Server

The sample will start and automatically connect to the LwM2M Server with an endpoint named “nrf-{Your Device IMEI}”.

NOTE: The IMEI of your device can be found on the bottom of the nRF-9160-DK near a bar code with the FCC ID at the bottom.

Dependencies

This application uses the following nRF Connect SDK libraries and drivers:

In addition, it uses the Secure Partition Manager sample:

References