LwM2M Demo

Table of Contents

  1. Introduction
  2. Resources
  3. Prerequisites
  4. Setup
  5. Using the Demo
    Auto Commissioning
    Manual Commissioning to Leshan Server
    View Leshan Cloud Data
  6. User Defined Server
  7. LED Behavior
  8. Building the Firmware
  9. Development

Introduction

In this demo, the Pinnacle 100/BL5340 device is configured to use LwM2M and DTLS with pre-shared keys. LightweightM2M (LwM2M) is a protocol that runs on top of CoAP. The demo is configured to leave the Pinnacle 100 device in its current mode (Cat-M1 or NB-IoT). The mobile app can be used to change the radio mode if desired. LwM2M is an ideal protocol for NB-IoT or Cat-M1 (Applies to Pinnacle 100/MG100 only) because it is UDP based. When using NB-IoT on the Pinnacle 100/MG100, we do not recommend using the TCP protocol due to the network latencies inherent to NB-IoT.

A LwM2M Server (Leshan or Cumulocity) is used to display information about the Pinnacle 100/BL5340 device and discovered sensors. Supported sensors are:

  1. BL654 BME280 Sensor / ESS BLE sensor
  2. BT510 sensors
  3. BT610 sensors
  4. MG100 only: onboard temperature sensor (LIS3DH)

The software version, model, manufacturer, serial number, and current time can be read. If a BL654 Sensor Board/ESS sample module is detected and can be connected to, then temperature, humidity, and pressure can be read. In addition, the green LED on the Pinnacle 100 device and LED 4 on the BL5340 development kit can be turned on and off using the light control object. If BT510 and/or BT610 sensor advertisements are detected, then their sensor readings will be interpreted and sent to the server as well.

                                     XXXXX
                                   XXX   XXX
                         XXXXX   XX        XX
                      XXX    XX XX          X XXXXXXX
                      X        XX            X       XX
                     X                                X
                      X         LwM2M Server           X
                      XX                              X
                       XXXXXXX                       XX
                             XX          XXXX    XXXX
                              XXX      XXX   XXXX
                                XXXXXXX
                                    ^
                                    |
                         Cat-M1/NB-IoT or Ethernet        
                            (LwM2M with DTLS)
                                    |
                                    |
                                    v
                          +---------+----------+
                          |                    |
                          |     DVK/MG100      |
                          |                    |
                          +---------+----------+
                                    ^
                                    |
           +-----------------------BLE-------------------+
           |                        |                    |
           v                        v                    v
+----------+------------+  +------------------+  +----------------+
|                       |  |                  |  |                |
|  BL654/ESS Sensor     |  |      BT510       |  |     BT610      |
|                       |  |                  |  |                |
+-----------------------+  +------------------+  +----------------+

Resources

Prerequisites

The following are required to fully exercise this demo firmware:

  • An activated SIM card. The Truphone SIM card that comes with the DVK does not currently support NB-IoT. If you have purchased a DVK in Europe, then please contact sales to obtain a SIM card that is NB-IoT capable (Pinnacle 100/MG100 only).
  • Pinnacle 100/BL5340 device programmed with LwM2M demo firmware.
    • Connect to the FTDI UART on the development kit to view firmware logs
  • Laird Pinnacle Connect app installed on a mobile device

Setup

To set up the device, follow these steps:

  1. Ensure an activated SIM card is inserted into the Pinnacle 100 SIM slot (Pinnacle 100/MG100 only).
  2. On your phone, launch the Pinnacle mobile app and follow the on-screen prompts.

Using the Demo

If the Laird Connectivity Leshan server is used, then the device should be configured to something other than its default settings. This allows multiple devices to connect to the same server.

Auto Commissioning

  1. Open the mobile app, connect to your device and go to the LwM2M Settings page.
  2. Click the Auto-commission device button. This will automatically add the Pinnacle 100 device with a unique ID to the Laird Connect Leshan LwM2M server.

Auto-commission device
Auto-commission device

  1. Skip to View Cloud Data for instructions on interacting with your device.

Manual Commissioning to Leshan Server

  1. Open Laird Connectivity Leshan web page.
  2. Go to the Security page.
  3. Press “Add Security Information”.

Leshan add device
Leshan add device

  1. Using the Pinnacle Connect mobile app, read the model number from the Device Information page.

Model number
Model number

  1. With the mobile app, make note of the Gateway ID from the home page.

Gateway ID
Gateway ID

  1. Enter <model number>_<id> into the Client endpoint field on the webpage. For example, pinnacle_100_dvk_354616090287629 or bl5340_dvk_cpuapp_ebc25ce12ffd.
  2. Generate a new private shared key using the LwM2M Settings page in the mobile app.
  3. Copy the value into the Key field on the webpage.
  4. Set and save the Client ID using the mobile app (don’t reuse a name that is already present on the server).
  5. Put the same name into the Identity field on the web page.

LwM2M settings
LwM2M settings

Leshan device config
Leshan device config

  1. Reset the modem using the mobile app (Power Settings page) or reset button (SW5 NRF_RESET).

View Leshan Cloud Data

From the clients page, click on your device once it is connected to interact with it.

  • Make sure to set the Response Timeout to something greater than 5s at the top of the page.

Leshan response timeout
Leshan response timeout

  • Click on an object and select R at the top to read all child values. In some cases, not all child values are supported.

Leshan read object
Leshan read object

  • The Light Control object can be used to control an LED on the device as described here below. Write true or false to the On/Off node.

Leshan light control
Leshan light control

User Defined Server

