Skip to main content

LwM2M

Introduction

LwM2M (Lightweight Machine to Machine) is a lightweight Internet of Things (IoT) device management protocol developed by OMA (Open Mobile Alliance) to provide efficient remote management and communication solutions for resource-constrained devices.

Why use LwM2M protocol?

LwM2M (Lightweight Machine-to-Machine) protocol is designed for low-power, low-bandwidth devices, addressing the following issues:

  1. Communication for low-power devices: Optimized for efficient communication in low-power devices, suitable for sensors and other IoT devices.
  2. Device management: Provides standardized management methods for device registration, remote configuration, and firmware updates.
  3. Adaptability to network limitations: Effectively transmits data in low-bandwidth, high-latency environments.
  4. Bandwidth and resource savings: Reduces bandwidth consumption with an efficient message format.
  5. Standardized protocol: Offers a unified interface that simplifies integration across different devices and platforms.

Overall, LwM2M provides an efficient, resource-saving communication method, ideal for large-scale IoT applications.

Note

The LwM2M protocol support was introduced in Shifu v0.57.0. Ensure that you are using version v0.57.0 or newer for LwM2M compatibility.

Deployment

  1. Click on Add Device -> Protocol menu.

    Choose LwM2M

  2. Select LwM2M protocol from the list of protocols and click on Next step.

    Choose LwM2M

  3. Fill in the device name, device manufacturer, device type, and device model. The device name is the identifier used to distinguish different devices in Shifu Cloud. Then click on Next step.

    Enter device information

  4. Enter the endpoint name, which must match the endpoint name of your LwM2M device. Choose a security mode:

    1. DTLS (PSK Mode): Enter the PSK identity and the PSK key in hexadecimal format, then click Next Step.
    2. None: If no security is required, select this option and proceed. Enter endpoint name
  5. Enter resource ID, instances and API name. The API name is optional; if left blank, the API will default to the object ID. Click Add. Then click on Deploy.

    (You can add multiple resource IDs.)

    API configuration

  6. Copy and paste the command from the pop-up to deploy the device into your Kubernetes cluster.

    Get deployment cmd

    Deploy cmd

Usage(Take Leshan as an example)

  1. Use following command to get your port.

    kubectl get services -n deviceshifu

    get port

  2. Run the Docker image first. Then use the following command to connect to deviceShifu.

    1. Run the Docker image

      docker run --rm -it edgenesis/lwm2m-demo-leshan-client:nightly bash
    2. Use the following command to connect to deviceShifu.

      java -jar leshan-client-demo-2.0.0-SNAPSHOT-jar-with-dependencies.jar -u coaps://localhost:your port -n shifu

    Deploy mock device

  3. Create a new terminal and send the request to /get_value/0/SensorValue to get the result.

    result