mikakaraila / node-red-contrib-opcua

A Node-RED node to communicate OPC UA. Uses node-opcua library.
Other
208 stars 191 forks source link

Better OPC-Client Description #702

Open muratcanberber opened 1 month ago

muratcanberber commented 1 month ago

I have rewrited OPC-UA Client description from ChatGPT. Would you consider to use it ?

Here's a revised and clearer version of the document, with added code examples for better understanding:


OpcUa-Client Guide

Connecting to an Endpoint

To connect to an OPC UA endpoint, use the following format:

opc.tcp://host:port/UA/EndpointName

Actions

Read

Reads the value of a node.

msg.topic = "ns=2;s=Channel1.Device1.Tag1";
return msg;

Write

Writes a value to a node.

msg.topic = "ns=2;s=Channel1.Device1.Tag1";
msg.payload = 42;  // Value to write
return msg;

Browse

Browses the address space.

msg.topic = "ns=2;s=Channel1.Device1";
return msg;

Subscribe

Subscribes to changes of a node value.

msg.topic = "ns=2;s=Channel1.Device1.Tag1";
msg.payload = {
    interval: 100  // Interval in ms
};
return msg;

Unsubscribe

Unsubscribes from a node.

msg.topic = "ns=2;s=Channel1.Device1.Tag1";
return msg;

Delete Subscription

Deletes a subscription.

msg.topic = "delete_subscription";
return msg;

Event

Subscribes to events.

msg.topic = "ns=2;s=Channel1.Device1.Event";
return msg;

Info

Reads attributes from a node.

msg.topic = "ns=2;s=Channel1.Device1.Tag1";
return msg;

Build

Constructs an Extension Object message.

msg.topic = "build";
msg.datatype = "MyDataType";
msg.payload = {
    field1: "value1",
    field2: "value2"
};
return msg;

Monitor

Monitors a node with additional parameters.

msg.topic = "ns=2;s=Channel1.Device1.Tag1";
msg.payload = {
    interval: 100,  // Interval in ms
    deadbandType: "Absolute",
    deadbandValue: 0.1
};
return msg;

Read Multiple

Reads multiple nodes.

msg.payload = ["ns=2;s=Channel1.Device1.Tag1", "ns=2;s=Channel1.Device1.Tag2"];
msg.topic = "read_multiple";
return msg;

Write Multiple

Writes values to multiple nodes.

msg.payload = [
    {nodeId: "ns=2;s=Channel1.Device1.Tag1", value: 42},
    {nodeId: "ns=2;s=Channel1.Device1.Tag2", value: 43}
];
msg.topic = "write_multiple";
return msg;

Register

Registers node IDs.

msg.payload = ["ns=2;s=Channel1.Device1.Tag1"];
msg.topic = "register";
return msg;

Unregister

Unregisters node IDs.

msg.payload = ["ns=2;s=Channel1.Device1.Tag1"];
msg.topic = "unregister";
return msg;

Acknowledge

Acknowledges an event/condition.

msg.topic = "ns=2;s=Channel1.Device1.Alarm";
msg.conditionId = "ns=2;s=Channel1.Device1.Event";
msg.comment = "Acknowledged";
return msg;

History

Reads historical values or aggregates.

msg.topic = "ns=2;s=Channel1.Device1.Tag1";
msg.aggregate = "raw";
msg.start = new Date(Date.now() - 3600000);  // 1 hour ago
msg.end = new Date();
return msg;

Read File

Reads a file from the server.

msg.topic = "ns=2;s=Channel1.Device1.File";
return msg;

Write File

Writes a file to the server.

msg.topic = "ns=2;s=Channel1.Device1.File";
msg.payload = Buffer.from("File content");
return msg;

Connect

Connects to the server.

msg.topic = "connect";
return msg;

Disconnect

Disconnects from the server.

msg.topic = "disconnect";
return msg;

Reconnect

Reconnects to the server.

msg.topic = "reconnect";
return msg;

Method

Calls a method on the server.

msg.topic = "ns=2;s=Channel1.Device1.Method";
msg.payload = {
    inputArguments: [42, "arg2"]
};
return msg;

Server Certificate Options

The client will try to load the server certificate from the endpoint if available. Manually copying the server certificate is also an option. Use a relative path and filename for the server certificate (must have a .pem extension).

Inject Node Usage

Inject your OPC UA address (NodeId) by the Topic of an Inject node or with the OpcUa-Item controlled by an Inject node.

Status Monitoring

The second output of the node provides status information:

{
    error: "error message",
    endpoint: "opcuaEndpoint",
    status: "currentStatus"
}

For more detailed examples, refer to the examples folder and the flow file OPCUA-MULTI-SUB.json.


mikakaraila commented 1 month ago

For me it does not look accurate, missing action!

integratec commented 2 weeks ago

First look... also missing datatype for action write.