How to convert analog input value to int16 to forward with opc ua

Hi,
I am trying to send Temperature Value from analog Input of Galileo Board with opcua to server. My Problem is that I get error if I connect function Block to opcua node.
Could Anyone help ms to find my fault?

[
    {
        "id": "59be47a5.7dac58",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "7b527f17.f4e1d8",
        "type": "OpcUa-Client",
        "z": "59be47a5.7dac58",
        "endpoint": "ccbe9b7b.6226d8",
        "action": "write",
        "deadbandtype": "a",
        "deadbandvalue": 1,
        "time": 10,
        "timeUnit": "s",
        "certificate": "n",
        "localfile": "",
        "securitymode": "None",
        "securitypolicy": "None",
        "name": "",
        "x": 980,
        "y": 200,
        "wires": [
            [
                "c74189db.84ba58"
            ]
        ]
    },
    {
        "id": "c74189db.84ba58",
        "type": "debug",
        "z": "59be47a5.7dac58",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1210,
        "y": 200,
        "wires": []
    },
    {
        "id": "68d7416f.873218",
        "type": "range",
        "z": "59be47a5.7dac58",
        "minin": "0",
        "maxin": "1023",
        "minout": "0",
        "maxout": "100",
        "action": "scale",
        "round": true,
        "property": "payload",
        "name": "",
        "x": 420,
        "y": 220,
        "wires": [
            [
                "3f8887c8.4e6b58",
                "83ed62e1.6af1b"
            ]
        ]
    },
    {
        "id": "a72a7ef4.81f088",
        "type": "mraa-gpio-ain",
        "z": "59be47a5.7dac58",
        "name": "Raumtemperatur",
        "pin": "0",
        "interval": "1000",
        "x": 170,
        "y": 220,
        "wires": [
            [
                "68d7416f.873218"
            ]
        ]
    },
    {
        "id": "ceac519a.5fa0d8",
        "type": "OpcUa-Item",
        "z": "59be47a5.7dac58",
        "item": "n=2;s=Tag18",
        "datatype": "Int16",
        "value": "number",
        "name": "",
        "x": 770,
        "y": 200,
        "wires": [
            [
                "7b527f17.f4e1d8"
            ]
        ]
    },
    {
        "id": "3f8887c8.4e6b58",
        "type": "debug",
        "z": "59be47a5.7dac58",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 380,
        "y": 300,
        "wires": []
    },
    {
        "id": "2196bf54.2ea58",
        "type": "debug",
        "z": "59be47a5.7dac58",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 760,
        "y": 320,
        "wires": []
    },
    {
        "id": "83ed62e1.6af1b",
        "type": "function",
        "z": "59be47a5.7dac58",
        "name": "",
        "func": "var temp = Number(msg.payload);\nmsg = parseFloat(temp).toFixed(0);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 610,
        "y": 220,
        "wires": [
            [
                "ceac519a.5fa0d8"
            ]
        ]
    },
    {
        "id": "ccbe9b7b.6226d8",
        "type": "OpcUa-Endpoint",
        "z": "",
        "endpoint": "opc.tcp://192.168.2.202:55383/IntegrationObjects/ServerSimulator_IOT2040",
        "secpol": "None",
        "secmode": "None",
        "login": false
    }
]

Thx a lot
DerD

In your function you have this...

var temp = Number(msg.payload);
msg = parseFloat(temp).toFixed(0);
return msg;

If you read the function node built in help, you will see you MUST return an object (usually the same msg that was sent in)

image

example...

var temp = Number(msg.payload);
msg.payload = parseFloat(temp).toFixed(0);
return msg;

NOTES

  • I dont use OPCUA node so you may need to set the msg.payload to something other than a number or string (read that nodes built in help)
  • parseFloat(temp).toFixed(0) will return a string not a floating point number - this may be incorrect. Try parseFloat(temp.toFixed(0)) instead.

I think that is the same as
Math.round(temp)

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