Single input to node, but unexpected triplicate outputs

Hi everyone,

I have a weird error in Node-Red. In the flow below, I created counter nodes to show how many times messages are passed through the flow. I found that this is great tool for debugging complex flows that interact with PLCs.

You can see that the IsGateBlocked node was called once, but the output of the node fired 3 times. This is a potential deal breaker in industrial automation, and its completely unexpected.

The only workaround here was to add a filter node, but that does needlessly complicate the flow.

Please can you have a look at this and share any constructive thoughts on this topic?

I am running an old version of NR2.2 on the server, and not able to upgrade until December.

Can you show us the contents of IsGateBlocked and your 123 function?

Export then and paste here.

Also what do the inbound messages look like?

Hi jbudd,

Thanks for looking at my post.

Here is a screnshot of the node content:

I left out the bottom part....

[{"id":"6da85ff772e08cfa","type":"switch","z":"0f2ee729476aa90a","name":"IsGateBlocked","property":"blocked","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":2140,"y":900,"wires":[["93b173faae9a2cea","bcd5b7bc0ff2a4ef"]]}]

And here is my counter node:

[{"id":"bcd5b7bc0ff2a4ef","type":"function","z":"0f2ee729476aa90a","name":"Counter","func":"var counter = context.get('counter') || 0;\n\nif(msg.reset){\n counter = 0;\n node.status({\n fill:'gray',\n shape:'dot',\n text: counter\n }\n );\n\n delete msg.reset;\n\n}else{\n counter++;\n node.status({\n fill:'blue',\n shape:'dot',\n text: counter\n }\n );\n}\ncontext.set("counter",counter);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\ncontext.set("counter", 0);\nnode.status({\n fill: 'gray',\n shape: 'dot',\n text: 0\n}\n);","finalize":"","libs":,"x":2285,"y":780,"wires":[],"outputLabels":["Off"],"icon":"node-red-dashboard/ui_numeric.png","l":false}]

Here is a view of the the input ... a single message.

DIscord does things to pasted flows so they cannot be copy and pasted. You need to add ``` to the beginning and the end of the flow. See this link How-to-share-code-or-flow-json.

Sorry about the formatting, here is a version that should work based on the Discord guidelines.


[{"id":"b68d2bbddc2bf805","type":"rbe","z":"0f2ee729476aa90a","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":1850,"y":860,"wires":[["29095af57cab2664","4b11dfde59ac9c7d","bd0ccd2cda026804"]]},{"id":"bd0ccd2cda026804","type":"function","z":"0f2ee729476aa90a","name":"Counter","func":"var counter = context.get('counter') || 0;\n\nif(msg.reset){\n    counter = 0;\n    node.status({\n        fill:'gray',\n        shape:'dot',\n        text: counter\n        }\n    );\n\n    delete msg.reset;\n\n}else{\n    counter++;\n    node.status({\n        fill:'blue',\n        shape:'dot',\n        text: counter\n        }\n    );\n}\ncontext.set(\"counter\",counter);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\ncontext.set(\"counter\", 0);\nnode.status({\n    fill: 'gray',\n    shape: 'dot',\n    text: 0\n}\n);","finalize":"","libs":[],"x":2035,"y":780,"wires":[[]],"outputLabels":["Off"],"icon":"node-red-dashboard/ui_numeric.png","l":false},{"id":"4b11dfde59ac9c7d","type":"switch","z":"0f2ee729476aa90a","name":"Validation Check2","property":"status","propertyType":"msg","rules":[{"t":"eq","v":"OK","vt":"str"},{"t":"eq","v":"DUPLICATE","vt":"str"},{"t":"eq","v":"QC FAILED","vt":"str"},{"t":"eq","v":"RETRYING","vt":"str"},{"t":"eq","v":"NOREAD","vt":"str"}],"checkall":"false","repair":false,"outputs":5,"x":2030,"y":1060,"wires":[["be7947ecf2ba01f6","be7947ecf2ba01f6","be7947ecf2ba01f6","be7947ecf2ba01f6","6da85ff772e08cfa","6da85ff772e08cfa","be7947ecf2ba01f6","be7947ecf2ba01f6","6da85ff772e08cfa","6e5a6f95502c1142","5818b8a9ec28b7a7"],["472c79a37374c11f","472c79a37374c11f","472c79a37374c11f","472c79a37374c11f","472c79a37374c11f","472c79a37374c11f","77f41c4075cb82eb"],["472c79a37374c11f","472c79a37374c11f","472c79a37374c11f","472c79a37374c11f","472c79a37374c11f","472c79a37374c11f","e5e9d68a0a3e413c"],["c3ad158299c664e5","c3ad158299c664e5","c3ad158299c664e5"],["472c79a37374c11f"]]},{"id":"6da85ff772e08cfa","type":"switch","z":"0f2ee729476aa90a","name":"IsGateBlocked","property":"blocked","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":2140,"y":900,"wires":[["93b173faae9a2cea","bcd5b7bc0ff2a4ef"]]},{"id":"bcd5b7bc0ff2a4ef","type":"function","z":"0f2ee729476aa90a","name":"Counter","func":"var counter = context.get('counter') || 0;\n\nif(msg.reset){\n    counter = 0;\n    node.status({\n        fill:'gray',\n        shape:'dot',\n        text: counter\n        }\n    );\n\n    delete msg.reset;\n\n}else{\n    counter++;\n    node.status({\n        fill:'blue',\n        shape:'dot',\n        text: counter\n        }\n    );\n}\ncontext.set(\"counter\",counter);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\ncontext.set(\"counter\", 0);\nnode.status({\n    fill: 'gray',\n    shape: 'dot',\n    text: 0\n}\n);","finalize":"","libs":[],"x":2285,"y":780,"wires":[[]],"outputLabels":["Off"],"icon":"node-red-dashboard/ui_numeric.png","l":false},{"id":"6e5a6f95502c1142","type":"function","z":"0f2ee729476aa90a","name":"Counter","func":"var counter = context.get('counter') || 0;\n\nif(msg.reset){\n    counter = 0;\n    node.status({\n        fill:'gray',\n        shape:'dot',\n        text: counter\n        }\n    );\n\n    delete msg.reset;\n\n}else{\n    counter++;\n    node.status({\n        fill:'blue',\n        shape:'dot',\n        text: counter\n        }\n    );\n}\ncontext.set(\"counter\",counter);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\ncontext.set(\"counter\", 0);\nnode.status({\n    fill: 'gray',\n    shape: 'dot',\n    text: 0\n}\n);","finalize":"","libs":[],"x":2195,"y":960,"wires":[[]],"outputLabels":["Off"],"icon":"node-red-dashboard/ui_numeric.png","l":false}]

The only thing that I notice is that your message.blocked is a boolean, (as is msg.payload[0].blocked) but in the switch node you are comparing it against numeric zero.

It ought to work but I think it's clearer to use the Is true option in the switch node rather than == 0

It would be very odd indeed for the switch node to emit three outbound messages for a single input.
If the change I suggested above doesn't fix it, I would insert a junction into the wire feeding IsGateBlocked and add a debug, set to output msg.blocked, looking for clues.

Add debug nodes to the flow showing the messages going in and out to see if there really are multiple messages for each input message.