How do I subscribe to all topics of a MQTT broker
Subscribing to #
gives you a subscription to everything except for topics that start with a $
(these are normally control topics anyway).
It is better to know what you are subscribing to first though, of course, and note that some broker configurations may disallow subscribing to #
explicitly.
You can use mosquitto_sub
(which is part of the mosquitto-clients
package) and subscribe to the wildcard topic #
:
mosquitto_sub -v -h broker_ip -p 1883 -t '#'
Concrete example
mosquitto.org is very active (at the time of this posting). This is a nice smoke test for a MQTT subscriber linux device:
mosquitto_sub -h test.mosquitto.org -t "#" -v
The "#" is a wildcard for topics and returns all messages (topics): the server had a lot of traffic, so it returned a 'firehose' of messages.
If your MQTT device publishes a topic of irisys/V4D-19230005/
to the test MQTT broker , then you could filter the messages:
mosquitto_sub -h test.mosquitto.org -t "irisys/V4D-19230005/#" -v
Options:
- -h the hostname (default MQTT port = 1883)
- -t precedes the topic
Use the wildcard "#" but beware that at some point you will have to somehow understand the data passing through the bus!