1. Introduction
1.1 Purpose & Description
The model DSGW-040-7 is smart L serial gateway product of Dusun which is used in smart home, intelligent security industry, pension services. It’s a central device, support LTE CatM1, Wi-Fi, Zigbee3.0, Bluetooth 5.2 and Z-wave wireless protocol. User can connect the network through LTE CatM1, Wi-Fi and Ethernet. In addition, smart sensors can be connected through Zigbee3.0, Bluetooth and Z-wave.
It is a smart gateway with DC power supply. It can be used in various scenarios flexibly. It can control BLE device remotely, receives the data sent by the BLE devices and sends it to servers. The Wi-Fi data rate can be up to 580Mbps and BLE data rate can be up to2Mbps.It can also supports the 5V adapter power supply. It reserves the Zigbee3.0 function ,Z-wave, 4G LTE function.
1.2 Product Feature Summary
- Support 5V adapter power supply
- Support IEEE802.11ac,IEEE802.11n,IEEE802.11g,IEEE 802.11b Protocol
- Support Network Communication of 4G Module (LTE-TDD/LTE-FDD)
- Support Bluetooth 5.2
- Support ZigBee3.0
- Support Z-WAVE
- Supporting waterproof and dustproof
- One WAN/LAN variable network port
- Back up Li battery
1.3 System block diagram
![Smart L Serial Gateway Development Instruction 1 image 33](http://dusuniot.com/wp-content/uploads/2022/07/image-33.webp)
1.4 Development Environment and Tool
![Smart L Serial Gateway Development Instruction 2 image 34](http://dusuniot.com/wp-content/uploads/2022/07/image-34.webp)
2. Reference Documentation
2.1 Standard Protocol Documentation
Specifications for zigbee3.0
- docs-05-3474-21-0csg-zigbee-specification.pdf
Specifications for BT
- Core_v4.2.pdf
- Bluez download : http://www.bluez.org/release-of-bluez-5-50/
Specifications for MQTT
- MQTT download: http://mqtt.org/documentation/
2.2 Dusun standard documentation
Dusun_Communication_Protocol_between_Cloud_and_Gateway_V0.9606.pdf
3. Configuration
3.1 Basic Configuration
3.1.1 Deploy the environment of configuration
![Smart L Serial Gateway Development Instruction 3 image 1](http://dusuniot.com/wp-content/uploads/2022/07/image-1.jpeg)
Putting the PC connect to the LAN port of the gateway by netting twine.
3.1.2 Login Password of Configuration Page
Open the website, Input Gateway IP Address: 192.168.66.1
![Smart L Serial Gateway Development Instruction 4 image 35](http://dusuniot.com/wp-content/uploads/2022/07/image-35.webp)
Enter the username and Password
Username: root
Password: root
![Smart L Serial Gateway Development Instruction 5 image 11](http://dusuniot.com/wp-content/uploads/2022/07/image-11.png)
In this page, you can check the status of system, memory, Network.
System Information: The hostname, Model, Firmware Version, Kernel Version, Local Time.
Memory Information: Total Available, Free, Buffered.
Network: IPv4 WAN Status.
3.1.3 System Configuration
You can enter the “system” menu.
![Smart L Serial Gateway Development Instruction 6 image 12](http://dusuniot.com/wp-content/uploads/2022/07/image-12.png)
Here you can configure the basic aspects of your device like its hostname or time zone.
![Smart L Serial Gateway Development Instruction 7 image 13](http://dusuniot.com/wp-content/uploads/2022/07/image-13.png)
3.1.4 Administrator Configuration
You can enter the “administrator” menu.
![Smart L Serial Gateway Development Instruction 8 image 36](http://dusuniot.com/wp-content/uploads/2022/07/image-36.webp)
You change the administrator password for accessing the device.
![Smart L Serial Gateway Development Instruction 9 image 14](http://dusuniot.com/wp-content/uploads/2022/07/image-14.png)
3.1.4 Firmware Configuration
You can enter the “Backup/flash” menu.
![Smart L Serial Gateway Development Instruction 10 image 15](http://dusuniot.com/wp-content/uploads/2022/07/image-15.png)
You can download the firmware from the current gateway to back up and restore.
And you also can upload a new firmware image to replace the running firmware.
![Smart L Serial Gateway Development Instruction 11 image 16](http://dusuniot.com/wp-content/uploads/2022/07/image-16.png)
3.1.5 Reboot
Reboots the operating system of your device.
![Smart L Serial Gateway Development Instruction 12 image 17](http://dusuniot.com/wp-content/uploads/2022/07/image-17.png)
3.2 Network Configuration
3.2.1 Network Interfaces Configuration
You can enter the “Interfaces” menu in <Network>.
![Smart L Serial Gateway Development Instruction 13 image 37](http://dusuniot.com/wp-content/uploads/2022/07/image-37.webp)
Interface Overview
![Smart L Serial Gateway Development Instruction 14 image 38](http://dusuniot.com/wp-content/uploads/2022/07/image-38.webp)
3.2.2 Interfaces-WAN Configuration
On this page, you can configure the network interfaces. You can bridge several interfaces by ticking the “bridge interfaces” field and enter the names of several network interfaces separated by spaces. You can also use VLAN notation INTERFACE.VLANNR (e.g.: eth0.1).
![Smart L Serial Gateway Development Instruction 15 image 18](http://dusuniot.com/wp-content/uploads/2022/07/image-18.png)
3.2.3 Interfaces – WAN6 Configuration
On this page, you can configure the network interfaces. You can bridge several interfaces by ticking the “bridge interfaces” field and enter the names of several network interfaces separated by spaces. You can also use VLAN notation INTERFACE.VLANNR (e.g.: eth0.1).
![Smart L Serial Gateway Development Instruction 16 image 19](http://dusuniot.com/wp-content/uploads/2022/07/image-19.png)
3.2.4 Interfaces – WANPPP Configuration
On this page, you can configure the network interfaces. You can bridge several interfaces by ticking the “bridge interfaces” field and enter the names of several network interfaces separated by spaces. You can also use VLAN notation INTERFACE.VLANNR (e.g.: eth0.1).
![Smart L Serial Gateway Development Instruction 17 image 20](http://dusuniot.com/wp-content/uploads/2022/07/image-20.png)
3.2.5 Interfaces – LAN Configuration
On this page, you can configure the network interfaces. You can bridge several interfaces by ticking the “bridge interfaces” field and enter the names of several network interfaces separated by spaces. You can also use VLAN notation INTERFACE.VLANNR (e.g.: eth0.1).
![Smart L Serial Gateway Development Instruction 18 image 21](http://dusuniot.com/wp-content/uploads/2022/07/image-21.png)
3.2.6 Network Diagnostics
![Smart L Serial Gateway Development Instruction 19 image 22](http://dusuniot.com/wp-content/uploads/2022/07/image-22.png)
3.3 MQTT server configuration
You can enter the “MQTT server config” menu in <dusun>.
![Smart L Serial Gateway Development Instruction 20 image 23](http://dusuniot.com/wp-content/uploads/2022/07/image-23.png)
You can configure the MQTT server: MQTT server Address, MQTT server Port, MQTT keep Alive Time, MQTT User Name, MQTT Password.
![Smart L Serial Gateway Development Instruction 21 image 24](http://dusuniot.com/wp-content/uploads/2022/07/image-24.png)
3.4 zigbee 3.0 manage
You can enter the “zigbee3.0 manage” menu in <dusun>.
![Smart L Serial Gateway Development Instruction 22 image 39](http://dusuniot.com/wp-content/uploads/2022/07/image-39.webp)
You can press the<permit> button to pair with Zigbee devices.
If pair successful, you can see the sensor information.
![Smart L Serial Gateway Development Instruction 23 image 40](http://dusuniot.com/wp-content/uploads/2022/07/image-40.webp)
3.5 Remote Assistance
You can enter the “remote assistance” menu in <dusun> .
![Smart L Serial Gateway Development Instruction 24 image 41](http://dusuniot.com/wp-content/uploads/2022/07/image-41.webp)
It can Remote connect back so that doing some develop work and upgrade.
![Smart L Serial Gateway Development Instruction 25 image 25](http://dusuniot.com/wp-content/uploads/2022/07/image-25.png)
3.6 Z-WAVE Manage
You can enter the “Zwave Manage” menu in <dusun> .
![Smart L Serial Gateway Development Instruction 26 image 26](http://dusuniot.com/wp-content/uploads/2022/07/image-26.png)
<Include>button: It can let gateway pair with sensors.
<Exclude>button: It can let gateway unpair with sensors
3.7 LTE Configuration
You can enter the “4G3G Argments config” menu in <dusun>
![Smart L Serial Gateway Development Instruction 27 image 27](http://dusuniot.com/wp-content/uploads/2022/07/image-27.png)
You can set the APN in this page.
3.8 Wi-Fi Configuration
You can enter the “Wi-Fi manage” menu in <dusun>
![Smart L Serial Gateway Development Instruction 28 image 28](http://dusuniot.com/wp-content/uploads/2022/07/image-28.png)
You can set the mode of Wi-Fi, AP or STA.
3.8.1 AP mode
If you set AP mode, The gateway enter the AP mode. You can set the SSID ,Wi-Fi Encryption, and Wi-Fi key .
3.8.2 STA mode
If you set STA mode, The gateway enter the STA mode . You can set the SSID and WI-FI key that you want to connect the router.
4. Configuration
An IoT application on the gateway is normally fetching data from IoT devices or sensors, then processing data and sending data to the cloud. The Dusun gateways support most protocols for these connectivity types and suit for many applications. Common connectivity protocols include BLE(4.x/5.0/Mesh), ZigBee 1.2/3.0, Z-Wave, TCP/UDP, etc.
4.1 Communication with ZigBee IoT devices
This sub chapter will discuss how to write an application for the gateway which communicates with a ZigBee sensor/device to get corresponding sensor data.
4.1.1 UBUS in OpenWrt
UBUS is a message bus in OpenWrt. Its main function is to realize information exchange between different applications. When UBUS starts, it runs the ubusd process in the background, which listens for a UNIX socket to communicate with other applications. Other applications can communicate with libubox based on the interface provided by libubox (or implemented by themselves). Figure 1 shows the simplified gateway OpenWrt system architecture.
![Smart L Serial Gateway Development Instruction 29 image 29](http://dusuniot.com/wp-content/uploads/2022/07/image-29.png)
Figure 1 the gateway system architecture
4.1.2 Getting ZigBee sensors/devices data from UBUS
Dusun has provided a library (please see the attached code files) in which a set of APIs can be used to fetch data from the ZigBee sensors/devices. The API library includes the static link library (librbsdk.a) and a corresponding header file (rbsdk.h). The API functions can be seen from the header file (rbsdk.h). Some core functions are listed below:
/*Function to initialize the SDK. */
int rbsdk_init(void *unused, int (*msgcb)(char *src, char *dest, char *msg));
/*Function to get the SDK version. */
int rbsdk_vers(char *version);
/*A General Call Functions. */
int rbsdk_call(char *mac, char *attr, int setOrget, void *jvalue);
/*Function to Set the Message Callback. */
int rbsdk_dev_msgcb_set(stDevMsgCb_t *dmc);
/*Function to Get Device list. */
int rbsdk_list_dev();
/*Functoin to Send adding device Request. */
int rbsdk_add_dev(char *mac, char *type);
/*Function to Send Deleting Device Request. */
int rbsdk_del_dev(char *mac);
/*Function to Send Add Lock PassWord Request. */
int rbsdk_dev_lock_add_pass(char *mac, int type, int id, int passVal1, int passVal2, int startTime, int endTime, int suspend);
/*Function to Send Delete Lock Password Request. */
int rbsdk_dev_lock_del_pass(char *mac, int type, int id);
/*Function to Send Modify Lock Password Request. */
int rbsdk_dev_lock_mod_pass(char *mac, int type, int id, int passVal1, int passVal2, int startTime, int endTime, int suspend);
/*Function to Send Clear Lock Password Request. */
int rbsdk_dev_lock_clr_pass(char *mac, int type);
/*Function to Send Set Dynamic Password Seed Request. */
int rbsdk_dev_lock_set_seed(char *mac, int id, int seed, int interval, int startTime, int endTime);
/*Function To Send Light OnOff Request. */
int rbsdk_dev_light_onoff(char *mac, int onoff);
/*Function to Send Window Controller's Open Request. */
int rbsdk_dev_winctr_open(char *mac);
/*Function to Send Window Controller's Stop Request. */
int rbsdk_dev_winctr_stop(char *mac);
/*Function to Send Window Controller's Close Request.*/
int rbsdk_dev_winctr_close(char *mac);
/*Function to Send Air conditioner Onoff Request.*/
int rbsdk_dev_air_onoff(char *mac, int onoff);
/*Function to Send Air conditioner Mode Request.*/
int rbsdk_dev_air_mode(char *mac, int mode);
/*Function to Send Air conditioner Fan Request. */
int rbsdk_dev_air_fan(char *mac, int fan);
/*Function to Send Air conditioner temp Request. */
int rbsdk_dev_air_temp(char *mac, int temp_mode, int dir, int temp_delt);
/*A callback function for pushing the sensor command data reported by the sensor using a customized cluster to the application*/
int (*rpt_cmd)(char *mac, int ep, int cluster, int cmd, char *buf, int len);
/*A callback function for pushing the sensor attribute data reported by the sensor using a customized cluster to the application*/
int (*rpt_attr)(char *mac, int ep, int cluster, int attr, char *buf, int len);
/*A function for sending the command data to the sensor using a customized cluster */
int rbsdk_zcl_cmd(char *mac, int ep, int cluster, int cmdid, char *data, int len);
/*A function for sending the attribute data to the sensor using a customized cluster */
int rbsdk_set_attr(char *mac, int ep, int cluster, int attrid, char *data, int len);
/*A function for sending the get atrribute command to the sensor using a customized cluster */
int rbsdk_get_attr(char *mac, int ep, int cluster, int attrid);
4.1.3 A sample: communicate with a door ZigBee sensor using the APIs
The code below shows how to use the provided APIs to get a Dusun door contact sensor data. First, we should init the sdk by calling rbsdk_init(NULL, NULL); Then, we write four callback functions, and fill a stDevMsgCb struct which is used by rbsdk_dev_msgcb_set to set the callback functions. We will get the data when the callback functions are invoking. For example, the rpt_door function can print the door status reported. If your sensor report data using a customized ZigBee cluster, you should write the rpt_cmd and rpt_attr callback functions in which you can get the sensor data to be processed.
#include <stdio.h>
#include <stdlib.h>
#include “rbsdk.h”
int rpt_dev_added(char *mac, char *ModelStr, char *model, int type, int battery) {
printf("[%s] - %s added\n", __func__, mac);
return 0;
}
int rpt_dev_deled(char *mac) {
printf("[%s] - %s deleted\n", __func__, mac);
return 0;
}
int rpt_dev_online(char *mac, int online) {
printf("[%s] - %s online : %d\n", __func__, mac, online);
return 0;
}
int rpt_door(char *mac, int door) {
printf("[%s] - %s door status:%d\n", __func__, mac, door);
return 0;
}
int main(int argc, char *argv[]) {
rbsdk_init(NULL, NULL);
char sver[32];
rbsdk_vers(sver);
printf("rbsdk version : %s\n", sver);
stDevMsgCb_t dmc = {
.rpt_dev_added = rpt_dev_added,
.rpt_dev_deled = rpt_dev_deled,
.rpt_dev_online = rpt_dev_online,
.rpt_dev_battery = NULL,
.rpt_dev_lowpower = NULL,
.rpt_temp = NULL,
.rpt_humi = NULL,
.rpt_door = rpt_door,
.rpt_pir = NULL,
.rpt_leak = NULL,
.ret_lock_password_add = NULL,
.ret_lock_password_del = NULL,
.ret_lock_password_mod= NULL,
.ret_lock_password_clr = NULL,
.ret_lock_dynamic_seed = NULL,
.rpt_lock_checkrecord = NULL,
.rpt_lock_system_locked= NULL,
.rpt_smoke = NULL,
.rpt_light_onoff = NULL,
.rpt_winctr_status = NULL,
.rpt_winctr_percent = NULL,
.rpt_cmd = NULL,
.rpt_attr = NULL,
};
rbsdk_dev_msgcb_set(&dmc);
while (1) {
sleep (1);
}
return 0;
}