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.
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.
mosquitto_pub is a simple MQTT version 5/3.1. 1 client that will publish a single message on a topic and exit.
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.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With