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.


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


Switch states


Accelerometer data




GPS coordinates




Light control



The sample supports the following development kit:

Hardware platforms


Board name

Build target

nRF9160 DK




The sample also requires an LwM2M server URL address available on the internet. For this sample, the URL address mentioned on the Leshan Demo Server page is used.

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.

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:


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 nrf9160dk_nrf9160ns build target. 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

Queue Mode support

To build the LwM2M Client sample with LwM2M Queue Mode support, build it with the -DOVERLAY_CONFIG=overlay-queue.conf option. See Providing CMake options for instructions on how to add this option.

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.


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

In addition, it uses the Secure Partition Manager sample: