本文介绍如何控制网关场景联动规则的开启和关闭。

请求Topic

  • 开启场景联动规则Topic:{srcApp}/request/linkedge/$Your_gateway_ProductKey/$Your_gateway_DeviceName/enableScene
  • 关闭场景联动规则Topic:{srcApp}/request/linkedge/$Your_gateway_ProductKey/$Your_gateway_DeviceName/disableScene

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

请求Payload

{
  "requestId": "0bc458b5-47f6-472f-bd88-3624696e****",
  "version": "1.0",
  "params": [
    {
      "id": "id1"
    }
  ]
}

其中:

  • 通用参数说明请参见Payload通用参数说明
  • params:必选参数,输入场景规则的ID等信息,params中必须包含至少一组对象或至多32组对象。

响应Topic

  • 开启场景联动规则响应Topic:linkedge/response/{srcApp}/$Your_gateway_ProductKey/$Your_gateway_DeviceName/enableScene
  • 关闭场景联动规则响应Topic:linkedge/response/{srcApp}/$Your_gateway_ProductKey/$Your_gateway_DeviceName/disableScene

其中,{srcApp}是发布消息的App名称,$Your_gateway_ProductKey表示网关设备所属产品的ProductKey,$Your_gateway_DeviceName表示网关设备的名称。

响应Payload

{
    "params":[
        {
            "id":"123000000",
            "code":1,
            "message":"no such scene"
        },
        {
            "id":"a08d6c08bc1a440693ba9c9c8166****",
            "code":0,
            "message":"success"
        }
    ],
    "requestId":"0bc458b5-47f6-472f-bd88-3624696e****",
    "version":"1.0",
    "timestamp":1572276907529,
    "code":0,
    "message":"success"
}

完整示例

  • 开启场景联动规则
    ./mosquitto_sub -u <your_username> -P <your_password> -p 8883 -t linkedge/response/testApp/+/+/enableScene -v &
    ./mosquitto_pub -u <your_username> -P <your_password> -p 8883 -t testApp/request/linkedge/a1PQ982****/gw_dev1/enableScene -m "{\"requestId\": \"0bc458b5-47f6-472f-bd88-3624696e****\",\"params\":[{\"id\":\"a08d6c08bc1a440693ba9c9c8166****\"},{\"id\":\"123000000\"}]}"
    linkedge/response/testApp/a1PQ982****/gw_dev1/enableScene {"params":[{"id":"123000000","code":1,"message":"no such scene"},{"id":"a08d6c08bc1a440693ba9c9c8166****","code":0,"message":"success"}],"requestId":"0bc458b5-47f6-472f-bd88-3624696e****","version":"1.0","timestamp":1572276907529,"code":0,"message":"success"}
  • 关闭场景联动规则
    ./mosquitto_sub -u <your_username> -P <your_password> -p 8883 -t linkedge/response/testApp/+/+/disableScene -v &
    ./mosquitto_pub -u <your_username> -P <your_password> -p 8883 -t testApp/request/linkedge/a1PQ982****/gw_dev1/disableScene -m "{\"requestId\": \"0bc458b5-47f6-472f-bd88-3624696e****\",\"params\":[{\"id\":\"a08d6c08bc1a440693ba9c9c8166****\"}]}"
    linkedge/response/testApp/a1PQ982****/gw_dev1/disableScene {"params":[{"id":"a08d6c08bc1a440693ba9c9c8166****","code":0,"message":"success"}],"requestId":"0bc458b5-47f6-472f-bd88-3624696e****","version":"1.0","timestamp":1572277158528,"code":0,"message":"success"}
说明 其中:
  • mosquitto_submosquitto_pub是用来订阅和发送MQTT消息的命令行工具,详细信息请参见官方文档
  • <your_username>:替换为云端开启MQTT API中设置的访问边缘Open API的用户名。
  • <your_password>:替换为云端开启MQTT API中设置的访问边缘Open API的密码。