Multiple Inputs and Multiple Outputs

Good morning everyone,

I am using Node-Red with OPCUA to connect to a controller and display the values in their own gauge to the dashboard.

I was wondering if there may be a better way to do this.

My thinking is that it is not necessary to create an OPC UA Client node for each OPCUA Node that I want to read. I also wonder if this is creating a separate connection for each node that I want to read.
Can someone please advise if my thinking is correct and if there would be some way to use only one OPCUA Client node to retrieve all of the values and then use a function to disperse the values to their respective gauge?

Just to clarify, this is what the OPCUA Client node outputs with multiple inputs. It seems to output a separate value rather than an array of values.

Capture3

Okay, if I understood you correctly, you just would like to use a single OPC UA Client node. Your second example shows that this seems possible, you receive the temperature readings one-by-one. So far so good, but now you need to put each one of them into the correct gauge in the dashboard

To do that, you can use the Switch node. Just configure a rule for each temperature sensor/reading and connect the corresponding output from the Switch to the respective gauge node.

To give further advice about the rules configuration, you have to provide a full msg content, only the payload is not enough to give you advice. I can imagine that filtering on PTank[X] somehow could be your solution

Thank you krambriw,

Here is the complete message.

Using the switch node, I would need to configure it so that the property it is checking is msg.browseName

The rules would then need to be setup so that if the browseName == "Tank2_Temp" then output to the first output, and then so on for the others. Correct?

Capture4

Exactly

Like in this example:

image

1 Like

Thank you krambriw. That did the trick!

In case of future readers,

Each time you add an OPC UA Client node, another session is created on the OPC-UA server.

Hi sir, hope your doing well!
I have the same kind of issue, I want to read multiple opc ua variables but I don't want to have to drag a opc ua item node for each variable, I think I managed to store node ids in the opc ua client node but i cant seem to read them as i get the following error

