mqttmosquitto

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


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.


Solution

  • 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".