首页 > 云计算 > 公有云实践 > IoT物联网平台:网关与子设备开发实战——实践类

在很多物联网场景中,终端设备本身没有连接互联网能力,那么数据如何上云呢?
IoT物联网平台支持设备MQTT直连,也支持的设备挂载到网关上,作为网关的子设备,由网关代理接入IoT物联网平台。
这时候网关设备除了自身作为IoT网关设备(拥有身份三元组)与IoT物联网平台建立MQTT连接,收发数据,还要负责子设备的管理,包括:
网关和子设备通信的协议由本地网络决定,可以是http,mqtt,ZigBee,Modbus,BLE,OPC-UA等,这部分逻辑由网关实现,IoT SDK不包含这部分功能。
创建网关产品时,需要选择节点类型:网关,即指可以挂载子设备的直连设备。网关可以管理子设备、可以维持与子设备的拓扑关系,并将该拓扑关系同步到云端。

网关与子设备的拓扑关系如下图所示:
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)
网关上线可以在控制台看到,设备状态是 在线

DeviceInfo deviceInfo = new DeviceInfo(); deviceInfo.productKey = productKey; deviceInfo.deviceName = deviceName; deviceInfo.deviceSecret = deviceSecret; LinkKit.getInstance().getGateway().gatewayAddSubDevice( deviceInfo, //子设备身份 SubDeviceConnectListener)

DeviceInfo deviceInfo = new DeviceInfo(); deviceInfo.productKey = productKey; deviceInfo.deviceName = deviceName; deviceInfo.deviceSecret = deviceSecret; LinkKit.getInstance().getGateway().gatewaySubDeviceLogin( deviceInfo, //子设备身份 ISubDeviceActionListener)

子设备查看到接入官网的信息

DeviceInfo deviceInfo = new DeviceInfo(); deviceInfo.productKey = productKey; deviceInfo.deviceName = deviceName; deviceInfo.deviceSecret = deviceSecret; LinkKit.getInstance().getGateway().gatewaySubDevicePublish( topic, //子设备topic data, //数据 deviceInfo, //子设备身份 ISubDeviceActionListener)

DeviceInfo deviceInfo = new DeviceInfo(); deviceInfo.productKey = productKey; deviceInfo.deviceName = deviceName; deviceInfo.deviceSecret = deviceSecret; LinkKit.getInstance().getGateway().gatewaySubDeviceSubscribe( topic, //子设备订阅Topic deviceInfo, //子设备身份 ISubDeviceActionListener)
DeviceInfo deviceInfo = new DeviceInfo(); deviceInfo.productKey = productKey; deviceInfo.deviceName = deviceName; deviceInfo.deviceSecret = deviceSecret; LinkKit.getInstance().getGateway().gatewaySubDeviceLogout( deviceInfo, //子设备身份 ISubDeviceActionListener)
DeviceInfo deviceInfo = new DeviceInfo(); deviceInfo.productKey = productKey; deviceInfo.deviceName = deviceName; deviceInfo.deviceSecret = deviceSecret; LinkKit.getInstance().getGateway().gatewayDeleteSubDevice( deviceInfo, //子设备身份 ISubDeviceRemoveListener)
物联网平台产品介绍详情:https://www.aliyun.com/product/iot/iot_instc_public_cn

阿里云物联网平台客户交流群
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70017009/viewspace-2937424/ ,如需转载,请注明出处,否则将追究法律责任。