Forward message after twice "false"


I have the "Adv Ping" node and then a function node with the following code:

msg.tripTime = msg.payload;
msg.payload = msg.payload! == false?
"VServer running":
"VServer cannot be reached";
return msg;

This works very well so far, but I would like that if a "false" comes from the ping node only once and if the second time "false" the message should be sent to others.

How do I have to change the Node function so that I am not notified immediately but only after the second time "false".

Greetings Volker

You could use a function node and keep track of fail count per IP. If fail count is 2, forward the message. You will need to store the"memory" object in context to remember the ping count

Assuming there is only 1 address being pinged, you could do this...

let failCount = context.get("failCount") || 0;//get remembered count
msg.tripTime = msg.payload;
if (msg.payload === false) {
    failCount++; //increment fail count
    node.status({ fill: "red", shape: "ring", text: "Fail count: " + failCount});
    if (failCount < 2)  {
        msg = null; //Setting msg null will prevent an output
    } else {
        msg.payload = "VServer cannot be reached";
} else {
    failCount = 0; //reset fail count as we got a good ping.
    node.status({ fill: "green", shape: "ring", text: "VServer OK. Triptime=" + msg.payload});
    msg.payload = "VServer running";

context.set("failCount", failCount); //remember count

return msg;//send msg to next node (or not!)


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