Search code examples
pythonmqttfeedadafruit

Is there a way to use multiple feeds with Adafruit MQTT python client subscriptions?


I'm using Adafruit IO MQTT python client to execute code based upon feeds. I want one feed to execute one function and a different to execute another. I've looked at this and searched around but nothing I have found shows how to subscribe to multiple feeds.


Solution

  • You can simply call subscribe multiple times, as in:

    for feed_id in ['feed1', 'feed2']:
      client.subscribe(feed_id)
    

    This is a basic feature of the MQTT protocol. Your on_message_ handler will receive the feed id as a parameter.