By Yi Cheng
In many IoT scenarios, terminal devices themselves do not access the Internet. So, you may be wondering, then, how can data be migrated to the cloud?
Well, the IoT Platform in the cloud supports direct connections on devices using a special protocol called MQTT, which is a machine-to-machine connectivity protocol specifically designed for IoT scenarios.
Interestingly, this sort of connection protocol also supports the mounting of a device onto the gateway so as to serve as a sub-device of the gateway, which can in turn allow the gateway proxy to connect the device to the IoT Platform. Then, following this, the gateway device itself, serving as the IoT gateway device, establishes the MQTT connections to the IoT Platform to send and receive data. In addition, the device is also responsible for managing the sub-device. As such, all of this thus also includes the following operations:
Also, depending on the local network, the communication protocol between the gateway and the sub-device could be HTTP, MQTT, ZigBee, Modbus, BLE, OPC-UA, among other protocols. This logic is implemented by the gateway. These connectivity features are cannot be provided, however, by the IoT SDK.
Now, let's see how you can have a go at setting up the scenario discussed above, specifically the gateway and sub-device scenario. To do so, you'll need to follow these steps:
To create a network product, you'll need to select a node type-which, for this tutorial, you'll want it to be gateway-this will serve as the direct connection means that can mount sub-devices. The gateway can manage sub-devices, maintain the topological relationships that exists with sub-devices, and synchronize these topological relationships to the cloud.
For reference, the topological relationship that exists between a gateway and its sub-devices is shown in the following figure:
You can set the following parameters to connect the gateway device.
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)
When the gateway device is connected, it is shown in the console, with the status of "Online".
You can set the following parameters to add the network topology relationship.
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.productKey = productKey;
deviceInfo.deviceName = deviceName;
deviceInfo.deviceSecret = deviceSecret;
LinkKit.getInstance().getGateway().gatewayAddSubDevice(
deviceInfo, // the ID of the sub-device
SubDeviceConnectListener)
You can alternatively do this on the console.
You can set the following parameters to connect the sub-device.
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.productKey = productKey;
deviceInfo.deviceName = deviceName;
deviceInfo.deviceSecret = deviceSecret;
LinkKit.getInstance().getGateway().gatewaySubDeviceLogin(
deviceInfo, // the ID of the sub-device
ISubDeviceActionListener)
You can alternatively do this on the console.
And you can view the connection information of the sub-device on the console.
You can set the following parameters to report the data of the sub-device.
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.productKey = productKey;
deviceInfo.deviceName = deviceName;
deviceInfo.deviceSecret = deviceSecret;
LinkKit.getInstance().getGateway().gatewaySubDevicePublish(
topic, // sub-device topic
data, // the data
deviceInfo, // the ID of the sub-device
ISubDeviceActionListener)
You can alternatively use the console.
You can set the following parameters to make the sub-device subscribe to topics.
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.productKey = productKey;
deviceInfo.deviceName = deviceName;
deviceInfo.deviceSecret = deviceSecret;
LinkKit.getInstance().getGateway().gatewaySubDeviceSubscribe(
topic, // sub-device subscription topic
deviceInfo, // the ID of the sub-device
ISubDeviceActionListener)
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.productKey = productKey;
deviceInfo.deviceName = deviceName;
deviceInfo.deviceSecret = deviceSecret;
LinkKit.getInstance().getGateway().gatewaySubDeviceLogout(
deviceInfo, // the ID of the sub-device
ISubDeviceActionListener)
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.productKey = productKey;
deviceInfo.deviceName = deviceName;
deviceInfo.deviceSecret = deviceSecret;
LinkKit.getInstance().getGateway().gatewayDeleteSubDevice(
deviceInfo, // the ID of the sub-device
ISubDeviceRemoveListener)
Building a Simple Entry-Exit Monitoring System on Alibaba Cloud IoT Platform
Alibaba Cloud Native Community - March 14, 2023
Alibaba Cloud Native Community - April 4, 2023
Alibaba Cloud ECS - March 12, 2019
Alibaba Cloud Native - August 14, 2024
Alibaba Cloud Community - May 16, 2022
Alibaba Clouder - April 14, 2021
A cloud solution for smart technology providers to quickly build stable, cost-efficient, and reliable ubiquitous platforms
Learn MoreA message service designed for IoT and mobile Internet (MI).
Learn MoreProvides secure and reliable communication between devices and the IoT Platform which allows you to manage a large number of devices on a single IoT Platform.
Learn MoreMore Posts by GXIC