# Help with code (Basic)(Solved)

**URL:** <https://discourse.nodered.org/t/help-with-code-basic-solved/21548>\
**Category:** General\
**Created:** [11 February 2020 16:32 UTC](https://discourse.nodered.org/t/help-with-code-basic-solved/21548 "2020-02-11T16:32:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [11 February 2020 16:32 UTC](https://discourse.nodered.org/t/help-with-code-basic-solved/21548/1 "2020-02-11T16:32:36Z")

</div>

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.

 ![Anotação 2020-02-11 132932](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a3b0f2190934a8efd39a2677500f023d50b6905f.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [11 February 2020 16:38 UTC](https://discourse.nodered.org/t/help-with-code-basic-solved/21548/2 "2020-02-11T16:38:12Z")

</div>

Hi @Shark_Polo

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

---

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [11 February 2020 16:39 UTC](https://discourse.nodered.org/t/help-with-code-basic-solved/21548/3 "2020-02-11T16:39:09Z")

</div>

Thank you so much!

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [11 February 2020 20:13 UTC](https://discourse.nodered.org/t/help-with-code-basic-solved/21548/4 "2020-02-11T20:13:09Z")

</div>

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/](https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament/)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 February 2020 20:13 UTC](https://discourse.nodered.org/t/help-with-code-basic-solved/21548/5 "2020-02-25T20:13:18Z")

</div>

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