Application integration

The LwM2M carrier library has an OS abstraction layer. See lwm2m_os.h. This abstraction layer makes the LwM2M carrier library independent of the nRF Connect SDK modules and underlying implementation of primitives such as timers, non-volatile storage, and heap allocation. It provides an abstraction of the following modules:

The OS abstraction layer is fully implemented for the nRF Connect SDK, and it would have to be ported if used with other RTOS or on other systems.

To run the library in an application, you must implement the application with the API of the library. You can enable the module using the CONFIG_LWM2M_CARRIER Kconfig option.

The nRF9160: LwM2M carrier sample project configuration (nrf/samples/nrf9160/lwm2m_carrier/prj.conf) contains all the configurations that are needed by the LwM2M carrier library.

You can provide the initialization parameter lwm2m_carrier_config_t to overwrite the carrier default settings with the Kconfig options described below:

Note that these settings can put the LwM2M carrier library either in the normal mode where it connects to the applicable carriers, or in the generic mode where it can connect to any bootstrap server.


A change of the bootstrap server URI between builds does not trigger a new bootstrap. The bootstrap process is intended to happen only once unless it is initiated from the server. To redo the bootstrap process, you must erase the flash and then load your application again.

After calling the lwm2m_carrier_init() function, your application can call the non-returning function lwm2m_carrier_run() in its own thread. Both these functions are called in nrf\lib\bin\lwm2m_carrier\os\lwm2m_carrier.c, which is included into the project when you enable the LwM2M carrier library.

The lwm2m_carrier_event_handler() function must be implemented by your application. This is shown in the nRF9160: LwM2M carrier sample. A weak implementation is included in nrf\lib\bin\lwm2m_carrier\os\lwm2m_carrier.c.

See nrf\lib\bin\lwm2m_carrier\include\lwm2m_carrier.h for all the events and API.

LwM2M carrier library events

Following are the various LwM2M carrier library events:

Device objects

The following values that reflect the state of the device must be kept up to date by the application:

  • Available Power Sources

  • Power Source Voltage

  • Power Source Current

  • Battery Level

  • Battery Status

  • Memory Total

  • Error Code

  • Device Type (Defaults to Smart Device if not set)

  • Software Version (Defaults to LwM2M <libversion>. For example, LwM2M 0.8.0 for release 0.8.0.)

  • Hardware Version (Defaults to 1.0 if not set)

For example, the carrier device management platform can observe the battery level of your device. The application uses the lwm2m_carrier_battery_level_set() function to indicate the current battery level of the device to the carrier.