By using a MQTT Transport in this chapter, we describe the publish/subscribe ThingScale built-in MQTT Broker.
Panel | |
---|---|
On this page:
|
Publish Publish / Subscribe
...
MQTT Endpoint
Protocol | Address:Port |
---|---|
MQTT | mqtt://m.thingscale.io:1883 |
MQTTS | mqtts://m.thingscale.io:8883 |
Websocket | ws://m.thingscale.io:8083 |
Secure Websocket | wss://m.thingscale.io:8084 |
Version: 3.1 and 3.1.1
Support:
QoS0(At most once) and QoS1(At least once) and QoS2(Exactly once)
Wills:Yes
Retained Message:Yes
Clean sesson/Durable connections:Yes
Limitation:
Publish API cannot support QoS2
MQTT Parameters
Client ID is between 1 and 23 characters long.We recommned <Device_ID>_<random suffix>
Username:ThingScale_ID(U******)
Password:DEVICE_TOKEN
MQTT Topic
Pub/Sub | Topic | Payload |
---|---|---|
Publish |
(NOTE)TAG_NAME is OPTIONAL | JSON or Numeric |
Publish(binary_mode) |
(NOTE)TAG_NAME is OPTIONAL | Binary(raw stream) |
Subscribe |
| JSON |
Warning |
---|
Note |
About MQTT TopicWhen Publish,device token that is included in the sometimes topic invalid, ThingScale will refuse the receipt of data that has been publish. |
Info |
---|
...
About binary(packed)When dealing with binary data, please store the byte character as it is in the MQTT payload to specify the topic for the binary message. Binary message as the payload of value1, is converted to the format of the hex dump string can be referenced from the Stream API. Serialization of binary message is recommended that you store in MessagePack(http://msgpack.org) For more information about the MQTT device connector, please refer |
...
NOTE
There are some questions here on how to handle failure to send(device_token missmatch,etc),as there is no mechanisum to report failure back to the device.
For more additional MQTT-related information,refer MQTT V3.1 Protocol Specification from IBM
Tutorial
...
Publish
...
...
Publish data to ThingScale (API v2.x)
Code Block |
---|
mosquitto_pub -h m.thingscale.io -t '<DEVICE_TOKEN>/json/<DEVICE_ID>' -m '{"temp":20, "humidity":50}' -d -u <ThingScale_ID> -P <DEVICE_TOKEN> |
Code Block |
Publish data to ThingScale with MQTTS(API v2.x)
Code Block |
---|
mosquitto_pub -h m.thingscale.io -p 8883 -t '<DEVICE_TOKEN>/json/<DEVICE_ID>' -m "23.5" --cafile /etc/pki/tls/certs/ca-bundle.crt -d -u <ThingScale_ID> -P <DEVICE_TOKEN> |
In this case,root cafile=CentOS default root ca-bundle.
Subscribe
...
Retrieve the commands from the Publish Service
Code Block |
---|
mosquitto_sub -h m.thingscale.io -t '<DEVICE_TOKEN>/<DEVICE_ID>/subscribe' -u <ThingScale_ID> -P <DEVICE_TOKEN> |
...