Write StatusCode and SourceTimestamp to an OPC-UA Server

Hello!

I'm currently utilizing the WRITE action of the OpcUa-Client node (from the node-red-contrib-opcua package) to send a value to an OPC-UA Server.

To set up the necessary msg with the targeted node id and the value for, I have used a function node with the following code:

msg.topic = "ns=2;s=InputSignal"
msg.datatype = "Float"
msg.payload = 100
return msg

My flow looks like this:

Is there a way to also specify the StatusCode that I want to write on the server? Additionally, can the SourceTimestamp be specified?

@mikakaraila

Thanks in advance

Isn't the status code autogenerated from the server response to a client's request? I could be wrong.

What are you trying to specify?

Grey

My goal was to understand if it's possible to write a StatusCode for example "Bad" from the client side to the server.
Maybe the StatusCode doesn't make much sense to be written from the client side, but the SourceTimestamp for me makes sense, since once a value has been assigned a source timestamp, the source timestamp for that value instance never changes, so the SourceTimestamp of the value that I want to pass must be kept.

Is there any way to do that?

I had to comment this code out as some (most) servers don´t accept writing statusCode or sourceTimestamp:

 nodeToWrite = {
            nodeId: nodeid.toString(),
            attributeId: opcua.AttributeIds.Value,
            value: new opcua.DataValue({
              value: new opcua.Variant(opcuaDataValue),
              // sourceTimestamp: new Date(),            // NOTE: Some servers do NOT accept time writing
              // statusCode: opcua.StatusCodes.Good      // NOTE: Same with status writing, NOT accepted always
            })
          };
1 Like

Some lines below:

        if (msg.timestamp) {
          nodeToWrite.value.sourceTimestamp = new Date(msg.timestamp).getTime();
        }

I will add same kind of handler for the statusCode to next version.

1 Like

With the changes you made to opcuaclient.js is now working as I expected. Thanks a lot!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.