Gateway and sub equipment development practice

Gateway and sub equipment development practice (java)

In many scenarios of the Internet of Things, the terminal device itself does not have the ability to connect to the Internet, so how can data go to the cloud?

IoT IoT platform supports MQTT direct connection of devices, and also supports devices to be attached to the gateway. As a sub device of the gateway, the gateway agent accesses IoT IoT platform.

At this time, in addition to establishing MQTT connection with IoT IoT platform as IoT gateway device (with identity triplet) and sending and receiving data, the gateway device is also responsible for the management of sub devices, including:

• Gateway adds sub device network topology relationship

• Sub equipment multiplexing gateway mqtt connection channel is online

• The gateway reports the sub device data to the cloud

• The gateway receives instructions and forwards them to the sub devices

• The gateway reports that the sub equipment is offline

• Gateway deletes sub device network topology relationship

The communication protocol between the gateway and the sub devices is determined by the local network, which can be http, mqtt, ZigBee, Modbus, BLE, OPC-UA, etc. This part of logic is implemented by the gateway, and the IoT SDK does not include this part of functions.

1. Create a gateway product

When creating a gateway product, you need to select the node type: Gateway, which refers to the direct connected device that can mount the sub device. The gateway can manage the sub devices, maintain the topology relationship with the sub devices, and synchronize the topology relationship to the cloud.

2. The gateway equipment goes online

LinkKitInitParams params = new LinkKitInitParams();

DeviceInfo gatewayInfo = new DeviceInfo();

gatewayInfo. productKey = gateway.productKey;

gatewayInfo. deviceName = gateway.deviceName;

gatewayInfo. deviceSecret = gateway.deviceSecret;

params. deviceInfo = gatewayInfo;

LinkKit.getInstance(). init(params, ILinkKitConnectListener)

The online gateway can be seen on the console, and the device status is online

3. Add network topology relationship

DeviceInfo deviceInfo = new DeviceInfo();

deviceInfo. productKey = productKey;

deviceInfo. deviceName = deviceName;

deviceInfo. deviceSecret = deviceSecret;

LinkKit.getInstance().getGateway().gatewayAddSubDevice(

DeviceInfo,//sub device identity

SubDeviceConnectListener)

4. Sub equipment online

DeviceInfo deviceInfo = new DeviceInfo();

deviceInfo. productKey = productKey;

deviceInfo. deviceName = deviceName;

deviceInfo. deviceSecret = deviceSecret;

LinkKit.getInstance().getGateway().gatewaySubDeviceLogin(

DeviceInfo,//sub device identity

ISubDeviceActionListener)

Information about access to the official website viewed by the sub device

5. Data reported by sub equipment

DeviceInfo deviceInfo = new DeviceInfo();

deviceInfo. productKey = productKey;

deviceInfo. deviceName = deviceName;

deviceInfo. deviceSecret = deviceSecret;

LinkKit.getInstance().getGateway().gatewaySubDevicePublish(

Topic,//sub device topic

Data,//data

DeviceInfo,//sub device identity

ISubDeviceActionListener)

6. Sub device subscription topic

DeviceInfo deviceInfo = new DeviceInfo();

deviceInfo. productKey = productKey;

deviceInfo. deviceName = deviceName;

deviceInfo. deviceSecret = deviceSecret;

LinkKit.getInstance().getGateway().gatewaySubDeviceSubscribe(

Topic,//Sub device subscription topic

DeviceInfo,//sub device identity

ISubDeviceActionListener)

7. Sub equipment offline

DeviceInfo deviceInfo = new DeviceInfo();

deviceInfo. productKey = productKey;

deviceInfo. deviceName = deviceName;

deviceInfo. deviceSecret = deviceSecret;

LinkKit.getInstance().getGateway().gatewaySubDeviceLogout(

DeviceInfo,//sub device identity

ISubDeviceActionListener)

8. Delete the sub equipment network topology

DeviceInfo deviceInfo = new DeviceInfo();

deviceInfo. productKey = productKey;

deviceInfo. deviceName = deviceName;

deviceInfo. deviceSecret = deviceSecret;

LinkKit.getInstance().getGateway().gatewayDeleteSubDevice(

DeviceInfo,//sub device identity

ISubDeviceRemoveListener)

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us