• 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

MQTT – Connect ESP32/ESP8266 to Node-RED with MicroPython

Q&A Forum › Category: ESP8266 › MQTT – Connect ESP32/ESP8266 to Node-RED with MicroPython
0 Vote Up Vote Down
Jacques Vermaak asked 5 years ago

Hi guys.

I am going through the MicroPython ESP32 ESP8266 ebook I bought. 

I have a question on the section under Module 5, MQTT – Connect ESP32/ESP8266 to Node-RED.

I have your example fully functional and running. I do however notice that the temperature update to the dashboard (ui) interface only updates when I toggle the LED switch.

Is there some way that the temperature signal (or any analogue signal for that matter) can dynamically be updated when I have my Node red/ui webpage open? I am controlling a cooling fan that cools down my solar inverters. But for me to see the latest temperatures I have to toggle the Fan off and on again. I would like it if I could immediately see the real time temperature every time I open the Node red/ui flow on the web browser.

Thank you 

6 Answers
0 Vote Up Vote Down
Jacques Vermaak answered 5 years ago

It would seem that the problem lies withing the umqttsimple.py file.

In there a section has the following comments…
# Wait for a single incoming MQTT message and process it.
# Subscribed messages are delivered to a callback previously
# set by .set_callback() method. Other (internal) MQTT
# messages processed internally.
That seems to be exactly what happens in my case. The temperature reading is only updated once I toggle the LED output.
Can this file be modified as NOT to wait for an incoming message?
I.e. send the temperature value regardless of what is coming in or not?
 

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

Hi Jacques.
Your problem is not related with that function. Although you have that function in the library file, we don’t use it in our example.
Additionally, that function only receives incoming MQTT messages and delivers them to the .set_callback method so that we’re able to use the incoming message later. It is not related with publishing messages – although the comment can be misleading.
If you refresh your node-red page, does it update with the latest readings?
Regards,
Sara

0 Vote Up Vote Down
Jacques Vermaak answered 5 years ago

Hi Sara.

No. Refreshing Node Red does not do anything. No new data comes in. Only if I do a new Deploy, but once it ran, that’s it. The analogue value does not change unless I issue a new command to the ESP

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

Hi again.
But do you get new temperature readings on the shell every 5 seconds?
Or you just get them on the shell and in Node-RED after pressing the fan button?

0 Vote Up Vote Down
Jacques Vermaak answered 5 years ago

Hi Sara,

I managed to get a working solution to my problem.
I had to add the following to the line …
Original…

client.publish(topic_pub, msg)

Modified…

client.publish(topic_pub, msg, qos=1, retain=False)

The updates are now sent to the Node red dashboard every 5 seconds.
Thank you

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

Hi.
Thanks for sharing that.
We’ll test it and update the eBook with your suggestion.
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

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition 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.