How to make mosquitto_sub print topic and message when subscribed to #

Khush Bhatia picture Khush Bhatia · Feb 23, 2017 · Viewed 20.6k times · Source

The following command shows all the messages published to topics that match the regex but not the exact topic itself.

mosquitto_sub -h localhost -u user -P pass -t 'devices/#'
{"value":"50"}
{"value":"45"}

For example the above json messages were published to topic devices/1234/transducer/46364/ but I could not figure any way to print the topic as well using mosquitto_sub.

Answer

hardillb picture hardillb · Feb 23, 2017

Use the -v option

mosquitto_sub -h localhost -u user -P pass -v -t 'devices/#'

From the man page:

   -v, --verbose
       Print received messages verbosely. With this argument, messages
       will be printed as "topic payload". When this argument is not
       given, the messages are printed as "payload".