Dusun smart gateways are Linux based and programmable. Then Dusun’s gateway can use any standard protocols to transfer data into Cloud.

Gateways communicate with sensors/devices over varying connectivity types, and then pre-process and filter the data being generated by sensors/devices to decrease transmission.

Finally, the processed data are translated into a standard protocol such as MQTT/COAP to be sent to the cloud through internet connections.

In fact, Dusun smart gateways are Linux based and programmable. Then Dusun’s gateway can use any standard protocols to transfer data into Cloud. Next, we will show you how to transfer data using a standard lwm2m protocol based on the open source project Wakayama. This means the gateways can be changed into a lwm2m client which transfers data received from sensors by lwm2m protocol to a lwm2m sever.

For simplicity, we will use the The lwm2m server at https://leshan.eclipseprojects.io/ which is a leshan based sandbox.

The Video: Change Dusun's IoT Gateway into a LwM2M Client

1. What is LwM2M?

OMA Lightweight M2M is a protocol from the Open Mobile Alliance for M2M or IoT device management.

  • On top of CoAP
  • UDP and SMS transport layer support
  • Simple Object-based resource model
  • Basic M2M functionalities: LWM2M Server, Access Control, Device,
  • Connectivity, Firmware Update, Location, Connectivity Statistics
  • DTLS based security​

The LWM2M manages data through Object/Instance/Resource. Figure 1 shows anbulb device can have 1 objects corresponding with 3 instance ids(0/1/2). Each instance has 2 resource ids.

DM 20220630163508 011
Figure 1. lmw2m object

2. Build the Wakaama LwM2M Client

The Wakaama demo client is used to demonstrate observe mode. Normally we can make a program for the gateway on a PC and cross-compile the program which will be copied to the gateway to run. The following steps show the procedure:

  1. open a terminal in a Linux PC in which git and cmake are installed.
  2. Clone the Wakaama source into a local folder. E.g.: /home/software Git clone https://github.com/eclipse/wakaama
  3. Download the cross compile OpenWrt-Toolchain from the following website (figure 2):


DM 20220630163508 012
Figure 2. the OpenWrt-Toolchain for cross-compiling

4. Decompress the downloaded OpenWrt Toolchain to a local folder (E.g.: home/software/) and add the toolchain path to the system path:

Open /etc/bash.bashrc and add the following to the end of the file:



Execute source /etc/bash.bashrc in a terminal.

5. Execute the following commands to build the lwm2mclient:

cd /home/software/wakaama/examples/client

mkdir build

cd build

cmake-gui .. (configure the cross-compiler according to figure 3)


DM 20220630163508 013
Figure 3. the configuration of cross-compiler in cmake-gui

The compiled lwm2mclient features nine LWM2M objects:

  • Security Object (id: 0)
  • Server Object (id: 1)
  • Access Control Object (id: 2) as a skeleton
  • Device Object (id: 3) containing hard-coded values from the Example LWM2M Client of Appendix E of the LWM2M Technical Specification.
  • Connectivity Monitoring Object (id: 4) as a skeleton
  • Firmware Update Object (id: 5) as a skeleton.
  • Location Object (id: 6) as a skeleton.
  • Connectivity Statistics Object (id: 7) as a skeleton.
  • Test Object (id: 31024) with the following description:


Object | ID | Instances | Mandatory |

Test | 31024 | Yes | No |


Supported Multiple

Name | ID | Operations | Instances | Mandatory | Type | Range |

test | 1 | R/W | No | Yes | Integer | 0-255 |

exec | 2 | E | No | Yes | | |

dec | 3 | R/W | No | Yes | Float | |

3. Test the LwM2M client

Connecting the Dusun gateway and execute commands in the opened console:

./lwm2mclient -4 –h leshan.eclipseprojects.io (-4 means ipv4; -h means server)

The connection procedure is shown below:

DM 20220630163508 014
Figure 4. lwm2m client connection procedure

If the connection succeeds, the program will print state: STATE_READY. The connection id above is KMCstnKU3g. Connect https://leshan.eclipseprojects.io, we can find our clients by registration id(figure 5):

DM 20220630163508 015
Figure 5. the connected clients on the test leshan sandbox

Click our clients, and we can find the 9 objects listed above. Figure 6 shows the device(/3) object. Figure 7 shows the test(/31024) object:

DM 20220630163508 016
Figure 6. the device object
DM 20220630163508 017
Figure 7. the test object
Now, we can do data communication by lwm2m protocol. Clicking the read button right to the Battery Level whose resource is /3/0/9. Then the value[100] is read from the client and screened on the web which is shown as below:
DM 20220630163508 018
If we type: “change /3/0/9 88” in the client console and activate the observe button for resource /3/0/9, the value will be changed to 88 immediately which is shown as below.
DM 20220630163508 019
DM 20220630163508 020
By clicking the read button right to the test object instance 10, we can get all the values in the instance. The figure below shows the situation.
DM 20220630163508 021
By executing “change /31024/10/1 99” and “change /31024/10/3 5.5”, We can see the values in the server web has changed to 99 and 5.5 as illustrated in figures below:
DM 20220630163508 022
DM 20220630163508 023

4. Developing your LwM2M Client On Dusun's Gateway

1) Developing your LWM2M client (for the Light Device and the Sensor device) is done by modifying the client example source code in the ../wakaama-master/examples/client folder on your Linux PC.

2) Create new C file for every new object in your LWM2M client. For example, for the LWM2M client in the Light Device, you need to create a new object_light_profile.c file for the Light Profile object by modifying the object_device.c file in the ../wakaamamaster/examples/client folder. Adjust the write and read functions for the Light Profile object in object_light_profile.c. Adjust as well the get_object and free_object functions in object_light_profile.c.

3) Adjust the lwm2mclient.c and lwm2mclient.h files in ../wakaamamaster/examples/client folder accordingly. In lwm2mclient.c, you need to initialize the Light Profile object in the beginning of the main function, and free the object memory allocation in the end of the main function. In lwm2mclient.c, you also need to set the right number of objects in your LWM2M client.

4) Adjust file ../wakaama-master/core/liblwm2m.h by adding the ID of the new object under line 167.

5) Adjust file ../wakaama-master/examples/client/CMakeLists.txt to include the new object file and any new libraries used in the modified code.

6) Cross-compile the new client and run the new lwm2mclient on the Dusun gateway.

You can get more information from the following website:
DUSUN office website:
DUSUN gateway link:
wakaama & leshan link:
Download this Document
How to change Dusun’s IoT gateway into an LWM2M client?