I have been in this scenario before many times and it keeps biting me.
This is a cut down of the code:
[{"id":"49a576ab.8b2ca","type":"function","z":"28c631fa.7e866e","name":"","func":"msg1 = {};\n\nvar state = context.get(\"state\") || 0;\nvar ST = global.get(\"SCAN_TIME\") || 20000;\nST = ST * 3;\n\nnode.status({text:state});\n\nif (msg.payload == true)\n{\n // All good\n msg.reset = true;\n if (state == 0)\n {\n msg.delay = ST;\n msg1.payload = \"UP\";\n context.set(\"state\",1);\n return [msg,msg1];\n } else\n {\n //\n return;\n }\n} else\n{\n // Not good.\n context.set(\"state\",0);\n return [msg,null];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":2880,"y":3540,"wires":[["4a303edf.9aa9c","37dc2ac4.5548ee"],["4599ebcb.53e71c"]],"outputLabels":["down","up"]},{"id":"4a303edf.9aa9c","type":"trigger","z":"28c631fa.7e866e","name":"","op1":"","op2":"DOWN","op1type":"nul","op2type":"str","duration":"6","extend":false,"overrideDelay":true,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":3050,"y":3540,"wires":[["3158e797.e96b58","4599ebcb.53e71c"]]},{"id":"37dc2ac4.5548ee","type":"debug","z":"28c631fa.7e866e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3040,"y":3490,"wires":[]},{"id":"857736ed.1d2248","type":"inject","z":"28c631fa.7e866e","name":"Set","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"false","payloadType":"bool","x":2780,"y":3610,"wires":[["49a576ab.8b2ca"]]},{"id":"4599ebcb.53e71c","type":"rbe","z":"28c631fa.7e866e","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":3175,"y":3600,"wires":[["650497f.77a79e8"]],"l":false},{"id":"4e386a22.f3a044","type":"inject","z":"28c631fa.7e866e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":2590,"y":3500,"wires":[["eac9160a.7ca4e8","49a576ab.8b2ca"]]},{"id":"a6a8a370.b5112","type":"inject","z":"28c631fa.7e866e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":2590,"y":3460,"wires":[["49a576ab.8b2ca","eac9160a.7ca4e8"]]},{"id":"3158e797.e96b58","type":"debug","z":"28c631fa.7e866e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":3250,"y":3520,"wires":[]},{"id":"650497f.77a79e8","type":"debug","z":"28c631fa.7e866e","name":"STATUS","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":3220,"y":3640,"wires":[]},{"id":"40cda74e.116b2","type":"inject","z":"28c631fa.7e866e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"UP","payloadType":"str","x":2740,"y":3660,"wires":[["4599ebcb.53e71c"]]},{"id":"12f72dc3.7f50b2","type":"inject","z":"28c631fa.7e866e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"DOWN","payloadType":"str","x":2740,"y":3700,"wires":[["4599ebcb.53e71c"]]},{"id":"faafb247.909de","type":"inject","z":"28c631fa.7e866e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"FOO","payloadType":"str","x":2740,"y":3740,"wires":[["4599ebcb.53e71c"]]},{"id":"eac9160a.7ca4e8","type":"debug","z":"28c631fa.7e866e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2890,"y":3490,"wires":[]}]
Picture:
Basics:
A true
or false
signal is received denoting the condition. true
is good. false
is bad.
All things being good I get true
signals every ..... (what ever).
the function
node sees what is received and if true
sends a msg.reset
out to stop the trigger
node if it was active. I'll explain that now.
So, if a false
signal is received, the trigger
node is activated and waits for a while before sending the message.
IF in the mean time, a true
comes in, the trigger
node is reset.
Great.
I am testing new stuff and so I am looking at this part of the code.
Or more so:
This part isn't working as expected.
Well, it is here, but not in the REAL part of the flow, and there is SFA difference. Just a rearrangement of the nodes and a couple of extra ones deleted. (FAN) Ok, one, not a couple.
Now, weirdly if I export the whole block and put it on another machine - more powerful - it works. As is.
If I duplicate it and put it else where on the same machine: It works.
I cut it down to basic nodes only to allow more people to be able to import it and (maybe) help me.
But that's just it! If I duplicate the code and put it else where on the machine - and simulate the input signals: It works.
As is it doesn't.
The RBE
isn't letting the DOWN
signal get through.
Here is a set of screen shots showing you what I see with the real code:
This has the IP set to fail and we are watching the code of interest on the screen.
Here you can see the trigger
node has been started and waiting 60
seconds.
And the next message comes through.....
And now you can see the trigger
node has timed out.
(No more blue dot under it.)
But the STATUS
node still says UP
.
It should say DOWN
as that is the message send.
What is going on?
Here is a better picture showing better messages:
And for the sake of "all cards on the table", here is that part of the code:
[{"id":"d0d076af.aade6","type":"link in","z":"28c631fa.7e866e","name":"Uplink status 1","links":["99fec739.577a4","ca7b2a2f.da6688"],"x":1415,"y":860,"wires":[["d2c6f62.6b59b88","b98ad199.c3b2e"]]},{"id":"d2c6f62.6b59b88","type":"debug","z":"28c631fa.7e866e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1570,"y":830,"wires":[]},{"id":"b98ad199.c3b2e","type":"function","z":"28c631fa.7e866e","name":"","func":"msg1 = {};\n\nvar state = context.get(\"state\") || 0;\nvar ST = global.get(\"SCAN_TIME\") || 20000;\nST = ST * 3;\n\nnode.status({text:state});\n\nif (msg.payload == true)\n{\n // All good\n msg.reset = true;\n if (state == 0)\n {\n msg.delay = ST;\n msg1.payload = \"UP\";\n context.set(\"state\",1);\n return [msg,msg1];\n } else\n {\n //\n return;\n }\n} else\n{\n // Not good.\n context.set(\"state\",0);\n return [msg,null];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":1560,"y":880,"wires":[["c641c733.ddcf08","41bda798.8375c"],["975da5db.6f47f","7acbe605.7ed528"]],"outputLabels":["down","up"]},{"id":"c641c733.ddcf08","type":"trigger","z":"28c631fa.7e866e","name":"","op1":"","op2":"DOWN","op1type":"nul","op2type":"str","duration":"60","extend":false,"overrideDelay":true,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1740,"y":880,"wires":[["975da5db.6f47f","402174e8.1add24"]]},{"id":"41bda798.8375c","type":"debug","z":"28c631fa.7e866e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1720,"y":830,"wires":[]},{"id":"975da5db.6f47f","type":"fan","z":"28c631fa.7e866e","name":"","x":1615,"y":930,"wires":[["c7efedf1.7e7a8"]],"l":false},{"id":"f6d46866.3ebf28","type":"inject","z":"28c631fa.7e866e","name":"Set","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"false","payloadType":"bool","x":1460,"y":950,"wires":[["b98ad199.c3b2e"]]},{"id":"7acbe605.7ed528","type":"debug","z":"28c631fa.7e866e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1650,"y":1060,"wires":[]},{"id":"402174e8.1add24","type":"debug","z":"28c631fa.7e866e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1930,"y":860,"wires":[]},{"id":"c7efedf1.7e7a8","type":"rbe","z":"28c631fa.7e866e","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":1685,"y":930,"wires":[["99f3baf.756be48","15467e2.0e01c82"]],"l":false},{"id":"68edec51.fb5b24","type":"inject","z":"28c631fa.7e866e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"UP","payloadType":"str","x":1420,"y":1000,"wires":[["975da5db.6f47f"]]},{"id":"c0f5029e.6f1c1","type":"inject","z":"28c631fa.7e866e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"DOWN","payloadType":"str","x":1420,"y":1040,"wires":[["975da5db.6f47f"]]},{"id":"68a0f3f2.511754","type":"inject","z":"28c631fa.7e866e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"FOO","payloadType":"str","x":1420,"y":1080,"wires":[["975da5db.6f47f"]]},{"id":"99f3baf.756be48","type":"link out","z":"28c631fa.7e866e","name":"Get new public IP","links":["1723bf77.0e3771","49140757.4051e"],"x":1830,"y":930,"wires":[],"l":true},{"id":"15467e2.0e01c82","type":"debug","z":"28c631fa.7e866e","name":"STATUS","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1730,"y":970,"wires":[]}]
You will need node-red-contrib-fan
for it to load.
Update:
Here is an update.
I suspect the RBE
node and have little choice than to test this theory.
I replaced it with this node/code (a function
block)
[{"id":"ebf6a97d.0ea5","type":"function","z":"28c631fa.7e866e","name":"RBE","func":"var old = context.get(\"OLD\") || 0;\nvar new_value = msg.payload;\nif (old != new_value)\n{\n context.set(\"OLD\",new_value);\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1855,"y":970,"wires":[["99f3baf.756be48","15467e2.0e01c82"]],"l":false}]
Now look at what happens (screen shots)
Changed from good to bad.
Getting worse.
Now it is really bad.
And this is what should happen
So could someone who really knows how things work explain this to me - please.