Threshold node will not output

Greetings all.

Still new to NR and having some trouble with something which is probably very basic. I have done the requisite search and study (hours not minutes) but to my shame, I can't seem to find the key.

The code below is intended to periodically ping an ip address and if the number of failed attempts rises above some number in some minutes time, trigger an output (power cycle router). The trouble is that the threshold node never produces an output. Debug node 1 gives me:

Blockquote
{"payload":false,"topic":"192.168.2.3","_msgid":"326f9f28.7032","checkValue":11}

Values configured in threshold less than checkValue (even 0) do not result in any output from threshold node appearing in debug node 2. Info for threshold node says:

Blockquote
...The node takes a single input. If that input value is higher than the threshold then the payload is delivered but only when the threshold is exceeded...
...add an attribute to that payload: payload.checkValue. The checkValue will be compared to the Threshold defined in the node editor each time a new payload arrives....

What am I not understanding?

Flow is below.

Hope you can help.

Q

[
    {
        "id": "dceb6fb1.f4efc",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "606bf72e.c70588",
        "type": "switch",
        "z": "dceb6fb1.f4efc",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "else"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 310,
        "y": 100,
        "wires": [
            [],
            [
                "88aed5ce.230858"
            ]
        ]
    },
    {
        "id": "d060335f.b011a",
        "type": "ping",
        "z": "dceb6fb1.f4efc",
        "name": "",
        "host": "192.168.2.3",
        "timer": "1",
        "x": 130,
        "y": 100,
        "wires": [
            [
                "606bf72e.c70588"
            ]
        ]
    },
    {
        "id": "be1b0a1c.6311a8",
        "type": "debug",
        "z": "dceb6fb1.f4efc",
        "name": "1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 490,
        "y": 220,
        "wires": []
    },
    {
        "id": "88aed5ce.230858",
        "type": "timed-counter",
        "z": "dceb6fb1.f4efc",
        "name": "",
        "timelimit": "10",
        "timeunit": "1000",
        "withhold": true,
        "fixedtimeout": true,
        "pertopic": false,
        "x": 500,
        "y": 100,
        "wires": [
            [
                "f25dc855.8b1048"
            ]
        ]
    },
    {
        "id": "f68c3980.7d6e18",
        "type": "debug",
        "z": "dceb6fb1.f4efc",
        "name": "2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 490,
        "y": 340,
        "wires": []
    },
    {
        "id": "2e6f2aa1.6d8456",
        "type": "threshold",
        "z": "dceb6fb1.f4efc",
        "name": "checkValue",
        "thresholdValue": "2",
        "x": 170,
        "y": 340,
        "wires": [
            [
                "f68c3980.7d6e18"
            ]
        ]
    },
    {
        "id": "f25dc855.8b1048",
        "type": "change",
        "z": "dceb6fb1.f4efc",
        "name": "",
        "rules": [
            {
                "t": "move",
                "p": "count",
                "pt": "msg",
                "to": "checkValue",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 180,
        "y": 220,
        "wires": [
            [
                "2e6f2aa1.6d8456",
                "be1b0a1c.6311a8"
            ]
        ]
    }
]

Hi.

One thing which is a problem:

  • You are using non standard nodes. I thought I had some, but didn't.

When I went to install the ping node..... There are just a few from which to choose.
Typically I chose the wrong one.

It would help if you wrote down the complete name of the node.

Say:
node-red-configurable-ping

It would be appreciated.

what does the debug message say the value of msg.payload.checkValue

To address your comment - node-red-node-ping. Please specify the appropriate standard nodes you think I should be using and why.

I don't believe it is pertinent actually because my trouble is with the change / threshold node interaction. The debug output of the ping has "count" which I re-labled checkValue in change node as shown. Some other ping might work better but for some 'reason' I picked this one.

Q

Perhaps this goes to the thing I am missing/don't get-

Didn't I already provide this information in my OP?

Thanks for the attention.

Q

i don't think youe checkValue is in the payload ie. msg.payload.checkValue
its in msg.checkValue

I am new to node-red myself and do not have that node installed. but from reading your question it said "add an attribute to that payload: payload.checkValue. "

Thanks for the reply.

Isn't that what this

is?

Q

As i am new i am not 100%

But i think, hopefully someone will jump in if im wrong.
This is "payload":false," payload and it has a value as boolean :False

the whole thing between {} is msg.
Topic,_msgid and ChecValue are seperate properties of msg

How did you atempt add checkValue to Payload?

{"payload":{"checkValue":11},"topic":"192.168.2.3","_msgid":"326f9f28.7032"}
{"payload":false,"topic":"192.168.2.3","_msgid":"326f9f28.7032","checkValue":11}

You need to check for msg.checkValue, not msg.payload.checkValue

I think the checkVakue has to be added to the payload as the documentation instructs.

documentation for ?

written in the quote from the first post, and in install pallete when you read the limited text information.

Sorry, totally missed that info, but the snarky comment is noted.

You can use this flow (no need for external nodes).

Replace the IP in the inject node, set the inject node to the interval you want to use and it will ping and keep track of the number of times it failed (it will be indicated underneath the function node), after 4 times failed it will generate a message.

Change the number in the function node to the number of times you want it to fail before sending the message.

[{"id":"1eb3f7f7.842728","type":"inject","z":"aa6ee791.99e188","name":"","topic":"","payload":" 10.0.0.1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":228,"y":192,"wires":[["a25119f7.a58648"]]},{"id":"a25119f7.a58648","type":"exec","z":"aa6ee791.99e188","command":"ping -c1","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":394,"y":192,"wires":[[],[],["1acb109e.6e93d7"]]},{"id":"3b30f993.426e9e","type":"debug","z":"aa6ee791.99e188","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":698,"y":192,"wires":[]},{"id":"1acb109e.6e93d7","type":"function","z":"aa6ee791.99e188","name":"","func":"m = msg.payload.code\nc = context.get(\"pingcount\") || 0\n\nif(m===0){\n    node.status({fill:\"green\",shape:\"dot\",text:\"Connected\"});\n    context.set(\"pingcount\",1)\n}\nif(m===1){\n    context.set(\"pingcount\",c+1)\n    node.status({fill:\"red\",shape:\"dot\",text:\"Failed:\"+(c+1)});\n    if(c>3){\n        node.status({fill:\"red\",shape:\"dot\",text:\"Unreachable\"});\n        context.set(\"pingcount\",0)\n        return {payload:\"ping failed, rebooting\"}\n        \n    }\n    \n}","outputs":1,"noerr":0,"x":554,"y":192,"wires":[["3b30f993.426e9e"]]}]

Frustrating! Tried to provide necessary info. from start. My 'point' was "I thought that was what I did (( see original post)). If that isn't what I did then what do I need to do (Implied)?"

Wasn't intending to be offensive or inconsiderate. Apologies!

Q

Thanks for other input. Have some mundane tasks to do now. Comments raise a aquestion or two that I might need clarification on later...

I really appreciate the quick responses!

Q

Thanks bakman2.

Because of my newness, I was trying to avoid 'unnecessary' use of function nodes. I didn't want to get bogged down in 'the code' if it was possible to stay in 'the flow'. I imagine you can do just about anything with an inject, function and (probably optional) an output node but that isn't what NR is all about - though the function node is indeed a useful and important capability to have.

At any rate, I understand your function and right away I see how it could be expanded to watch over multiple IPs such as point to point links ( I could use this), APs and for failure of my dns, etc. I expect I will use this method. It is simple enough and gets the job done. That is the important part isn't it?

Also, I hadn't got as far as thinking about the ability to execute an external program (ping) which is hidden from view but undoubtedly how the ping node I was using works. Your example is helpful here as well. So more progress!

Regards and thanks again.

Q

I am not interested in arguing semantics of what nodes should be used.

You posted a flow with non-standard nodes. If you want people to be able to load the flow you need to specify - exactly - the nodes needed.
Otherwise help won't be as quick in coming.

Ok apologie accepted.

You provided all info i needed to see your issue, but i missed the debug message info

Anyway akman2 flow is the best option and really neat. We have both learn somthing.

@trying_to_learn, The node-red-node-ping node is one of the default nodes on a raspberry Pi. So If you use our install script it is a standard node. If you don't use our script it isn't installed by default so would need to be added.