IoT Resources Library

Including IoT development kits, implementation reference documents, and the newest advances of the internet of things. To help more developers do more flexible applications on their IoT projects.

How to Change Dusun's IoT Gateway into a LwM2M Client? 

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

figure1 LWM2M object.png

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

  3.  Download the cross compile OpenWrt-Toolchain from the following website (figure 2):

Figure 2 the OpenWrt-Toolchain for cross

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)


Figure 3 the configuration of cross-comp

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  (-4 means ipv4; -h means server)

The connection procedure is shown below:

Figure 4 lwm2mclient connection procedur

Figure 4. lwm2m client connection procedure

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

Figure 5 the connected clients on the te

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:

Figure 6 the device object.png

Figure 6. the device object

Figure 7 the test object.png

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:

Figure 8.png

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.

Figure 9.png
Figure 10.png