3

I have an OPC-UA server up and running with some pre-configured tags, now I want to add a new Variable from my NodeJS OPC-UA client when my certain tag changes. For e.g.

import {
    OPCUAClient,
    MessageSecurityMode, SecurityPolicy,
    AttributeIds,
 } from "node-opcua-client";

const connectionStrategy = {
    initialDelay: 1000,
    maxRetry: 1
}

const options = {
    applicationName: "MyClient",
    connectionStrategy: connectionStrategy,
    securityMode: MessageSecurityMode.SignAndEncrypt,
    securityPolicy: SecurityPolicy.Basic256Sha256,
    endpointMustExist: false,
    
};
const client = OPCUAClient.create(options);
const endpointUrl = "{opc_url}";

try {
      // step 1 : connect to
      await client.connect(endpointUrl).then(res => console.log('connected!'))
    //   console.log("connected !");
  
      // step 2 : createSession
      await client.createSession({userName: "user_name", password: "password"}, async (err, session) => {
        if(err){
            console.log(err)
        }
        if(!err){
           // do something
        }
      }
    }

Above in the do something part I tried:

var nodeId = "nodeId";
var nodesToWrite = [{
                nodeId: nodeId,
                attributeId: AttributeIds.Value,
                value: /*new DataValue(*/{
                  value: {/* Variant */
                    dataType: 1,
                    value: false
                    }
                  }
                }];
session.write(nodesToWrite, (err, statusCodes) => {
    if(!err){
          console.log("success", statusCodes);
        } else {
          console.log(err, statusCodes)
        }
    }
); 

But since the nodeId doesn't exist so it will throw the error that it doesn't exist. I found a snippet example to add variables from the server-side, but is it possible to do it from the client's side as we want to add some variables based on the other variables which I am monitoring from the client's side.

Mayank Pathela
  • 453
  • 1
  • 6
  • 15

1 Answers1

0

Please see the link https://reference.opcfoundation.org/Core/docs/Part4/5.7.2/

And check with SDK/Server vendor, whether they support NodeManagement Service Set or not.

If yes, you can find a method in the session context like session.addNodes()

Sinu
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 01 '21 at 15:44