How to use the node-opcua.TimestampsToReturn.Both function in node-opcua

To help you get started, we’ve selected a few node-opcua examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua-htmlpanel / app.js View on Github external
});
    
        console.log("Listening on port " + port);
        console.log("visit http://localhost:" + port);
        // --------------------------------------------------------
    
        const itemToMonitor = {
            nodeId: nodeIdToMonitor,
            attributeId: AttributeIds.Value
        };
        const parameters = {
            samplingInterval: 100,
            discardOldest: true,
            queueSize: 100
        };
        const monitoredItem = await subscription.monitor(itemToMonitor, parameters, TimestampsToReturn.Both);

        monitoredItem.on("changed", (dataValue) => {
            console.log(dataValue.value.toString());
            io.sockets.emit('message', {
                value: dataValue.value.value,
                timestamp: dataValue.serverTimestamp,
                nodeId: nodeIdToMonitor,
                browseName: "Temperature"
            });
        });

        // detect CTRL+C and close
        let running = true;
        process.on("SIGINT", async () => {
            if (!running) {
                return; // avoid calling shutdown twice
github node-opcua / node-opcua / packages / playground / client_with_simple_subscription.js View on Github external
subscription.on("raw_notification", (n) => {
            //console.log(n.toString());
        });

        const itemToMonitor = {
            attributeId: AttributeIds.Value,
            nodeId: resolveNodeId("ns=0;i=2258")
        };

        const parameters = {
            discardOldest: true,
            queueSize: 10,
            samplingInterval: 2000
        };

        const monitoredItem = ClientMonitoredItem.create(subscription, itemToMonitor, parameters, TimestampsToReturn.Both);

        // subscription.on("item_added",function(monitoredItem){
        monitoredItem.on("initialized", () => {
            console.log(" Initialized !");
        });

        monitoredItem.on("changed", (dataValue) => {
            console.log("Changed on ", dataValue.value.toString());
        });

        const nodeToRead = { nodeId: "i=2258", attributeId: AttributeIds.Value };

        const timer = setInterval(async () => {
            try {
                const dv = await session.read(nodeToRead);
                console.log("dv =", session.sessionId.toString(), session.timeout, dv.statusCode.toString());
github node-opcua / node-opcua / documentation / sample_client_ts.ts View on Github external
const itemToMonitor: ReadValueIdLike = {
      nodeId: "ns=3;s=Scalar_Simulation_Float",
      attributeId: AttributeIds.Value
    };
    const parameters: MonitoringParametersOptions = {
      samplingInterval: 100,
      discardOldest: true,
      queueSize: 10
    };
    
    const monitoredItem = ClientMonitoredItem.create(
      subscription,
      itemToMonitor,
      parameters,
      TimestampsToReturn.Both
    );
    
    monitoredItem.on("changed", (dataValue: DataValue) => {
      console.log(" value has changed : ", dataValue.value.toString());
    });
    
    async function timeout(ms: number) {
      return new Promise(resolve => setTimeout(resolve, ms));
    }
    await timeout(10000);
    
    console.log("now terminating subscription");
    await subscription.terminate();

    // step 6: finding the nodeId of a node by Browse name
    const browsePath = makeBrowsePath(