Node red ping watchdog

We have a Cerbo GX. I would like for it to trigger a relay (normally closed) for 2 seconds if a ping has failed 4x times in a row.

Sort of like a watchdog function.

This will basically kill the 24 to 48V convertor powering a network switch which will in turn reboot the switch.

We want it to pin something like google 8.8.8.8 and if it fails ping 4x in a row it will trigger the relay for a moment.

The pings will be every 5 mins or something.

Is this possible with node Red? The cerbo has a function like this but it just reboots the cerbo itself..

Why not use the automatic reboot on communication lost feature?

On the cerbo gx?

It just reboots the cerbo itself.

Our network switch is not powered by the cerbo
It is powered by a 24 to 48v convertor, that has a relay port on it that usually has a jumper so its just always on.

We want the cerbo to stay on, but if it can’t get to the internet - trigger relay 2 (normally closed) or something.

This would reboot the network switch and fix everything.

The switches lock up sometimes which required a physical reboot which sucks.

YES:

[
  {
    "id": "simple-internet-check",
    "type": "tab",
    "label": "Simple Internet Check",
    "disabled": false,
    "info": "Every 5 min: HTTP to Google → boolean true/false"
  },
  {
    "id": "trigger",
    "type": "inject",
    "z": "simple-internet-check",
    "name": "every 5 min",
    "props": [{ "p": "payload" }],
    "repeat": "300",
    "crontab": "",
    "once": true,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "",
    "payloadType": "date",
    "x": 140,
    "y": 160,
    "wires": [ ["http-check"] ]
  },
  {
    "id": "http-check",
    "type": "http request",
    "z": "simple-internet-check",
    "name": "GET google 204",
    "method": "GET",
    "ret": "txt",
    "paytoqs": "ignore",
    "url": "https://www.google.com/generate_204",
    "tls": "",
    "persist": false,
    "authType": "",
    "senderr": false,
    "headers": [],
    "x": 340,
    "y": 160,
    "wires": [ ["check-status"] ]
  },
  {
    "id": "check-status",
    "type": "switch",
    "z": "simple-internet-check",
    "name": "204? up : down",
    "property": "statusCode",
    "propertyType": "msg",
    "rules": [
      { "t": "eq", "v": "204", "vt": "num" },
      { "t": "else" }
    ],
    "checkall": "true",
    "repair": false,
    "outputs": 2,
    "x": 540,
    "y": 160,
    "wires": [ ["set-true"], ["set-false"] ]
  },
  {
    "id": "set-true",
    "type": "change",
    "z": "simple-internet-check",
    "name": "up = true",
    "rules": [
      { "t": "set", "p": "payload", "pt": "msg", "to": "true", "tot": "bool" }
    ],
    "action": "",
    "property": "",
    "from": "",
    "to": "",
    "reg": false,
    "x": 740,
    "y": 140,
    "wires": [ ["debug"] ]
  },
  {
    "id": "set-false",
    "type": "change",
    "z": "simple-internet-check",
    "name": "down = false",
    "rules": [
      { "t": "set", "p": "payload", "pt": "msg", "to": "false", "tot": "bool" }
    ],
    "action": "",
    "property": "",
    "from": "",
    "to": "",
    "reg": false,
    "x": 740,
    "y": 180,
    "wires": [ ["debug"] ]
  },
  {
    "id": "debug",
    "type": "debug",
    "z": "simple-internet-check",
    "name": "internet: true/false",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 940,
    "y": 160,
    "wires": []
  }
]

We are wanting it to be like a “watchdog” function.

Basically ping google every 5 mins. → If it fails once then it starts a fail counter. → It needs to fail 5 times in a row. So after 25 mins pretty much 5x5.

After that it would trigger a momentary OPEN of the relay 2 on the cerbo which the wiring is connected to normally closed.

That would kill the ORION 24v to 48V DC to DC convertor which in turn would kill the switch power, and restart it.

Then the function would restart itself. (so if internet never came back on, it would essentially reboot the switch every 25 mins)

See image : Note: there is much more to this setup. But for this node red function what is in the pic is all that matters.

THANKS!

What is stopping you, honest question,..
Above flow provides your true/false signal every 5 minutes, feed it to the relay node, if needed with a fail counter in between.

And your requirement specification is pretty good, copy paste it into grok and it will probably one-shot the rest.

But you’ll have to get to your feed wet with Node-RED yourself unless you are looking to hire.

If you look below this thread, you will find several Node-RED relay topics as well. Your request is a perfect little starters project with good purpose to boot.

2 Likes

