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.
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?
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?
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
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?
I managed to get a working solution to my problem.
I had to add the following to the line …
client.publish(topic_pub, msg, qos=1, retain=False)
The updates are now sent to the Node red dashboard every 5 seconds.