How to use tedge mqtt pub and sub? cli provides a convenient way to debug and aid development process.


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


tedge mqtt pub 'tedge/measurements' '{ "temperature": 21.3 }'

tedge mqtt pub supports setting of QoS for MQTT messages:

tedge mqtt pub 'tedge/measurements' '{ "temperature": 21.3 }' --qos 2

tedge mqtt pub supports publishing a MQTT message with retain flag:

tedge mqtt pub --retain --qos 1 tedge/alarms/critical/high_temperature '{"message": "Temperature is critical"}'

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


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 tedge/errors

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

tedge mqtt sub '#'

Now use tedge mqtt pub 'tedge/measurements' '{ "temperature": 21.3 }' to publish message on tedge/measurements topic with payload { "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