I’m using 2 Trigger nodes to provide the watchdog function, works great.
But yes, working with (the more advanced parts of) Victron will require some patience, study and wet feet.
If you’re looking for someone to hold your hand along the way: we are not your mama.
Pinging Google is a horrible way to make a watchdog by the way.

1 Like

Well, I did give 80% of the required flow already :wink: (without pinging google, just in case you missed that detail)

1 Like

Oh no. Not looking for anyone to create the whole thing for me.

I just had made that pic in Visio so wanted to post that to make my question a little more explained visually so posted it after your reply.

1 Like

Its not terrible as long as you make it fail 4-5 times in a row over like 30 mins.

I find its better to ping an IP also not DNS address.

We do this with 100s of devices in our org. but usually they allow us to ping two IPs.

Google and AWS or something.

2 Likes

Yea I get that side of it also. Its basically testing PING + DNS, http. To test the internet is “fully” working not just a network ping.

From my side in IT, We have had DNS servers go down, which doesn’t really mean the network is down and to restart everything which is why we usually only test IP pings. That being said i’m sure the CERBO uses a lot of DNS to work right, so probably need that working also.

Come to think about it, if that picture displays actual gear, that industrial switch could very well provide what you are looking for ‘out of the box’ already. Did you check?

It does not unfortunately.

It has watchdog stuff that will restart POE ports if pings fail. (like a camera port, or wifi)

It also has a reboot schedule. (this is a hardcode reboot at set time)

But not a “reboot switch” only if lost internet.

That being said, it MAY have something like that in the CLI just not in the GUI. I believe this is cisco backend. (Its an AXIS switch)

Also we think it’s the actual switches that lock sometimes, so any internal stuff on the switch wouldn’t work if thats the case.

Also in IT networking, sometimes we are just wanting to “watchdog” ping the next device, not necessarily the “internet”

For example: Ping the other (far side) radio of a wireless P2P link.

So I would say ping watchdog isn’t terrible. Its just a different option. Sometimes you want to watchdog simple, sometimes more complex.

You can use a 24Vdc Shelly Plus i4 DC https://www.shelly.com/products/shelly-plus-i4-dc
And this script: shelly-script-examples/router-watchdog.js at main · ALLTERCO/shelly-script-examples · GitHub

That way you can ‘relieve’ the Cerbo GX of this task.

That way you can ‘relieve’ the Cerbo GX of this task.

We are actually trying to make the Cerbo GX be responsible for this task.

We thought about something like what you mentioned (the shelly). We have used these before for access control stuff.
It would have to be ethernet, not wifi. The wifi for this setup is not near the cerbo or switch.

Just feel like having node red on cerbo do this would be the best.

I’’ll play around with it tonight and see if I can’t get it working.

Thanks for help!

1 Like

Just is case: there is the json download.

The relay nodes are included in the VenusOS large Node-RED implementation.
And get yourself the extremely versatile boolean-logic-ultimate nodes (via palette install) to build the timer/switch logic with.

This is what I came up with. After testing it works great. It’s probably embarrassing to look at but it works hah.
I couldn’t figure out how to momentary turn on/off relay for just 5 seconds without doing it the way I did.

I had to download the “ping” add on. Again - not trying to test the internet. We want to ping the next thing in line in the network. (P2P radio at a tower)

So a single ping watchdog type function is preferred. (If we can’t even ping the next P2P radio something is wrong and reset switch).
Yes I know there are better ways if you are trying to test internet (watchdog). Ping URLs and multiple of them etc. (google + aws)
But this is actually the better way for us. We don’t NEED to test the internet. Just the next hop.

For example: If the internet/firewall goes down, we don’t really want our deer stand setups restarting. They have cameras on them that record to internal servers.

