Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I subscribe to all topics of a MQTT broker

Tags:

mqtt

mosquitto

I want to connect a client which will monitor all the topics of the broker to respond to the events when I don't know what are names of topic.

like image 500
Yugandhar Chaudhari Avatar asked Oct 02 '15 09:10

Yugandhar Chaudhari


People also ask

Can a client subscribe to all the topics available with broker?

Q- Can I get list of all topics on a broker? A- Not unless you subscribe to all topics and scan them.

Can MQTT subscribe to multiple topics?

When a client subscribes to a topic, it can subscribe to the exact topic of a published message or it can use wildcards to subscribe to multiple topics simultaneously. A wildcard can only be used to subscribe to topics, not to publish a message.

How do I subscribe to MQTT broker?

To receive messages on topics of interest, the client sends a SUBSCRIBE message to the MQTT broker. This subscribe message is very simple, it contains a unique packet identifier and a list of subscriptions. Packet Identifier The packet identifier uniquely identifies a message as it flows between the client and broker.

How do I subscribe to a topic in Mosquitto?

Click OK and then click on the Connect button. MQTT. fx will establish a connection with the local Mosquitto server. Notice that the Connect button is disabled and the Disconnect button is enabled because the client is connected to the MQTT server.


2 Answers

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.

like image 86
ralight Avatar answered Oct 11 '22 18:10

ralight


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 '#' 
like image 41
rem Avatar answered Oct 11 '22 16:10

rem