MQTT callback for multiple feeds using just one call
-
Hello all,
Im new to micropython and IOT, but enjoying the learning so far.
With my project/ use case I have 8 feeds, using Adafruit IO. I have successfully managed to send and retrieve data for just one feed. But I want to be able to work with all 8.
I call the check_msg function every 30 secs, which I believe then runs the callback function (in my case assigned to 'response_function') with feed data. All feeds report to the same callback function.
I am keeping all my feed data in one dictionary to match the key with the values.
Current I am just gathering one topic and value for each call (the topic seems to change each time), and updating just one object in the dictionary every 30 secs. I would like to do this for all feeds every 30 secs.
My question is - is there a way of gathering the feed data in some sort of list which I can then assign to the respective dictionary key?
My current callback function is:
def response_function(topic,msg):
global my_feed_dictionary
my_feed_dictionary[topic]=msg # update value of respective dictionary keyI was hoping I would be able to use something like *args and then iterate through all the data in my callback sub. Maybe calling check_msg() 8 times at each cycle would also work - but this seems like it would be a bodge.
Any help would be appreciated.
Kind regards
Jake