I use the node-opcua module and I would like to track many opc ua nodes with a subscription. I see the result, for example: user in the html UI selects which nodes to monitor, then click on the βMonitorβ button that sent these nodeIds as parameters, and then for each nodeid a subscription will be installed, and .on ("changed") works for each of these elements, as in parallel. Now the code looks like this:
var monitoredItem = the_subscription.monitor({ nodeId: opcua.resolveNodeId("ns=6;s=S71500ET200MP station_1.Master.111"), attributeId: 13 }, { samplingInterval: 100, discardOldest: true, queueSize: 10 }, opcua.read_service.TimestampsToReturn.Both ); console.log("-------------------------------------"); var nodes = []; monitoredItem.on("changed",function(dataValue){ //console.log(" value = ",dataValue.value.value); //console.log(" sourceTimestamp = ",dataValue.sourceTimestamp.toISOString()); //console.log(JSON.stringify(dataValue)); var Node = {nodeId: "ns=6;s=S71500ET200MP station_1.Master.111", nodeName: "111" , nodeValue: dataValue.value.value , nodeTimestamp: dataValue.sourceTimestamp.toISOString()}; var arrayNode = Object.keys(Node).map(function(k) { return Node[k] }); //console.log(JSON.stringify(Node)); nodes.push(arrayNode); // console.log(nodes); }); },
Right now, if I want to install a new control item, just add a lot of monitors MonitorItem1, .. 2, .. 3 etc.
How to do more agile/dynamic ? if I have an array (strings) of nodeIds and I want each of them to be tracked in a subscription. The code is part of async.series ([code])
source share