# Unable to write values to the OPC UA server

**URL:** https://discourse.nodered.org/t/unable-to-write-values-to-the-opc-ua-server/79503
**Category:** General
**Created:** [30 June 2023 09:38 UTC](https://discourse.nodered.org/t/unable-to-write-values-to-the-opc-ua-server/79503 "2023-06-30T09:38:40Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![SK\_30](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sk_30/32/80998_2.png) [@SK\_30](https://discourse.nodered.org/u/SK_30)
#### Post date: [30 June 2023 09:38 UTC](https://discourse.nodered.org/t/unable-to-write-values-to-the-opc-ua-server/79503/1 "2023-06-30T09:38:40Z")

</div>

Hello,

I am using node-red-contrib-iiot-opcua node. I have created a server in my flow and some variables.  
I am receiving a boolean value from PLC, I want to write this value in my OPC UA server in node-red.  
I have added a function block in between to send relevant data to the write node. It gives me an error. I am relatively new to node-red. Can somebody help me to tackle this problem? Thank you!

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/2/828a79323d5884ea65ec048492c85e1beafc276f.png)  
 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7f4cd3c14d36141f5ae13382fc8ea53f060494d3.png)

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [30 June 2023 10:13 UTC](https://discourse.nodered.org/t/unable-to-write-values-to-the-opc-ua-server/79503/2 "2023-06-30T10:13:25Z")

</div>

Hello @SK_30 and welcome to the forum.

Use a debug node to show msg.payload as it leaves the function node.  
I suspect it will not look exactly as you intend, though I don't see any problem with msg.payload.injectType specifically.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [30 June 2023 10:13 UTC](https://discourse.nodered.org/t/unable-to-write-values-to-the-opc-ua-server/79503/3 "2023-06-30T10:13:46Z")

</div>

Since `msg.payload` is a boolean, you cannot start setting sub properties like it is an object.

I would have shown you how but since you posted a picture of the code, I am not about to re-write it

_(TIP: Always post code and logs as text - so people helping you out can copy/update/paste a fix for you)._

  

You will need something like

```auto
msg.payload = {
   other_properties: 'other values',
   value: msg.payload 
}
return msg

```

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [30 June 2023 10:14 UTC](https://discourse.nodered.org/t/unable-to-write-values-to-the-opc-ua-server/79503/4 "2023-06-30T10:14:43Z")

</div>

Oh good catch, wish I'd spotted that!

---

<div class="post-metadata">

### Author: ![SK\_30](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sk_30/32/80998_2.png) [@SK\_30](https://discourse.nodered.org/u/SK_30)
#### Post date: [30 June 2023 10:48 UTC](https://discourse.nodered.org/t/unable-to-write-values-to-the-opc-ua-server/79503/5 "2023-06-30T10:48:49Z")

</div>

Thank you for your quick response,  
I made changes according to your example. It shows me the following error in the 'write' node.

`Error: serviceResult = BadNothingToDo (0x800f0000)`

Following is my new code in function node.

```auto
msg.payload = {
    nodetype: 'inject',
    injectType: 'write',
    addressSpaceValues: 'ns=1;s=ExitStation',
    valuesToWrite: msg.payload
}
return msg;

```

The write node requires the following data as input.

```auto
Input:
payload (value to write one or all)
topic
addressSpaceItems or nodesToWrite (Array of Node-Ids)
nodetype (inject)
injectType (write)
valuesToWrite (Array of values or objects to write individual)

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [30 June 2023 11:01 UTC](https://discourse.nodered.org/t/unable-to-write-values-to-the-opc-ua-server/79503/6 "2023-06-30T11:01:43Z")

</div>

> [@SK\_30](#):
>
> Following is my new code in function node.
> 
> ```auto
> msg.payload = {
> nodetype: 'inject',
> injectType: 'write',
> addressSpaceValues: 'ns=1;s=ExitStation',
> valuesToWrite: msg.payload
> }
> return msg;
> 
> ```
> 
> The write node requires the following data as input.
> 
> ```auto
> Input:
> payload (value to write one or all)
> topic
> addressSpaceItems or nodesToWrite (Array of Node-Ids)
> nodetype (inject)
> injectType (write)
> valuesToWrite (Array of values or objects to write individual)
> 
> ```

If the node needs the above ☝ format - why are you setting it up differently?

try...

```auto
msg.topic = ""
msg.nodetype ="inject"
msg.injectType = "write"
msg.addressSpaceItems = [
    {"name":"","nodeId":"ns=1;s=ExitStation","datatypeName":"Boolean"}
]
	
msg.valuesToWrite = [
    msg.payload
]
return msg;

```

Untested: this was formed from info in this post: [Issue with opcua and s7 -\> OPCServer in node red with many tags](https://discourse.nodered.org/t/issue-with-opcua-and-s7-opcserver-in-node-red-with-many-tags/58920)

* * *

Lastly, have you checked out the built in examples?

ctrl-i → `examples`

---

<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: [13 August 2023 17:18 UTC](https://discourse.nodered.org/t/unable-to-write-values-to-the-opc-ua-server/79503/7 "2023-08-13T17:18:42Z")

</div>

Simple error: there is no value to write. Value must match to valid value DataType in this case true/false.  
Status code tells you "Nothing to Do".

---

<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: [12 October 2023 17:18 UTC](https://discourse.nodered.org/t/unable-to-write-values-to-the-opc-ua-server/79503/8 "2023-10-12T17:18:47Z")

</div>

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