Help with code (Basic)(Solved)

Hi.
My project consist of ESP32s sending sensor data to Node-Red though MQTT and Node-Red send it to Influx.
Everything is working fine except when the ESP is off and stop sending data.
I would like that the Node-Red start sending sensor off to Influx every 20s after not receiving data from the ESP for 10s.
Currently I find a way to send only one off signal using trigger but I would like like it keep sending every 20s.
I would appreciate any help even optimizations suggestions.
Thanks!
PS: Desligado means off
Each ESP send their name for taging the data and I use the switch to create a trigger for each ESP.

Hi @Shark_Polo

there's an example of that in the cookbook - https://cookbook.nodered.org/basic/trigger-placeholder

1 Like

Thank you so much!

Another solution is to use the LWT (last will topic) functionality build into mqtt itself.
Basically the broker will issue a message to a topic the client announce on connection is lost.
If you subscribe to this topic you will be informed.
The timer has the limitation if you use deep sleep. You will get false alarms if your device is sleeping unless you set the timer longer than the sleep period. With a LWT you get instant notification when your ESP is disconnected ungraceful but not if disconnect normally before going into deep sleep.
You can still use the timer method set longer than the wake up time to detect if the esp does not awake as expected.

A good resource to learn more about mqtt:

https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament/

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.