node.jsopc-uaopcnode-opcua

Nodejs OPCUA multiple monitored items in a subscription object


i need subscribe to mutliple monitored item on a subcripiton object. I build below codes in nodejs and working.

    const itemToMonitor = {
        nodeId: resolveNodeId("ns=2;s=Channel1.Device1.temprature"),
        attributeId: AttributeIds.Value
    };
    const itemToMonitor2 = {
            nodeId: resolveNodeId("ns=2;s=Channel1.Device1.altitude"),
            attributeId: AttributeIds.Value
    };
    const monitoringParamaters = {
        samplingInterval: 1000,
        discardOldest: true
    };
    the_subscription.monitor(itemToMonitor, monitoringParamaters, TimestampsToReturn.Both, (err, monitoredItem) => {
        monitoredItem.on("changed", function (dataValue) {
            console.log("monitored item changed:  temprature = ", dataValue.value.value);
        });
    });
    the_subscription.monitor(itemToMonitor2, monitoringParamaters, TimestampsToReturn.Both, (err, monitoredItem) => {
        monitoredItem.on("changed", function (dataValue) {
            console.log("monitored item changed:  altitude = ", dataValue.value.value);
        });
    });

but i need something like that :

the_subscription.monitor({itemToMonitor,itemToMonitor2}, monitoringParamaters, TimestampsToReturn.Both, (err, monitoredItem) => {
            monitoredItem.on("changed", function (datavalues) {
                datavalues.each(){
                    //
                }
            });
        });

Is it possible ? I did something similar to this in .net core:

.net core codes (what i want sample)

    _subscription.AddItems(_nodes);
    _subscription.FastDataChangeCallback = new FastDataChangeNotificationEventHandler(DataChanged);
    _session.AddSubscription(_subscription);
    _subscription.Create();

        private void DataChanged(Subscription subscription, DataChangeNotification notification, IList<string> stringTable)
        {
          //
        }

Solution

  • I solved;

    its wrong;

    the_subscription.monitor({itemToMonitor,itemToMonitor2}, monitoringParamaters, TimestampsToReturn.Both, (err, monitoredItem) => {
         monitoredItem.on("changed", function (datavalues) {
    
         });
    });
    

    its true

      //monitoredNodes is an monitoredItem list
      the_subscription.monitorItems(monitoredNodes, monitoringParamaters, TimestampsToReturn.Both, (err, monitoredItems) => {
          monitoredItems.on("changed", function (items,data) {
              console.log("Node ID: ", items.itemToMonitor.nodeId.value);
              console.log("Node value: ", data.value.value);
          });
      });
    

    Document : https://node-opcua.github.io/api_doc/2.32.0/classes/node_opcua.clientsubscription.html#monitoritems