# Node red OPCUA write through kepserver

**URL:** <https://discourse.nodered.org/t/node-red-opcua-write-through-kepserver/86589>\
**Category:** General\
**Created:** [20 March 2024 08:15 UTC](https://discourse.nodered.org/t/node-red-opcua-write-through-kepserver/86589 "2024-03-20T08:15:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ect\_09](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@ect\_09](https://discourse.nodered.org/u/ect_09)\
**Post date:** [20 March 2024 08:15 UTC](https://discourse.nodered.org/t/node-red-opcua-write-through-kepserver/86589/1 "2024-03-20T08:15:15Z")

</div>

Hi,  
I am new to forum, below is the code for node red flow to write the value to opc client.

the purpose is to first read the setpoint and then change the set point in it by increasing/decreasing arrow. but issue is its not working and showing error "the value supplied for the attribute is not of same type as attribute value"

Please help me.

```auto
[
    {
        "id": "34b4a94d7b272c32",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "6d8a13ae2c065bfd",
        "type": "inject",
        "z": "34b4a94d7b272c32",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "num",
        "x": 170,
        "y": 180,
        "wires": [
            [
                "433e18ac38e77f47"
            ]
        ]
    },
    {
        "id": "433e18ac38e77f47",
        "type": "OpcUa-Item",
        "z": "34b4a94d7b272c32",
        "item": "ns=2;s=Q02.D1.Dev01.d366",
        "datatype": "Int32",
        "value": "",
        "name": "Read",
        "x": 370,
        "y": 180,
        "wires": [
            [
                "256e2c11a56705c2"
            ]
        ]
    },
    {
        "id": "256e2c11a56705c2",
        "type": "function",
        "z": "34b4a94d7b272c32",
        "name": "function 9",
        "func": "msg.payload = msg.payload / 10.00;\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 180,
        "wires": [
            [
                "24205a69fe8b70e9"
            ]
        ]
    },
    {
        "id": "24205a69fe8b70e9",
        "type": "ui_numeric",
        "z": "34b4a94d7b272c32",
        "name": "",
        "label": "numeric",
        "tooltip": "",
        "group": "d783cb980c3979fc",
        "order": 40,
        "width": 0,
        "height": 0,
        "wrap": false,
        "passthru": true,
        "topic": "",
        "topicType": "str",
        "format": "{{value}}",
        "min": 0,
        "max": "100",
        "step": 1,
        "className": "",
        "x": 780,
        "y": 180,
        "wires": [
            [
                "c38635f0199e45bd"
            ]
        ]
    },
    {
        "id": "c38635f0199e45bd",
        "type": "function",
        "z": "34b4a94d7b272c32",
        "name": "function 10",
        "func": "msg.payload = msg.payload / 10.00;\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 980,
        "y": 180,
        "wires": [
            [
                "78cc844f987230e6"
            ]
        ]
    },
    {
        "id": "53e854383a6c8484",
        "type": "OpcUa-Client",
        "z": "34b4a94d7b272c32",
        "endpoint": "274c4b3760e8209a",
        "action": "write",
        "deadbandvalue": "",
        "time": "",
        "certificate": "n",
        "localfile": "",
        "localkeyfile": "",
        "useTransport": false,
        "maxChunkCount": "1",
        "maxMessageSize": "8192",
        "receiveBufferSize": "8192",
        "sendBufferSize": "8192",
        "name": "",
        "x": 680,
        "y": 340,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "78cc844f987230e6",
        "type": "OpcUa-Item",
        "z": "34b4a94d7b272c32",
        "item": "ns=2;s=Q02.D1.Dev01.d366",
        "datatype": "Int32",
        "value": "",
        "name": "write",
        "x": 430,
        "y": 340,
        "wires": [
            [
                "53e854383a6c8484"
            ]
        ]
    },
    {
        "id": "d783cb980c3979fc",
        "type": "ui_group",
        "name": "Test Demo",
        "tab": "0449b3b1fea99d52",
        "order": 1,
        "disp": true,
        "width": 21,
        "collapse": false,
        "className": ""
    },
    {
        "id": "274c4b3760e8209a",
        "type": "OpcUa-Endpoint",
        "endpoint": "opc.tcp://127.0.0.1:49320",
        "secpol": "None",
        "secmode": "None",
        "none": true,
        "login": false,
        "usercert": false,
        "usercertificate": "",
        "userprivatekey": ""
    },
    {
        "id": "0449b3b1fea99d52",
        "type": "ui_tab",
        "name": "BALL MILL HMI",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [20 March 2024 08:55 UTC](https://discourse.nodered.org/t/node-red-opcua-write-through-kepserver/86589/2 "2024-03-20T08:55:23Z")

</div>

Just to let you know I am not a OPCUA user.

Looking at your flow json and function code  
You are trying to save a INT32 data type, but the function code can produce a float, i.e 9/10 = 0.9. So you get error data type is not the same as value supplied.  
Try `msg.payload = Math.round(msg.payload / 10);` to round the supplied value to an Integer.

There are OPCUA users here they may have a better answer for you.

---

<div class="post-metadata">

**Author:** ![ect\_09](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@ect\_09](https://discourse.nodered.org/u/ect_09)\
**Post date:** [20 March 2024 09:14 UTC](https://discourse.nodered.org/t/node-red-opcua-write-through-kepserver/86589/3 "2024-03-20T09:14:37Z")

</div>

Thank you for your reply.  
I tried the above advise but it didn't work. Though its a small thing but i am not able to solve this,

I appreciate if someone can guide. If you need any further input, feel free to write.

Thanks...!

---

<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:** [18 June 2024 09:14 UTC](https://discourse.nodered.org/t/node-red-opcua-write-through-kepserver/86589/4 "2024-06-18T09:14:38Z")

</div>

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