Skip to main content
Version: Next

MQTT Tools

thin-edge.io cli provides a convenient way to debug and aid development process.

Publish​

Command tedge mqtt pub can be used to publish MQTT messages on a topic to the local mosquitto server.

Example:

tedge mqtt pub 'te/device/main///m/env_sensor' '{
"temperature": 21.3
}'

Messages can also be published with a different Quality of Service (QoS).

tedge mqtt pub -q 2 'te/device/main///m/env_sensor' '{
"temperature": 21.3
}'

MQTT messages can also be published using the retained option which means that the message will be received by new MQTT clients connecting to the broker after the message was published.

Below shows an example of publishing a retained MQTT message:

tedge mqtt pub -r -q 1 'te/device/main///a/high_temperature' '{
"text": "Temperature is critical",
"severity": "critical"
}'
note

By default the mqtt message will be published with retain flag set to false.

Subscribe​

Command tedge mqtt sub can be used to ease debugging of of MQTT communication on local bridge. You can subscribe to topic of your choosing:

tedge mqtt sub 'te/errors'

Or you can subscribe to any topic on the server using wildcard (#) topic:

tedge mqtt sub '#'

Now using a different console/shell, publish the following measurement so that the previous subscription will receive it:

tedge mqtt pub -r -q 1 'te/device/main///m/env_sensor' '{
"temperature": 21.3
}'

All messages from sub command are printed to stdout and can be captured to a file if you need to:

tedge mqtt sub '#' > filename.mqtt

Wildcard (#) topic is used by MQTT protocol as a wildcard and will listen on all topics