Skip to main content

LwM2M with Gateway

Introduction

The Gateway module in Shifu Cloud plays a key role in the IoT architecture, and is used to achieve data communication and protocol conversion between devices and the server. The following are the main functions and features of the Gateway:

Why use gateway?

The main role of a gateway in protocol conversion is to forward and convert data between different protocols. For example, it can convert MQTT messages into HTTP requests or OPC UA messages into LwM2M. This helps with:

  1. Enabling interoperability between different protocols, allowing devices and systems using different protocols to communicate.
  2. Simplifying system integration, where devices and applications can use the protocols they are familiar with, and the gateway handles the conversion.
  3. Adapting to different network requirements, such as CoAP being suitable for low-bandwidth and low-power devices, with the gateway helping to select the appropriate protocol.

Deployment Example with Leshan Server

  1. Click on Add Device -> Protocol menu.

    Choose LwM2M

  2. Select LwM2M protocol from the list of protocols, check "Forward to LwM2M Server" and click on Next step.

    Choose LwM2M

  3. Go to Leshan server and copy the COAPS URL. Fill in the Server address with the copied URL and the Endpoint name. Then click on Next step.

    Copy URL Fill server address

  4. Optionally, fill in Lifetime, Update Interval and Observe Interval. Then click on Next step.

    1. These parameters have the following default values:
      • Lifetime: 247
      • Update Interval: 60
      • Observe Interval: 30

    Fill optional info

  5. Go to Leshan security, click on "ADD SECURITY INFORMATION" and fill in endpoint, identity and key. Then click on "ADD".

    Add security information

  6. In Shifu Cloud. Select DTLS mode and fill in the endpoint name, PSK identity and PSK key and keep the information consistent with Leshan. Then click on Next step.

    Fill gateway info

  7. 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.

    Fill device info

  8. Fill in the endpoint name, select DTLS mode and fill in the PSK identity and PSK key. Then click on Next step.

    (This part is filled with LwM2M device configuration)

    Fill endpoint name

    Fill DTLS information

  9. Enter resource ID, number of instances and API name (If API name is not specified Shifu Cloud will use Resource ID as the API). Then click Add and Deploy.

Add api

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

Get deploy cmd

Deploy cmd

Usage(Take Leshan as an example)

  1. Use the following two instructions to check whether the deployment is successful. Copy the UDP port.

    kubectl get po -n deviceshifu
    kubectl get services -n deviceshifu

    Get deployment info

  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

    Start Leshan

  3. Go to Leshan client. Search and click on "lwm2m-device". Then click on "Temperature".

    Go to client

  4. Click on "R" to read from device.

    Get result