Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. Watchdog to notify when sensor offline using Node Red

Watchdog to notify when sensor offline using Node Red

Scheduled Pinned Locked Moved General Discussion
3 Posts 3 Posters 3.6k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wassa350
    wrote on last edited by
    #1

    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.

    YveauxY 1 Reply Last reply
    0
    • W wassa350

      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.

      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #2

      @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:

      0_1518506178888_d0657211-4ae9-4446-b777-dfa5e2043901-image.png

      This 'Detect online' subflow can be used as follows:

      0_1518506570174_87c77b14-10cd-42f3-8d49-9a85f40d8743-image.png

      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:

      0_1518506652757_59793a79-6d04-4803-82ea-0162e67d2d65-image.png

      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"}]
      

      http://yveaux.blogspot.nl

      1 Reply Last reply
      2
      • D Offline
        D Offline
        dakipro
        wrote on last edited by
        #3

        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)

        C: OpenHAB2 with node-red on linux laptop
        GW: Arduino Nano - W5100 Ethernet, Nrf24l01+ 2,4Ghz mqtt
        GW: Arduino Mega, RFLink 433Mhz

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        24

        Online

        11.7k

        Users

        11.2k

        Topics

        113.1k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular