Unable to write values to the OPC UA server

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!


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.

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

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

Oh good catch, wish I'd spotted that!

1 Like

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.

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.

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 :point_up: format - why are you setting it up differently?

try...

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


Lastly, have you checked out the built in examples?

ctrl-i → examples

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".

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