Hi, I have adapted the def sub(topic,msg) routine in you example code to detect a topic which I have defined as
topic_sub = b’cmnd/garage/door and it works fine reporting if my garage door is open or closed.
I would like to add a second topic (e.g. topic_sub = b’cmnd/garage/light) to receive messages about my garage light is but I am not sure how to do this?
Is it possible to be subscribed to more than one topic ? and how to I check this second topic?
def sub_cb(topic, msg): print((topic, msg)) oled.fill(0) if msg == b'on': oled.text(topic,0,20) oled.text('on:door open',0,40) ledr.value(0) ledg.value(1) if msg == b'off': oled.text(topic,0,20) oled.text('off:door closed',0,40) ledr.value(1) ledg.value(0) oled.text(msg, 0, 0) oled.show()
Yes, it is possible to subscribe to multiple topics.
Everything is explained here: https://rntlab.com/question/esp32-mqtt-subscribe-to-multiple-topics/
Scroll down until you find Rui talking about MicroPython.
If need further help, feel free to ask.