Error    at Object.assert (/opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-opcua/node_modules/node-opcua-assert/dist/index.js:13:21)    at coerceReadValueId (/opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-opcua/node_modules/node-opcua-client/dist/private/client_session_impl.js:78:29)    at Array.map (<anonymous>)    at ClientSessionImpl.readVariableValue (/opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-opcua/node_modules/node-opcua-client/dist/private/client_session_impl.js:318:35)    at ClientSessionImpl.readVariableValue (/opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-opcua/node_modules/thenify/index.js:65:46)    at readmultiple_action_input (/opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-opcua/opcua/102-opcuaclient.js:665:22)    at OpcUaClientNode.processInputMsg [as _inputCallback] (/opt/plcnext/appshome/data/60002172000051/lib/node_m...

here is my flow exported and as an image:

[{"id":"cc95bb10.b86a68","type":"inject","z":"12fe81e2.84a77e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":610,"y":780,"wires":[["e72328bf.6d2e28"]]},{"id":"21a93691.75b30a","type":"OpcUa-Client","z":"12fe81e2.84a77e","endpoint":"e58eaf37.d067b","action":"readmultiple","deadbandtype":"a","deadbandvalue":1,"time":10,"timeUnit":"s","certificate":"n","localfile":"","securitymode":"None","securitypolicy":"None","name":"","x":1020,"y":800,"wires":[["3d9a7594.8d847a"]]},{"id":"3d9a7594.8d847a","type":"debug","z":"12fe81e2.84a77e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1190,"y":800,"wires":[]},{"id":"e72328bf.6d2e28","type":"function","z":"12fe81e2.84a77e","name":"irrigation sectors","func":"var a = \"ns=4;s=Arp.Plc.Eclr/Secteur_3_P_OFF;datatype=Boolean\";\nvar b = \"ns=4;s=Arp.Plc.Eclr/Secteur_3_P_ON;datatype=Boolean\";\nmsg.topic = [\n    {a},{b}\n] ;\n// msg.payload = \"read multiple\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":800,"y":780,"wires":[["21a93691.75b30a"]]},{"id":"53fb34b1.5df5ec","type":"inject","z":"12fe81e2.84a77e","name":"Read multiple items","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"readmultiple","payload":"","payloadType":"str","x":730,"y":840,"wires":[["21a93691.75b30a"]]},{"id":"f53a845a.e401c8","type":"inject","z":"12fe81e2.84a77e","name":"Clear nodeId array","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"clearitems","payload":"","payloadType":"str","x":770,"y":880,"wires":[["21a93691.75b30a"]]},{"id":"e58eaf37.d067b","type":"OpcUa-Endpoint","z":"","endpoint":"opc.tcp://192.168.1.10:4840","secpol":"None","secmode":"None","login":false}]

I get the "node ids stored" status as well as the "cleared items" status on the opc ua client node but i dont get the "active multiple reading" status , instead i get the error i mentionned.

Thanks for your help!

Good afternoon bdr21,

Did you solve this problem?

Good afterboon elyancorrea,
Not really but what i did was use this solution to dynamically add opc ua variables to the opc ua client node with just one inject node : https://flows.nodered.org/flow/5c4c0f5a08d4e91ea14d

here is my flow :

[{"id":"adbe2163.24b56","type":"inject","z":"63b4326b.ae226c","name":"27","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"27","payloadType":"num","x":110,"y":2740,"wires":[["cfff4d65.02371"]]},{"id":"cfff4d65.02371","type":"function","z":"63b4326b.ae226c","name":"BLINK n","func":"\nvar o = false;\nfor (var i=0; i<(msg.payload); i++) {\n    node.send( {payload:+(o=!o)} )\n}\n\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":2740,"wires":[["efcb931b.25d08"]]},{"id":"efcb931b.25d08","type":"switch","z":"63b4326b.ae226c","name":"","property":"vanneIndex","propertyType":"global","rules":[{"t":"lt","v":"18","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":2740,"wires":[["69497e93.92181"]]},{"id":"69497e93.92181","type":"function","z":"63b4326b.ae226c","name":"VanneB_VanneIndex","func":"msg.topic = `ns=4;s=Arp.Plc.Eclr/VanneB_${global.get(\"vanneIndex\")}` ;\nmsg.datatype = \"Boolean\";\nmsg.browseName = `VanneB_${global.get(\"vanneIndex\")}` ;\nglobal.set(\"vanneIndex\",global.get(\"vanneIndex\") + 1)\n// if (global.get(\"vanneIndex\") == 17) {\n//     global.set(\"clearVar\",1)\n// }\nreturn msg;\n// msg.topic = [\n//     \"ns=4;s=Arp.Plc.Eclr/Secteur_3_P_OFF\" ,\n//     \"ns=4;s=Arp.Plc.Eclr/Secteur_4_P_ON\" ,\n//     \"ns=4;s=Arp.Plc.Eclr/Secteu_4_P_OFF\" ,\n//     \"ns=4;s=Arp.Plc.Eclr/Secteur_5_P_ON\" \n// ] ;\n// msg.datatype = [\n//     \"Boolean\" ,\n//     \"Boolean\" ,\n//     \"Boolean\" ,\n//     \"Boolean\" \n// ] ;\n// msg.browseName = [\n//     \"Secteur_3_P_OFF\" ,\n//     \"Secteur_4_P_ON\" ,\n//     \"Secteu_4_P_OFF\" ,\n//     \"Secteur_5_P_ON\" \n// ] ;\n// return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":2740,"wires":[["3ad74b79.70f404"]]},{"id":"3ad74b79.70f404","type":"OpcUa-Client","z":"63b4326b.ae226c","endpoint":"19d9e7bb.ab4558","action":"readmultiple","deadbandtype":"a","deadbandvalue":1,"time":10,"timeUnit":"s","certificate":"n","localfile":"","name":"","x":800,"y":2740,"wires":[["6bef4592.be1afc"]]},{"id":"3ff82ad9.8c75b6","type":"inject","z":"63b4326b.ae226c","name":"Read multiple items","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"readmultiple","payload":"","payloadType":"str","x":590,"y":2800,"wires":[["3ad74b79.70f404"]]},{"id":"9d023b30.bdadd8","type":"inject","z":"63b4326b.ae226c","name":"Clear nodeId array","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"clearitems","payload":"","payloadType":"str","x":590,"y":2840,"wires":[["3ad74b79.70f404"]]},{"id":"6bef4592.be1afc","type":"debug","z":"63b4326b.ae226c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":2700,"wires":[]},{"id":"19d9e7bb.ab4558","type":"OpcUa-Endpoint","z":"","endpoint":"opc.tcp://192.168.1.10:4840","secpol":"None","secmode":"None","login":false}]

Could you please share the code.

Hello everyone, i need to reply this message because i need help. i have similar problem that i wat to understand:
In my flow i have 3 opcua items that i need to put in a Json-structure messagefor sending all to an application with HTTP Post Rquest.

Here is my function node for create a Json-structure:

msg.payload = [
{
"Temperature" : ... ,
"min_temperature" :98.6,
"Max_temperature" :98.6,
"Speed" :98.6,
"Mission" :98.6
}
]
return msg;

i need to add 3 opc-ua items in the same Json-structure but i don't know how to do. Normal examples show me the possibility to add just one with, for example, "Temperature" : msg.payload, btu how can i do if i have 3 different msg.payload?

Thanks in advance

I think you mean you want to put them in a javascript object. Are the three items in different messages? If so you need to get them into one message.
Do they start off in one message which you then split or do they start off in different messages?
Is it possible to change the way you fetch them so that you fetch them all in one go?

If not then you will have to join them together into one message. See this article in the cookbook for an example of how to join messages into one object.

first of all, thanks for answering me.
i will try to give more informazions. t

  • are three different messages, they start with the same inject node (as show in picture attached)
    here are 3 different messages that i have from OPCUAClient: Temperature, Speed and Mission. i want to put together in the message before but i don't know how to do.

msg.payload = [
{
"Temperature" : HEREMYOPCUAVALUE1 ,
"min_temperature" :98.6,
"Max_temperature" :98.6,
"Speed" :HEREMYOPCUAVALUE2
"Mission" :HEREMYOPCUAVALUE3
}
]
return msg;

Here what i'm thinking about.

I don't use opc-ua, but I see the node has a read multiple feature. Can you use that to read all three items at once? Then they would all be in one message (I presume) which is much better than joining them afterwards. It is probably more efficient in the comms with the PLC too.