# Write StatusCode and SourceTimestamp to an OPC-UA Server

**URL:** <https://discourse.nodered.org/t/write-statuscode-and-sourcetimestamp-to-an-opc-ua-server/90713>\
**Category:** Industrial\
**Created:** [4 September 2024 15:01 UTC](https://discourse.nodered.org/t/write-statuscode-and-sourcetimestamp-to-an-opc-ua-server/90713 "2024-09-04T15:01:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![star-board](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@star-board](https://discourse.nodered.org/u/star-board)\
**Post date:** [4 September 2024 15:01 UTC](https://discourse.nodered.org/t/write-statuscode-and-sourcetimestamp-to-an-opc-ua-server/90713/1 "2024-09-04T15:01:26Z")

</div>

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:

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

```

My flow looks like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/7/c7bad14e20dfa9c5e643d96e894fd638d03bd5b4.png)

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

---

<div class="post-metadata">

**Author:** ![gdziuba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gdziuba/32/81398_2.png) [@gdziuba](https://discourse.nodered.org/u/gdziuba)\
**Post date:** [4 September 2024 15:14 UTC](https://discourse.nodered.org/t/write-statuscode-and-sourcetimestamp-to-an-opc-ua-server/90713/2 "2024-09-04T15:14:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![star-board](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@star-board](https://discourse.nodered.org/u/star-board)\
**Post date:** [4 September 2024 15:21 UTC](https://discourse.nodered.org/t/write-statuscode-and-sourcetimestamp-to-an-opc-ua-server/90713/3 "2024-09-04T15:21:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mikakaraila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikakaraila/32/37496_2.png) [@mikakaraila](https://discourse.nodered.org/u/mikakaraila)\
**Post date:** [15 October 2024 08:28 UTC](https://discourse.nodered.org/t/write-statuscode-and-sourcetimestamp-to-an-opc-ua-server/90713/4 "2024-10-15T08:28:42Z")

</div>

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

```auto
 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
            })
          };

```

---

<div class="post-metadata">

**Author:** ![mikakaraila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikakaraila/32/37496_2.png) [@mikakaraila](https://discourse.nodered.org/u/mikakaraila)\
**Post date:** [15 October 2024 08:32 UTC](https://discourse.nodered.org/t/write-statuscode-and-sourcetimestamp-to-an-opc-ua-server/90713/5 "2024-10-15T08:32:04Z")

</div>

Some lines below:

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

```

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

---

<div class="post-metadata">

**Author:** ![star-board](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@star-board](https://discourse.nodered.org/u/star-board)\
**Post date:** [18 October 2024 08:05 UTC](https://discourse.nodered.org/t/write-statuscode-and-sourcetimestamp-to-an-opc-ua-server/90713/6 "2024-10-18T08:05:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 November 2024 08:06 UTC](https://discourse.nodered.org/t/write-statuscode-and-sourcetimestamp-to-an-opc-ua-server/90713/7 "2024-11-01T08:06:29Z")

</div>

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