Hi,
I am learning opc ua and using node-red OPC UA nodes to create a flow where I can read all the variables periodically. After getting the complete address space of thr OPC UA server, I filtered out all the variable references in an array. In a simple for loop, I am then, calling the BROWSE node for each of these variables using node.send(msg) after setting msg.topic with the nodeId (ns=x;i=y).
The BROWSE node produces the correct payload only if single element is present in the variable array(single-element-array.jpg). Which means when its called only once. Calling more then once, the payload has no items in the array(multiple-element-array). What could be the reason the BROWSE node doesn't work when called in a loop?
Here's the flow:
[
{
"id": "ae2e6953005a4235",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "09131db5fbb93ca4",
"type": "inject",
"z": "ae2e6953005a4235",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 200,
"y": 180,
"wires": [
[
"859de096ba5b88bc"
]
]
},
{
"id": "859de096ba5b88bc",
"type": "function",
"z": "ae2e6953005a4235",
"name": "test_overloading",
"func": "let variables_array = [\t\t{\n\t\t\"referenceTypeId\": \"ns=0;i=47\",\n\t\t\"isForward\": true,\n\t\t\"nodeId\": \"ns=0;i=2256\",\n\t\t\"browseName\": {\n\t\t\t\"namespaceIndex\": 0,\n\t\t\t\"name\": \"ServerStatus\"\n\t\t},\n\t\t\"displayName\": {\n\t\t\t\"text\": \"ServerStatus\"\n\t\t},\n\t\t\"nodeClass\": \"Variable\",\n\t\t\"typeDefinition\": \"ns=0;i=2138\"\n\t},\n\t{\n\t\t\"referenceTypeId\": \"ns=0;i=46\",\n\t\t\"isForward\": true,\n\t\t\"nodeId\": \"ns=0;i=2255\",\n\t\t\"browseName\": {\n\t\t\t\"namespaceIndex\": 0,\n\t\t\t\"name\": \"NamespaceArray\"\n\t\t},\n\t\t\"displayName\": {\n\t\t\t\"text\": \"NamespaceArray\"\n\t\t},\n\t\t\"nodeClass\": \"Variable\",\n\t\t\"typeDefinition\": \"ns=0;i=68\"\n\t}];\nfor (let i = 0; i < variables_array.length; i++) {\n let node_id = variables_array[i].nodeId;\n msg.payload = \"\";\n msg.topic = node_id;\n node.send(msg);\n}\nvariables_array = null;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 180,
"wires": [
[
"f0e40795a880a0e7"
]
]
},
{
"id": "f0e40795a880a0e7",
"type": "OpcUa-Browser",
"z": "ae2e6953005a4235",
"endpoint": "d98c1a19c588c1be",
"item": "",
"datatype": "",
"topic": "",
"items": [],
"name": "Read SIngle Node",
"x": 610,
"y": 180,
"wires": [
[
"01323ead260f0b62"
]
]
},
{
"id": "01323ead260f0b62",
"type": "debug",
"z": "ae2e6953005a4235",
"name": "read_variables",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 840,
"y": 180,
"wires": []
},
{
"id": "d98c1a19c588c1be",
"type": "OpcUa-Endpoint",
"endpoint": "opc.tcp://192.168.1.20:53530/OPCUA/SimulationServer",
"secpol": "None",
"secmode": "None",
"none": true,
"login": false,
"usercert": false,
"usercertificate": "",
"userprivatekey": ""
}
]