C.2 MQTT API
MQTT API is a wrapper around HTTP, but based on MQTT characteristics, requests and responses need to be separated
C.2.1 Request
topic is control/{gateway_id}/v1 where gateway_id is the gateway ID Request payload is
{
"cmd_id": "uuid",
"method": "PUT",
"url": "/api/device/{device_name}/control_by_name",
"data": {
"key": "M100",
"value": 1,
"value_type": 1
}
}其中
- cmd_id is the unique command number, it is recommended to use uuid, the payload of the return topic will match it
- url refers to http api
- method refers to http api
- data refers to the request body of http api, if there is no request body, use “data”:null
C.2.2 Response
topic is echo/{gateway_id}/v1 where gateway_id is the gateway ID After sending the control topic, there will be an echo Response payload is
其中 * cmd_id is the unique command number, matching the cmd_id in control * msg, request return value * ret if the request is successful, the value is 0, if it fails, refer to the http_statuscode of http api