Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mqtt

mosquitto

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.

like image 485
Khush Bhatia Avatar asked Feb 23 '17 21:02

Khush Bhatia


People also ask

How do I publish with Mosquitto?

Publishing Using The Mosquitto_pub Client In the first example the message is published and the client exits without displaying any messages. If you enable the debugging using the -d flag then you can see the connect,publish and disconnect messages. Notice the -h flag sets the host name or IP address.

What is Mosquitto_pub?

mosquitto_pub is a simple MQTT version 5/3.1. 1 client that will publish a single message on a topic and exit.

How do I cancel my Mosquitto broker?

Starting and Stopping The Broker This gives you access to the console which is invaluable for testing. On Windows you can stop the service if it is running by using the control panel>admin>services. By default the broker will start listening on port 1883.


1 Answers

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".
like image 126
hardillb Avatar answered Oct 10 '22 06:10

hardillb