1

If a message is sent to the topic in an mqtt broker, I want to know the topic by Python. In order to use client.subscribe (), I have to manually enter a topic, so I need to know the topic before client.subscribe() dynamically. Is there a way to know what broker topics are?

KiHyun Nam
  • 77
  • 6
  • Possible duplicate of [Request all published topics](http://stackoverflow.com/questions/42559890/request-all-published-topics) – hardillb Mar 08 '17 at 11:01
  • Also just knowing the topics doesn't help if you don't also know the format of the data being published. What is the actual problem you are trying to solve? – hardillb Mar 08 '17 at 11:04

1 Answers1

1

If you send "EVERY" message to broker with retain message = True, then you can:

  1. Connects to server with subscribe '#'
  2. Check all the retain message and their topic (then you can got all topics)
  3. Unsubscribe '#'
  4. Subscribe the topic you want

This solution subscribe twice, may not fit your original requirement (only subscribe once), but can do what you want

Asoul
  • 996
  • 1
  • 10
  • 22
  • You're welcome. If you like my answer, you can accept my answer by clicking the checkmark on the left side. Thanks! :) – Asoul Mar 09 '17 at 09:06