Watchdog to notify when sensor offline using Node Red
-
I am using ESP8266 with sensors like BME280, GPS module etc, and sending data via MQTT to Raspberry Pi/Mosquito and the displaying the data on a Node Red dashboard. This part is all working OK, BUT if my ESP which is sending data goes offline for some reason, my Dashboard doesn't change as it continues to display the last published value. Any ideas how a "watchdog" could be incorporated to advise of this condition.
-
@wassa350 Hi there and welcome to the forum!
I made a subflow in Node Red that detects when a sensor goes offline by monitoring the messages it sends in a configurable timeout interval:This 'Detect online' subflow can be used as follows:
Subscribe to some MQTT topic (notice the wildcard #) to receive all incoming messages from a node. Define a timeout, depending on the message frequency of the node, and send it to the 'Detect online' subflow. The returned topic will be set true when the node is online. The timestamp injected on startup is to get a defined startup state.
The online status is displayed using a UI Switch:Not perfect, but it does the job
[{"id":"6dd596c0.510558","type":"subflow","name":"Detect online","info":"","in":[{"x":260,"y":100,"wires":[{"id":"b819ab3d.82ac48"},{"id":"9e8a5611.149218"},{"id":"5e081291.070f0c"}]}],"out":[{"x":1440,"y":140,"wires":[{"id":"a58a8850.3d5e58","port":0},{"id":"9cf35d5a.5c0fb","port":0}]}]},{"id":"b85986e7.098e48","type":"delay","z":"6dd596c0.510558","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":870,"y":160,"wires":[["57e39bb6.e63fd4"]]},{"id":"9cf35d5a.5c0fb","type":"inject","z":"6dd596c0.510558","name":"Startup","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":true,"x":930,"y":260,"wires":[["57e39bb6.e63fd4"]]},{"id":"9e8a5611.149218","type":"change","z":"6dd596c0.510558","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":160,"wires":[["b85986e7.098e48"]]},{"id":"f6d33549.af3f78","type":"delay","z":"6dd596c0.510558","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":660,"y":200,"wires":[["b85986e7.098e48"]]},{"id":"b819ab3d.82ac48","type":"change","z":"6dd596c0.510558","name":"Online","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1030,"y":110,"wires":[["b73f93e2.91396"]]},{"id":"57e39bb6.e63fd4","type":"change","z":"6dd596c0.510558","name":"Offline","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1030,"y":160,"wires":[["b73f93e2.91396"]]},{"id":"a58a8850.3d5e58","type":"rbe","z":"6dd596c0.510558","name":"","func":"rbe","gap":"","start":"","inout":"out","x":1300,"y":140,"wires":[[]]},{"id":"5e081291.070f0c","type":"change","z":"6dd596c0.510558","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"timeout","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":200,"wires":[["f6d33549.af3f78"]]},{"id":"96afa4d.9bf6758","type":"comment","z":"6dd596c0.510558","name":"Each incoming message will retrigger a new timeout (msg.timeout [ms]) before being reported offline","info":"","x":590,"y":40,"wires":[]},{"id":"b73f93e2.91396","type":"change","z":"6dd596c0.510558","name":"Offline","rules":[{"t":"set","p":"topic","pt":"msg","to":"isonline","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":140,"wires":[["a58a8850.3d5e58"]]},{"id":"b5f7c03d.0efae","type":"mqtt in","z":"3ce68302.c3197c","name":"","topic":"some/mqtt/topic/#","qos":"1","broker":"fb1ad45d.04e528","x":280,"y":210,"wires":[["c8e0170c.a6b998"]]},{"id":"5a123330.a13ecc","type":"subflow:6dd596c0.510558","z":"3ce68302.c3197c","name":"","x":640,"y":210,"wires":[["e516913f.33cdd"]]},{"id":"c8e0170c.a6b998","type":"change","z":"3ce68302.c3197c","name":"Timeout 5 min","rules":[{"t":"set","p":"timeout","pt":"msg","to":"300000","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":210,"wires":[["5a123330.a13ecc"]]},{"id":"e516913f.33cdd","type":"ui_switch","z":"3ce68302.c3197c","name":"","label":"{{msg.topic}}","group":"1d40c94d.8f9407","order":1,"width":"0","height":"0","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"check_circle","oncolor":"green","offvalue":"false","offvalueType":"bool","officon":"error_outline","offcolor":"red","x":800,"y":210,"wires":[[]]},{"id":"33e1fc26.4ebb64","type":"change","z":"3ce68302.c3197c","name":"","rules":[{"t":"set","p":"enabled","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":260,"wires":[["88d7d373.d432e"]]},{"id":"88d7d373.d432e","type":"change","z":"3ce68302.c3197c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":260,"wires":[["e516913f.33cdd"]]},{"id":"8b06406d.9f938","type":"inject","z":"3ce68302.c3197c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":260,"y":260,"wires":[["33e1fc26.4ebb64"]]},{"id":"fb1ad45d.04e528","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"1d40c94d.8f9407","type":"ui_group","z":"","name":"Status","tab":"35337bfc.b7ac04","disp":true,"width":"6"},{"id":"35337bfc.b7ac04","type":"ui_tab","z":"","name":"Status","icon":"dashboard"}]
-
Very simple solution, but I just put up a single flow (called watchdog of course) that subscribes to "hart beat" and value topics of items I am watching (in my case via openhab, but principle is the same for vanilla mqtt) and then have a "timeout node" for each item. Timeout node triggers if no message comes in in a predefined period (per item, some send data every few minutes, some every few hours) But each arduino node has defined hart-beat interval
In my case all timeouts go to a function that formats a message in format "<itemname> not seen in <timeframe>" and that is logged and sent to an email once a day. But you can as well put it into a dashboard as Yveaux showed.
I also like use of subflows whenever possible, but in my case all is happening on one flow and in two nodes, one that connects to mqtt hearbeat and one node that triggers if no data comes in (sorry I forgot the name, but it is a default node-red node)
Suggested Topics
-
Update RF24 library to latest version
Bug Reports • 23 Mar 2014, 23:37 • andriej 24 Mar 2014, 22:52 -
Combination of networks
General Discussion • 1 Feb 2025, 17:30 • Sniker 4 Feb 2025, 01:02 -
Meet in Malmö, Summer 2016?
General Discussion • 1 Feb 2016, 15:34 • bjacobse 27 days ago -
Why is the output of ACS712 current measurement module unchanged?
General Discussion • 19 Jul 2021, 09:09 • Tessie T a day ago -
No merge into master in the last 5 years, should we use development?
General Discussion • 23 Sept 2024, 17:48 • kiesel 5 days ago -
ESP-NOW
General Discussion • 22 Apr 2018, 05:58 • NeverDie 17 Feb 2025, 22:24