• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

MicroPython mqtt subscribe to more than one topic

Q&A Forum › Category: ESP8266 › MicroPython mqtt subscribe to more than one topic
0 Vote Up Vote Down
Peter Ashford asked 5 years ago

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()
Question Tags: MicroPython, MQTT, subscribe
3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi Peter.
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.
Regards,
Sara 

0 Vote Up Vote Down
Peter Ashford answered 5 years ago

Thank you for your very prompt answer.
Peter

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Great!
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.