Node red OPCUA write through kepserver

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.

[
    {
        "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
    }
]

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.

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

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