In addition to the steps in the Using the Demo section, the Peer URL must be set using the mobile app.

Depending on the servers support for bootstrap, enable or disable bootstrap with the mobile app or use the following command via the UART console:

# disable bootstrap
attr set 264 0

# enable bootstrap
attr set 264 1

LED Behavior

Pinnacle 100/MG100

The Blue LED blinks when the module is advertising and allowing another device to connect to and configure it. When a central device connects, the LED remains on. When advertising stops, the LED remains off. Button 1 (SW1) can be pressed to restart advertising.

The Green LED can be controlled via the LwM2M server Light Control object (Pinnacle 100 only).

The Red LED blinks when the Pinnacle 100 device is searching for a cellular network. It remains on and does not blink when connected to a network. If there is an error with the SIM card or network registration, then the LED remains off.

BL5340

LED 1 blinks when the module is advertising and allowing another device to connect to and configure it. When a central device connects, the LED remains on. When advertising stops, the LED remains off. Button 1 can be pressed to restart advertising.

LED 2 blinks once a second when the module is searching for a BL654 Sensor Board/ESS service device. When it finds a sensor and successfully connects to it, the LED remains on.

LED 3 is on when network connectivity is established, it remains off when there is no network connection.

LED 4 can be controlled via the LwM2M server Light Control object.

Building the Firmware

Pinnacle 100/MG100

The firmware can be built to work with or without the mcuboot bootloader. Building without mcuboot is faster and easier for development and debug, but gives up the ability to update the Zephyr app via UART or BLE.

Note: If using VS Code for development the build lwm2m with mcuboot and build lwm2m tasks can be used to easily build the firmware.

Issue these commands from the ble_gateway_firmware directory.

WARNING: If using windows, checkout code to a path of 12 characters or less to avoid build issues related to path length limits.

Build without mcuboot:

Note: [board] should be replaced with mg100 or pinnacle_100_dvk

# Linux and macOS

rm -f app/pm_static.yml && west build -b [board] -d build/[board]/lwm2m app

# Windows

del app\pm_static.yml && west build -b [board] -d build\[board]\lwm2m app

Note: When switching between builds with or without mcuboot, be sure to delete the build directory before building.

Build with mcuboot:

Note: [board] should be replaced with mg100 or pinnacle_100_dvk

# Linux and macOS

cp ../modules/zephyr_lib/mcuboot_config/pm_static.[board].yml app/pm_static.yml

west build -b [board] -d ${PWD}/build/[board]/lwm2m ${PWD}/app -- -DOVERLAY_CONFIG="${PWD}/app/overlay_lwm2m_dtls.conf ${PWD}/../modules/zephyr_lib/mcumgr_wrapper/config/overlay-mcuboot.conf" -Dmcuboot_DTC_OVERLAY_FILE=${PWD}/app/boards/pinnacle_100.overlay -Dmcuboot_CONF_FILE=${PWD}/../modules/zephyr_lib/mcuboot_config/pinnacle_100.conf

# Windows

copy ..\modules\zephyr_lib\mcuboot_config\pm_static.[board].yml app\pm_static.yml

west build -b [board] -d %CD%\build\[board]\lwm2m %CD%\app -- -DOVERLAY_CONFIG="%CD%\app\overlay_lwm2m_dtls.conf %CD%\..\modules\zephyr_lib\mcumgr_wrapper\config\overlay-mcuboot.conf" -Dmcuboot_DTC_OVERLAY_FILE=%CD%\app\boards\pinnacle_100.overlay -Dmcuboot_CONF_FILE=%CD%\..\modules\zephyr_lib\mcuboot_config\pinnacle_100.conf

After building the firmware, it can be flashed with the following command:

Note: [board] should be replaced with mg100 or pinnacle_100_dvk

west flash -d build/[board]/lwm2m

If the firmware was built with mcuboot, west flash will program merged.hex which contains the mcuboot bootloader and app in a combined image.

BL5340

The firmware can only be built with mcuboot.

Issue these commands from the BLE_Gateway_Firmware directory.

WARNING: If using windows, checkout code to a path of 12 characters or less to avoid build issues related to path length limits.

# Linux and macOS

cp app/boards/pm_static_bl5340_dvk.yml app/pm_static.yml

west build -b bl5340_dvk_cpuapp -d ${PWD}/build/bl5340_dvk_cpuapp/lwm2m ${PWD}/app -- -DOVERLAY_CONFIG="${PWD}/app/overlay_lwm2m_dtls.conf ${PWD}/../modules/zephyr_lib/mcumgr_wrapper/config/overlay-mcuboot.conf" -Dmcuboot_CONF_FILE=${PWD}/../modules/zephyr_lib/mcuboot_config/bl5340.conf

# Windows

copy app\boards\pm_static_bl5340_dvk.yml app\pm_static.yml

west build -b bl5340_dvk_cpuapp -d %CD%\build\bl5340_dvk_cpuapp\lwm2m %CD%\app -- -DOVERLAY_CONFIG="%CD%\app\overlay_lwm2m_dtls.conf %CD%\..\modules\zephyr_lib\mcumgr_wrapper\config\overlay-mcuboot.conf" -Dmcuboot_CONF_FILE=%CD%\..\modules\zephyr_lib\mcuboot_config\bl5340.conf

After building the firmware, it can be flashed with the following command:

west flash -d build/bl5340_dvk_cpuapp/lwm2m

Development

See here for help on getting started with custom development.

Cellular Network Information

See here for instructions on how to get details about the cell network (Pinnacle 100/MG100 only).