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.
OMA Lightweight M2M is a protocol from the Open Mobile Alliance for M2M or IoT device management.
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.
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:
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:
cmake-gui .. (configure the cross-compiler according to figure 3)
The compiled lwm2mclient features nine LWM2M objects:
Object | ID | Instances | Mandatory |
Test | 31024 | Yes | No |
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 | |
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:
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)：
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:
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.