[
    {
        "id": "457ecf75d4acfd9e",
        "type": "ping",
        "z": "simple-internet-check",
        "protocol": "IPv4",
        "mode": "timed",
        "name": "Ping IP 60 sec",
        "host": "192.168.7.66",
        "timer": "60",
        "inputs": 0,
        "x": 330,
        "y": 460,
        "wires": [
            [
                "c7c3c1e22e00b22e",
                "d43da5ecf0124c26"
            ]
        ]
    },
    {
        "id": "db59c6082ce7d809",
        "type": "debug",
        "z": "simple-internet-check",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 940,
        "y": 540,
        "wires": []
    },
    {
        "id": "c7c3c1e22e00b22e",
        "type": "switch",
        "z": "simple-internet-check",
        "name": "Up or Down",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "false"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 570,
        "y": 460,
        "wires": [
            [
                "f39076e76efb2643"
            ],
            [
                "ee64318d3b15c393"
            ]
        ]
    },
    {
        "id": "ee64318d3b15c393",
        "type": "change",
        "z": "simple-internet-check",
        "name": "Up - Reset Count Zero",
        "rules": [
            {
                "t": "set",
                "p": "counter",
                "pt": "flow",
                "to": "0",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 720,
        "y": 540,
        "wires": [
            [
                "db59c6082ce7d809",
                "e6cd85e20f46c931"
            ]
        ]
    },
    {
        "id": "d43da5ecf0124c26",
        "type": "debug",
        "z": "simple-internet-check",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 280,
        "wires": []
    },
    {
        "id": "f39076e76efb2643",
        "type": "function",
        "z": "simple-internet-check",
        "name": "DOWN - Counter + 1",
        "func": "var counter = flow.get(\"counter\") || 0\n\ncounter ++\n\nflow.set(\"counter\", counter)\n\nmsg.payload = counter\n\nreturn msg",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 760,
        "y": 380,
        "wires": [
            [
                "f935a396379d50ca",
                "2f7c496451f18f63"
            ]
        ]
    },
    {
        "id": "f935a396379d50ca",
        "type": "debug",
        "z": "simple-internet-check",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 960,
        "y": 280,
        "wires": []
    },
    {
        "id": "7cfc9aba330718aa",
        "type": "victron-output-relay",
        "z": "simple-internet-check",
        "service": "com.victronenergy.system/0",
        "path": "/Relay/0/State",
        "serviceObj": {
            "service": "com.victronenergy.system/0",
            "name": "Venus device"
        },
        "pathObj": {
            "path": "/Relay/0/State",
            "type": "enum",
            "name": "Venus relay 1 state",
            "enum": {
                "0": "Open",
                "1": "Closed"
            },
            "mode": "both",
            "disabled": false
        },
        "name": "",
        "onlyChanges": false,
        "x": 1440,
        "y": 320,
        "wires": []
    },
    {
        "id": "2cfeccc135823d11",
        "type": "delay",
        "z": "simple-internet-check",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 1180,
        "y": 480,
        "wires": [
            [
                "e0d6f3d50bc3443c"
            ]
        ]
    },
    {
        "id": "4b9137af51ac86a0",
        "type": "victron-output-relay",
        "z": "simple-internet-check",
        "service": "com.victronenergy.system/0",
        "path": "/Relay/0/State",
        "serviceObj": {
            "service": "com.victronenergy.system/0",
            "name": "Venus device"
        },
        "pathObj": {
            "path": "/Relay/0/State",
            "type": "enum",
            "name": "Venus relay 1 state",
            "enum": {
                "0": "Open",
                "1": "Closed"
            },
            "mode": "both",
            "disabled": false
        },
        "name": "",
        "onlyChanges": false,
        "x": 1460,
        "y": 540,
        "wires": []
    },
    {
        "id": "e0d6f3d50bc3443c",
        "type": "change",
        "z": "simple-internet-check",
        "name": "Reset Count Zero + Set Relay OPEN again",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "0",
                "tot": "num"
            },
            {
                "t": "set",
                "p": "counter",
                "pt": "flow",
                "to": "0",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1470,
        "y": 480,
        "wires": [
            [
                "4b9137af51ac86a0"
            ]
        ]
    },
    {
        "id": "2f7c496451f18f63",
        "type": "switch",
        "z": "simple-internet-check",
        "name": "Continue if count over 10 (60 mins)",
        "property": "counter",
        "propertyType": "flow",
        "rules": [
            {
                "t": "gte",
                "v": "10",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 1040,
        "y": 400,
        "wires": [
            [
                "383eb37bf73d126d"
            ]
        ]
    },
    {
        "id": "383eb37bf73d126d",
        "type": "change",
        "z": "simple-internet-check",
        "name": "Set relay CLOSED",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "1",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1290,
        "y": 400,
        "wires": [
            [
                "7cfc9aba330718aa",
                "2cfeccc135823d11"
            ]
        ]
    },
    {
        "id": "e6cd85e20f46c931",
        "type": "function",
        "z": "simple-internet-check",
        "name": "Get Count for Debug",
        "func": "var counter = flow.get(\"counter\") || 0\n\nmsg.payload = counter\n\nreturn msg",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 840,
        "y": 640,
        "wires": [
            [
                "024b33ded2043ac1"
            ]
        ]
    },
    {
        "id": "024b33ded2043ac1",
        "type": "debug",
        "z": "simple-internet-check",
        "name": "debug 4",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1040,
        "y": 640,
        "wires": []
    }
]