Git Product home page Git Product logo

Comments (3)

AcureroAdrian avatar AcureroAdrian commented on June 12, 2024

While debugging the code, I observed that in the 'result' parameter of the callback, which is passed as an argument to this.translateBrowsePath, the StatusCode is:

 statusCode: BadNodeIdUnknown (0x80340000) {
      _description: 'The node id refers to a node that does not exist in the server address space.',
      _name: 'BadNodeIdUnknown',
      _value: 2150891520,
}

image

from node-opcua.

AcureroAdrian avatar AcureroAdrian commented on June 12, 2024

I successfully acknowledged the alarm by employing a different method, which I discovered in a node-opcua issue discussion:
How to acknowledge alarm using Cogent DataHub #1317

However, the standard or 'correct' method for event acknowledgment proved entirely ineffective in my case. Consequently, it's fair to conclude that this issue remains unresolved.

This situation is particularly puzzling since I've been providing precisely the same parameters that worked with session.acknowledgeCondition.

Here's how the code currently stands:
image

Additionally, I am eager to share the complete code for the benefit of anyone looking to implement a similar solution.

import express from "express";
import { createServer } from 'node:http'
import { AttributeIds, OPCUAClient, TimestampsToReturn, constructEventFilter, ObjectIds, callConditionRefresh, MethodIds, Variant, DataType } from "node-opcua-client";

const app = express();
const server = createServer(app);

const URL = "opc.tcp://ADRIAN-ASUS:4840";

(async () => {
    try {
        const client = OPCUAClient.create();

        client.on("backoff", (retry, delay) => {
            console.log("Retying to connect to ", URL, " attempt ", retry);
        });

        console.log("connecting to ", URL);
        await client.connect(URL);
        console.log("connected to ", URL);

        const session = await client.createSession();
        console.log("session initialized");

        const subscripcion = await session.createSubscription2({
            requestedPublishingInterval: 50,
            requestedMaxKeepAliveCount: 20,
            publishingEnabled: true,
        });

        const fields = [
            "EventId",
            "AckedState",
            "AckedState.Id",
            "ConfirmedState",
            "ConfirmedState.Id",
            "ConditionId",
        ];

        const eventFilter = constructEventFilter(fields);

        const itemToMonitor = {
            nodeId: ObjectIds.Server,
            attributeId: AttributeIds.EventNotifier,
        };

        const parameters = {
            filter: eventFilter,
            discardOldest: true,
            queueSize: 100,
        };


        const EventMonitor = await subscripcion.monitor(
            itemToMonitor,
            parameters,
            TimestampsToReturn.Both
        )

        const alarmData = {
        }

        callConditionRefresh(subscripcion) // Give us all events!!!

        EventMonitor.on("changed", (events) => {
            for (let i = 0; i < events.length; i++) {
                alarmData[fields[i]] = events[i].value
            }
            console.log(alarmData)
        });

        setTimeout(async () => {
            try {

                /* session.acknowledgeCondition(alarmData.ConditionId, alarmData.EventId, comment, (err) => {
                    console.log({ err })
                }) */

                const methodToCall = {
                    objectId: alarmData.ConditionId,
                    methodId: MethodIds.AcknowledgeableConditionType_Acknowledge, // TODO: Replace to MethodIds
                    inputArguments: [
                        new Variant({ dataType: DataType.ByteString, value: alarmData.EventId }),
                        new Variant({ dataType: DataType.LocalizedText, value: "test comment!" })
                    ]
                }

                session.call(methodToCall, (err, result) => {
                    if (err) return console.log(err); // Currently not important
                    console.log("Method call result: " + JSON.stringify(result, null, 2));
                })
            } catch (error) {
                console.log(error)
            }

        }, 5000)



        let running = true;
        process.on("SIGINT", async () => {
            if (!running) {
                return; // avoid calling shutdown twice
            }
            console.log("shutting down client");
            running = false;
            await subscripcion.terminate();
            await session.close();
            await client.disconnect();
            console.log("Done");
            process.exit(0);
        });
    } catch (error) {
        console.log("ERROR: ", error.message);
        console.log(error);
    }

    server.listen(4000, () => {
        console.log('server running at http://localhost:4000');
    });
})();

from node-opcua.

erossignon avatar erossignon commented on June 12, 2024

It should be fixed now in [email protected].
@AcureroAdrian can you confirm ?

from node-opcua.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.