1

i've found here an example code that works ok as a subscription to events (code below), i'm trying to use it on a custom serve that send some other fields, but if i add those fileds name to the const fields, i get null value, so i would like to get all the fields available in the event to understand what the server send but if i remove the eventFilter option i just get empty events

any suggestion on how to get all the fields from an event?

import {
  AttributeIds,
  constructEventFilter,
  ObjectIds,
  OPCUAClient,
  TimestampsToReturn,
  Variant,
} from "node-opcua-client";

async function main(): Promise<void> {

  const client = OPCUAClient.create({});

  const endpointUrl = "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer";

  const subscriptionParamters = {
    requestedPublishingInterval: 1000,
    maxNotificationsPerPublish: 100,
    publishingEnabled: true,
    priority: 10,
  };

  await client.withSubscriptionAsync(endpointUrl, subscriptionParamters, async (session, subscription) => {
      const fields = [
        "EventId",
        "EventType",
        "SourceNode",
        "SourceName",
        "Time",
        "ReceiveTime",
        "Message",
        "Severity",
      ];
      const eventFilter = constructEventFilter(fields);
      const event_monitoringItem = await subscription.monitor(
        {
          nodeId: ObjectIds.Server,
          attributeId: AttributeIds.EventNotifier,
        },
        {
          queueSize: 10,
          filter: eventFilter,
          discardOldest: true,
        },
        TimestampsToReturn.Both
      );

      event_monitoringItem.on("changed", (events: Variant[]) => {
        for(let i=0;i<events.length;i++) {
            console.log(fields[i],"=", events[i].toString());
        }
        console.log("----------------\n\n")
      });

      console.log("CTRL+C to stop");
      await new Promise<void>((resolve) => process.once("SIGINT", resolve));

    }
  );
}
main();
Darkmagister
  • 53
  • 1
  • 6
  • Can you try to remove the eventFilter option and the fields array entirely. This may allow you to receive all fields available in the event: Instead of this line: `const eventFilter = constructEventFilter(fields);` You can use this: `const eventFilter = null;` – SFriedl Jan 17 '23 at 09:09

1 Answers1

0

I think you have to add the namespace index for your single event fields as well. And if they are sub properties the full path.

So it could look like this:

const fields = [
  "EventId",
  "EventType",
  "3:MyProp1",
  "3:MyProp2",
  "3:SomeSubObject/SomeOtherProperty",
];
Tyler2P
  • 2,324
  • 26
  • 22
  • 31