complete example for read multiple values from OPCUA server with function node-through node-red-contrib-opcua module
Hi there!
Here is a complete example for READ-MULTIPLE mode of a OPC UA Client node from node-red-contrib-opcua.
This example is taken from a section of a complete IIoT system I developed. I made it quite robust by adding a fallback mechanism in case of failures — but of course, you can use only the parts you need and remove the fallback logic (which involves the 'linkIn', 'linkOut' nodes and the 'areNodeIdsStored' variable).
[
{
"id": "a07113ad99ef2c6f",
"type": "group",
"z": "521893e30bf3a45c",
"name": "Client READ-MULTIPLE",
"style": {
"label": true,
"stroke": "#0070c0",
"fill": "#0070c0",
"fill-opacity": "0.1",
"color": "#000000",
"label-position": "n"
},
"nodes": [
"a3ebbfea1281b7dd",
"dbc58fbb4b1a16b0",
"9c9d996d104812c2",
"b58839d38bec2747",
"cb3c845452788b5f",
"6a1304589666c6b8",
"bc1dd60b6f0e60e8",
"777bfd51dab63c6a",
"7d4c5a82a267599c",
"0c0c5e44cb7ac40b",
"1f8f9c895eba953a",
"0f649565db5398cf",
"68072338f325f046",
"f0d4ef6807685e3e",
"c879bc714d85e3c0",
"48eca354f6767036",
"57dabcc722d5c830",
"d9b6eec4bb841b9b",
"1825f0fa1828f615",
"3f4d923cca1abe78"
],
"x": 134,
"y": 571.8571510314941,
"w": 1572,
"h": 369.14284896850586
},
{
"id": "a3ebbfea1281b7dd",
"type": "OpcUa-Client",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"endpoint": "5054e70d33a31e8f",
"action": "readmultiple",
"deadbandtype": "a",
"deadbandvalue": 1,
"time": 10,
"timeUnit": "s",
"certificate": "n",
"localfile": "",
"localkeyfile": "",
"securitymode": "None",
"securitypolicy": "None",
"useTransport": false,
"maxChunkCount": 1,
"maxMessageSize": 8192,
"receiveBufferSize": 8192,
"sendBufferSize": 8192,
"setstatusandtime": false,
"keepsessionalive": false,
"name": "",
"x": 940,
"y": 740,
"wires": [
[
"6a1304589666c6b8"
],
[
"dbc58fbb4b1a16b0"
],
[]
]
},
{
"id": "dbc58fbb4b1a16b0",
"type": "switch",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "",
"property": "status",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "no items to read",
"vt": "str"
},
{
"t": "eq",
"v": "nodeId stored",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1150,
"y": 760,
"wires": [
[
"b58839d38bec2747"
],
[
"9c9d996d104812c2"
]
]
},
{
"id": "9c9d996d104812c2",
"type": "change",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "Ok",
"rules": [
{
"t": "set",
"p": "areNodeIdsStored",
"pt": "flow",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1330,
"y": 780,
"wires": [
[]
]
},
{
"id": "b58839d38bec2747",
"type": "change",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "Error (try again)",
"rules": [
{
"t": "set",
"p": "areNodeIdsStored",
"pt": "flow",
"to": "false",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1360,
"y": 740,
"wires": [
[
"cb3c845452788b5f"
]
]
},
{
"id": "cb3c845452788b5f",
"type": "link out",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "OPC UA Client [Error-NoNodeIdsRegistered]",
"mode": "link",
"links": [
"f0d4ef6807685e3e"
],
"x": 1535,
"y": 740,
"wires": []
},
{
"id": "6a1304589666c6b8",
"type": "switch",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "statusCode == OK",
"property": "statusCode.value",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 1170,
"y": 700,
"wires": [
[
"3f4d923cca1abe78"
]
]
},
{
"id": "bc1dd60b6f0e60e8",
"type": "OpcUa-Item",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"item": "ns=6;i=492060",
"datatype": "Byte",
"value": "",
"name": "NodeId1",
"x": 700,
"y": 680,
"wires": [
[
"a3ebbfea1281b7dd"
]
]
},
{
"id": "777bfd51dab63c6a",
"type": "OpcUa-Item",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"item": "ns=6;i=426524",
"datatype": "Byte",
"value": "",
"name": "NodeId2",
"x": 700,
"y": 720,
"wires": [
[
"a3ebbfea1281b7dd"
]
]
},
{
"id": "7d4c5a82a267599c",
"type": "OpcUa-Item",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"item": "ns=6;i=229916",
"datatype": "Byte",
"value": "",
"name": "NodeId3",
"x": 700,
"y": 760,
"wires": [
[
"a3ebbfea1281b7dd"
]
]
},
{
"id": "0c0c5e44cb7ac40b",
"type": "OpcUa-Item",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"item": "ns=6;i=164380",
"datatype": "Byte Array",
"value": "",
"name": "NodeId4",
"x": 700,
"y": 800,
"wires": [
[
"a3ebbfea1281b7dd"
]
]
},
{
"id": "1f8f9c895eba953a",
"type": "inject",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "Inject NodeIds (initialization)",
"props": [],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "1",
"topic": "",
"x": 300,
"y": 720,
"wires": [
[
"0c0c5e44cb7ac40b",
"7d4c5a82a267599c",
"777bfd51dab63c6a",
"bc1dd60b6f0e60e8"
]
]
},
{
"id": "0f649565db5398cf",
"type": "inject",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "[debug] Read all",
"props": [
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "readmultiple",
"x": 660,
"y": 900,
"wires": [
[
"a3ebbfea1281b7dd"
]
]
},
{
"id": "68072338f325f046",
"type": "inject",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "[debug] Clear",
"props": [
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "clearitems",
"x": 660,
"y": 860,
"wires": [
[
"a3ebbfea1281b7dd"
]
]
},
{
"id": "f0d4ef6807685e3e",
"type": "link in",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "OPC UA Client [Register NodeIds]",
"links": [
"57dabcc722d5c830",
"cb3c845452788b5f"
],
"x": 255,
"y": 780,
"wires": [
[
"48eca354f6767036"
]
]
},
{
"id": "c879bc714d85e3c0",
"type": "comment",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "About \"NodeIds\" (click me)",
"info": "## OPC UA - NodeId (Node Identifier)\n\nIn **OPC UA**, a **NodeId** uniquely identifies a node (e.g., variable, object, method) in the server’s **Address Space**.\n\n## NodeId Structure\n- **Namespace Index (ns):** Distinguishes identifiers from different domains.\n- **Identifier Type:** Can be one of the following:\n - Numeric (`i=`)\n - String (`s=`)\n - GUID (`g=`)\n - ByteString (`b=`)\n- **Identifier:** The actual value that identifies the node.\n\n## Examples\n- `ns=2;i=1234` → Numeric\n- `ns=1;s=Motor1.Status` → String\n- `ns=3;g=550e8400-e29b-41d4-a716-446655440000` → GUID\n- `ns=4;b=QmFzZTY0` → ByteString\n\n## Purpose\n- Allows clients to access:\n - Variables\n - Methods\n - Objects\n - Folders\n- Used in operations like `Read`, `Write`, `Browse`, and `Call`.\n\n> To find the data and corresponding NodeIds, I recommend using the 'UA Expert' software to connect and browse your OPC UA server.",
"x": 410,
"y": 840,
"wires": [],
"icon": "font-awesome/fa-info-circle"
},
{
"id": "48eca354f6767036",
"type": "delay",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "",
"pauseType": "delay",
"timeout": "3",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 360,
"y": 780,
"wires": [
[
"7d4c5a82a267599c",
"bc1dd60b6f0e60e8",
"777bfd51dab63c6a",
"0c0c5e44cb7ac40b"
]
]
},
{
"id": "57dabcc722d5c830",
"type": "link out",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "Fallback [Re-Inject NodeIds]",
"mode": "link",
"links": [
"f0d4ef6807685e3e"
],
"x": 825.0000171661377,
"y": 612.8571510314941,
"wires": []
},
{
"id": "d9b6eec4bb841b9b",
"type": "switch",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "are NodeIds Stored?",
"property": "areNodeIdsStored",
"propertyType": "flow",
"rules": [
{
"t": "false"
},
{
"t": "true"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 640,
"y": 620,
"wires": [
[
"57dabcc722d5c830"
],
[
"a3ebbfea1281b7dd"
]
]
},
{
"id": "1825f0fa1828f615",
"type": "inject",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "Read Data 1x/minute",
"props": [],
"repeat": "60",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 320,
"y": 620,
"wires": [
[
"d9b6eec4bb841b9b"
]
]
},
{
"id": "3f4d923cca1abe78",
"type": "debug",
"z": "521893e30bf3a45c",
"g": "a07113ad99ef2c6f",
"name": "your data should appear here if everything is ok",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1480,
"y": 700,
"wires": []
},
{
"id": "5054e70d33a31e8f",
"type": "OpcUa-Endpoint",
"endpoint": "opc.tcp://192.168.0.50:4840",
"secpol": "None",
"secmode": "None",
"none": true,
"login": false,
"usercert": false,
"usercertificate": "",
"userprivatekey": ""
}
]
Also read the official page of node-red-contrib-opcua module, they have a lot of usage examples there.
Hope this helps you ^^