Publish service
Publish service provides message delivery function to the device from ThingScale.
By Publish service, it will deliver the command to the device that are subscribed to the MQTT broker of ThingScale.
Destination MQTT Topic
| Topic | Payload |
|---|---|
| [device_token]/[device_id]/subscribe | contents of "payload" |
(NOTE) Messages that are commonly published to the device includes a control command .
About MQTT Topic/message
In the Publish Service, device token corresponding to the device ID is published embedded in MQTT topic.
On the device side, it is possible to receive a message from the Publish Service by to subscribe to MQTT broker ThingScale the following topics.
Message (payload) Please specify in the freestyle.(ThingScale does not concern the content of the payload.)
About Destination Device
Device that receives the message, prior to the device API: You must have been registered at (see Device service list).
In fact MQTT publish API returns an error if the ThingScale device registry is wrong if the device ID does not exist will not be performed.
Publish message
Publish MQTT message to device.
Request Header:
| Header: | Description |
|---|---|
| X-APITOKEN | API_TOKEN_HERE |
Request Body:
| Elements | Type | Descritption |
|---|---|---|
| qos | number | 0:MQTT QoS0(At most once),1:MQTT QOS1(At least once) |
| payload | string | MQTT payload(JSON) |
POST https://m.thingscale.io/v2/publish/{device_id}
Parameters: device_id (String)
Sample payload:
{
"qos" : 0 or 1, // default:0
"payload" : "dout=on"
}
Sample curl(Publish message to 'test_device01' with QoS0)
(On Platform side)
curl -X POST -H "X-APITOKEN: API_TOKEN_HERE" -k -d '{"payload" : "door=open"}' https://m.thingscale.io/v2/publish/test_device01
(On Device side)
mosquitto_sub -h m.thingscale.io -t '<device_token>/<device_id>/subscribe' -u <ThingScale_ID> -P <device_token> -d -q 0
Response code:
| HTTP status: | Desc./Response body |
|---|---|
| 200 OK | Transaction OK. |
| 400 Bad Request | { "error": "BAD_JSON_FORMAT" } // check json array. |
| 401 Unauthorized | {"error": "AUTH_REQUIRED"} |