# Write string value to OPC UA Server - contrib-opcua-server

**URL:** <https://discourse.nodered.org/t/write-string-value-to-opc-ua-server-contrib-opcua-server/63539>\
**Category:** Industrial\
**Created:** [7 June 2022 00:24 UTC](https://discourse.nodered.org/t/write-string-value-to-opc-ua-server-contrib-opcua-server/63539 "2022-06-07T00:24:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![atravel](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@atravel](https://discourse.nodered.org/u/atravel)\
**Post date:** [7 June 2022 00:24 UTC](https://discourse.nodered.org/t/write-string-value-to-opc-ua-server-contrib-opcua-server/63539/1 "2022-06-07T00:24:13Z")

</div>

Hello,

I'm trying to let a Client node write a value to a variable of the address space in my OPC UA server.

As long as the variable in the Server is specified as Integer, Double, etc. everything works fine. I can write and read the variable with a Client without any problems.

However, if I specify the variable as string, the following happens:

1. Reading the initialized value - OK
2. Writing new value - two messages from Client node:

> "Counter: Second set value by Input b"

> "Counter: Payload value, setting value to [{"\_msgid":"1","payload":"2","topic":"3","datatype":"4","browseName":"5"},"385fde3613f0f306","b","ns=1;s=count","String","Counter"]"

with "b" from the first statement being the value I wanted to write

1. Trying to read the value again - message from Client node

> "Client node error on: error: [" error at active reading: serviceResult = BadInternalError (0x80020000)"]"

My flow:

```auto
[
    {
        "id": "056d99c0561209fd",
        "type": "OpcUa-Client",
        "z": "4571363c02da6541",
        "endpoint": "d6af2ba71bd244b8",
        "action": "read",
        "deadbandtype": "a",
        "deadbandvalue": 1,
        "time": "1",
        "timeUnit": "s",
        "certificate": "n",
        "localfile": "",
        "localkeyfile": "",
        "securitymode": "None",
        "securitypolicy": "None",
        "folderName4PKI": "",
        "name": "",
        "x": 840,
        "y": 600,
        "wires": [
            [
                "e80207e73aea2dd9"
            ]
        ]
    },
    {
        "id": "e568aa60eb783cc1",
        "type": "OpcUa-Item",
        "z": "4571363c02da6541",
        "item": "ns=1;s=count",
        "datatype": "String",
        "value": "",
        "name": "Counter",
        "x": 620,
        "y": 600,
        "wires": [
            [
                "056d99c0561209fd"
            ]
        ],
        "icon": "node-red-contrib-opcua-server/icon.png"
    },
    {
        "id": "cdba768a51f2843e",
        "type": "inject",
        "z": "4571363c02da6541",
        "name": "Add item",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "x": 440,
        "y": 600,
        "wires": [
            [
                "e568aa60eb783cc1"
            ]
        ]
    },
    {
        "id": "e80207e73aea2dd9",
        "type": "debug",
        "z": "4571363c02da6541",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1050,
        "y": 600,
        "wires": []
    },
    {
        "id": "ca3305551b7a3a9b",
        "type": "OpcUa-Item",
        "z": "4571363c02da6541",
        "item": "ns=1;s=count",
        "datatype": "String",
        "value": "",
        "name": "Counter",
        "x": 640,
        "y": 500,
        "wires": [
            [
                "a85637302bde4a56"
            ]
        ],
        "icon": "node-red-contrib-opcua-server/icon.png"
    },
    {
        "id": "a85637302bde4a56",
        "type": "OpcUa-Client",
        "z": "4571363c02da6541",
        "endpoint": "d6af2ba71bd244b8",
        "action": "write",
        "deadbandtype": "a",
        "deadbandvalue": 1,
        "time": 10,
        "timeUnit": "s",
        "certificate": "n",
        "localfile": "",
        "localkeyfile": "",
        "securitymode": "None",
        "securitypolicy": "None",
        "folderName4PKI": "",
        "name": "",
        "x": 860,
        "y": 500,
        "wires": [
            [
                "7bc9af43b5d78cc1"
            ]
        ]
    },
    {
        "id": "e4253eb280cffc69",
        "type": "inject",
        "z": "4571363c02da6541",
        "name": "Add item",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "b",
        "payloadType": "str",
        "x": 440,
        "y": 500,
        "wires": [
            [
                "ca3305551b7a3a9b"
            ]
        ]
    },
    {
        "id": "7bc9af43b5d78cc1",
        "type": "debug",
        "z": "4571363c02da6541",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1050,
        "y": 500,
        "wires": []
    },
    {
        "id": "7bcb25894b455949",
        "type": "opcua-compact-server",
        "z": "4571363c02da6541",
        "port": "4840",
        "endpoint": "",
        "productUri": "",
        "acceptExternalCommands": true,
        "maxAllowedSessionNumber": 10,
        "maxConnectionsPerEndpoint": 10,
        "maxAllowedSubscriptionNumber": 100,
        "alternateHostname": "",
        "name": "",
        "showStatusActivities": false,
        "showErrors": false,
        "allowAnonymous": true,
        "individualCerts": false,
        "isAuditing": false,
        "serverDiscovery": true,
        "users": [],
        "xmlsetsOPCUA": [],
        "publicCertificateFile": "",
        "privateCertificateFile": "",
        "registerServerMethod": 1,
        "discoveryServerEndpointUrl": "",
        "capabilitiesForMDNS": "",
        "maxNodesPerRead": 1000,
        "maxNodesPerWrite": 1000,
        "maxNodesPerHistoryReadData": 100,
        "maxNodesPerBrowse": 3000,
        "maxBrowseContinuationPoints": 10,
        "maxHistoryContinuationPoints": 10,
        "delayToInit": 1000,
        "delayToClose": 200,
        "serverShutdownTimeout": 100,
        "addressSpaceScript": "function constructAlarmAddressSpace(server, addressSpace, eventObjects, done) {\n\n const opcua = coreServer.choreCompact.opcua;\n const LocalizedText = opcua.LocalizedText;\n const namespace = addressSpace.getOwnNamespace();\n \n const Variant = opcua.Variant;\n const DataType = opcua.DataType;\n const DataValue = opcua.DataValue;\n \n let count=\"a\";\n \n coreServer.debugLog(\"init dynamic address space\");\n const rootFolder = addressSpace.findNode(\"RootFolder\");\n \n node.warn(\"construct new address space for OPC UA\");\n \n const HBFG = namespace.addFolder(rootFolder.objects, {\n \"browseName\":\"HBFG\"\n });\n \n const Tanks = namespace.addFolder(HBFG,{ \"browseName\":\"Tanks\" });\n \n \nnamespace.addVariable({\n \"componentof\": Tanks,\n \"nodeId\": \"ns=1;s=count\",\n \"browseName\":\"Counter\",\n \"dataType\": \"String\",\n \"value\": {\n \"get\": function() {\n return new Variant({\n \"dataType\": DataType.String,\n \"value\": count\n });\n },\n \"set\": function(variant) {\n count=parseFloat(variant.value);\n return opcua.StatusCodes.Good;\n }\n }\n });\n \n\n coreServer.debugLog(\"create dynamic address space done\");\n node.warn(\"construction of new address space for OPC UA done\");\n \n done();\n}\n",
        "x": 660,
        "y": 380,
        "wires": []
    },
    {
        "id": "d6af2ba71bd244b8",
        "type": "OpcUa-Endpoint",
        "endpoint": "opc.tcp://localhost:4840",
        "secpol": "None",
        "secmode": "None",
        "none": false,
        "login": false,
        "usercert": false,
        "usercertificate": "",
        "userprivatekey": ""
    }
]

```

Does anybody know what I'm doing wrong? I'm relatively new to OPC UA and would appreciate the help. Thank you!

--edit: forgot to remove the "parsefloat()" in the set command. I can read the variable now. The issue with the writing client is still there though

---

<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:** [20 June 2022 16:20 UTC](https://discourse.nodered.org/t/write-string-value-to-opc-ua-server-contrib-opcua-server/63539/2 "2022-06-20T16:20:07Z")

</div>

Look examples folder and OPCUA-TEST-NODES.json Tab Write:

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

Item-node:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d0697eff0b2b1fd235deedb7770b3203f2e4a657.png)

---

<div class="post-metadata">

**Author:** ![MrSharper](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsharper/32/65594_2.png) [@MrSharper](https://discourse.nodered.org/u/MrSharper)\
**Post date:** [2 August 2022 17:43 UTC](https://discourse.nodered.org/t/write-string-value-to-opc-ua-server-contrib-opcua-server/63539/3 "2022-08-02T17:43:12Z")

</div>

I am getting the same warnings, but the code executes as expected with correct values written. This warning is showing in version 0.2.284. I went back to 0.2.248 and nothing shows there with the same nodes.

---

<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 October 2022 17:43 UTC](https://discourse.nodered.org/t/write-string-value-to-opc-ua-server-contrib-opcua-server/63539/4 "2022-10-01T17:43:49Z")

</div>

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