本文介绍如何获取网关子设备列表。

请求Topic

获取网关子设备列表Topic:{srcApp}/request/linkedge/$Your_gateway_ProductKey/$Your_gateway_DeviceName/getDeviceList

其中,$Your_gateway_ProductKey表示网关设备所属产品的ProductKey,$Your_gateway_DeviceName表示网关设备的名称。

请求Payload

{
  "requestId": "0bc458b5-47f6-472f-bd88-3624696e****", # [Required]
  "timestamp": 1571219858000,                          # ms [Optional]
  "timeout":3,                                         # 最少1s,最多120s [Optional: default 4s]
  "version": "1.0"                                     # [Optional]
}

参数说明请参见Payload通用参数说明

响应Topic

获取网关子设备列表响应Topic:linkedge/response/{srcApp}/$Your_gateway_ProductKey/$Your_gateway_DeviceName/getDeviceList

其中,$Your_gateway_ProductKey表示网关设备所属产品的ProductKey,$Your_gateway_DeviceName表示网关设备的名称。

响应Payload

{
    "requestId":"0bc458b5-47f6-472f-bd88-3624696e****",
    "timestamp": 1571219859000,
    "version":"1.0",
    "code":0,
    "message":"success",
    "params":[
        {
            "productKey":"a1Mtx4p****",
            "deviceName":"device1",
            "localOnline":"true",
            "cloudOnline":"true",
            "activationState": "activated/notActivated/activationFailed",
            "tag":[
                {
                    "key":"coordinate",
                    "value":"0:0"
                }
            ]
        }
    ]
}

完整示例

./mosquitto_sub -u <your_username> -P <your_password> -p 8883 -t linkedge/response/testApp/a1PQ982****/gw_dev1/getDeviceList -v &
./mosquitto_pub -u <your_username> -P <your_password> -p 8883 -t testApp/request/linkedge/a1PQ982****/gw_dev1/getDeviceList -m "{\"requestId\": \"0bc458b5-47f6-472f-bd88-3624696e****\", \"version\":\"1.0\"}"
linkedge/response/testApp/a1PQ982****/gw_dev1/getDeviceList {"data":[{"productKey":"a1ZJTVs****","deviceName":"LightDev","localOnline":"true","cloudOnline":"true","activationState":"activated","tags":[{"key":"type","value":"light"},{"key":"owner","value":"test"},{"key":"location","value":"livingroom"},{"key":"color","value":"white"}]},{"productKey":"a1arJcX****","deviceName":"Sensor_device1","localOnline":"true","cloudOnline":"true","activationState":"activated","tags":[{"key":"location","value":"master bedroom"}]},{"productKey":"a1KRepm****","deviceName":"modbus_tcp_dev_1","localOnline":"false","cloudOnline":"false","activationState":"notActivated","tags":[]},{"productKey":"a1Mtx4p****","deviceName":"LightSensor","localOnline":"true","cloudOnline":"true","activationState":"activated","tags":[]},{"productKey":"a1ZJTVs****","deviceName":"LightDev2","localOnline":"false","cloudOnline":"false","activationState":"notActivated","tags":[{"key":"type","value":"light"},{"key":"owner","value":"test"},{"key":"location","value":"master bedroom"},{"key":"color","value":"red"}]},{"productKey":"a1PQ982****","deviceName":"gw_dev1","localOnline":"false","cloudOnline":"false","activationState":"notActivated","tags":[]},{"productKey":"a1ZJTVs****","deviceName":"lightDevNoSpecial","localOnline":"true","cloudOnline":"true","activationState":"activated","tags":[]}],"requestId":"0bc458b5-47f6-472f-bd88-3624696e****"}
说明 其中:
  • mosquitto_submosquitto_pub是用来订阅和发送MQTT消息的命令行工具,详细信息请参见官方文档
  • <your_username>:替换为云端开启MQTT API中设置的访问边缘Open API的用户名。
  • <your_password>:替换为云端开启MQTT API中设置的访问边缘Open API的密码。