Node-Red Buffers- Integers and Floats

Version
Download 705
File Size 6.01 KB
File Count 1
Create Date July 9, 2019
Last Updated October 6, 2020
Download
or download free
[free_download_btn]

Description

Join out Email list and stay up to date
[email-subscribers-form id="1"]

Make a Contribution

pay-pal-buy-now

if you find this useful and would like to make a contribution, then you can do so by clicking here.

Categories & Tags

Similar Downloads

No related download found!
steve
Please rate? And use Comments to let me know more

2 comments

  1. Hello Steve,
    I am new to Node Red & trying to get the data from a gas flow meter. The data type is Float. I have tried few methods by searching the Web, Youtube. Here is the json file of the Flow.
    The problem is I am not getting the correct value of as in the register of the Modbus contrib read.
    The 8 bit buffer from the read data matches the value of the flowmeter register. But when I convert the value is not matching. Please help.
    The correct value is 1242298282-32Bit UInt, 2293227 – Float.
    Please Weld gas Total
    [
    {
    “id”: “cc95679c3902ed7a”,
    “type”: “tab”,
    “label”: “Paneling”,
    “disabled”: false,
    “info”: “”
    },
    {
    “id”: “11b428f717ac8283”,
    “type”: “modbus-read”,
    “z”: “cc95679c3902ed7a”,
    “name”: “WeldGasFlRt”,
    “topic”: “”,
    “showStatusActivities”: false,
    “logIOActivities”: false,
    “showErrors”: false,
    “unitid”: “1”,
    “dataType”: “HoldingRegister”,
    “adr”: “3”,
    “quantity”: “2”,
    “rate”: “1”,
    “rateUnit”: “m”,
    “delayOnStart”: false,
    “startDelayTime”: “”,
    “server”: “0fe5f962b71582e1”,
    “useIOFile”: false,
    “ioFile”: “”,
    “useIOForPayload”: false,
    “emptyMsgOnFail”: false,
    “x”: 130,
    “y”: 60,
    “wires”: [
    [
    “0157462b9f7cf4f8”,
    “e517639961f7ea91”
    ],
    []
    ]
    },
    {
    “id”: “0157462b9f7cf4f8”,
    “type”: “modbus-response”,
    “z”: “cc95679c3902ed7a”,
    “name”: “”,
    “registerShowMax”: 20,
    “x”: 330,
    “y”: 20,
    “wires”: []
    },
    {
    “id”: “e517639961f7ea91”,
    “type”: “function”,
    “z”: “cc95679c3902ed7a”,
    “name”: “Convert”,
    “func”: “msg.payload = (msg.payload[0]<<16 + msg.payload[1]);\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 300,
    "y": 80,
    "wires": [
    [
    "68b2a54d6d2251df"
    ]
    ]
    },
    {
    "id": "2be7479ff0f1d399",
    "type": "modbus-response",
    "z": "cc95679c3902ed7a",
    "name": "",
    "registerShowMax": 20,
    "x": 330,
    "y": 120,
    "wires": []
    },
    {
    "id": "3791f2a088c36ccc",
    "type": "modbus-read",
    "z": "cc95679c3902ed7a",
    "name": "WeldGasFlw",
    "topic": "",
    "showStatusActivities": false,
    "logIOActivities": false,
    "showErrors": false,
    "unitid": "1",
    "dataType": "HoldingRegister",
    "adr": "32",
    "quantity": "2",
    "rate": "10",
    "rateUnit": "s",
    "delayOnStart": false,
    "startDelayTime": "",
    "server": "0fe5f962b71582e1",
    "useIOFile": false,
    "ioFile": "",
    "useIOForPayload": false,
    "emptyMsgOnFail": false,
    "x": 130,
    "y": 160,
    "wires": [
    [
    "2be7479ff0f1d399"
    ],
    [
    "46410512aaf01603",
    "14f1d0cde6873538",
    "8c52ba9e407e1941"
    ]
    ]
    },
    {
    "id": "bfddfaae38d576b1",
    "type": "modbus-response",
    "z": "cc95679c3902ed7a",
    "name": "",
    "registerShowMax": 20,
    "x": 330,
    "y": 340,
    "wires": []
    },
    {
    "id": "75e596045590cdfe",
    "type": "modbus-read",
    "z": "cc95679c3902ed7a",
    "name": "PnlAirFlRt",
    "topic": "",
    "showStatusActivities": false,
    "logIOActivities": false,
    "showErrors": false,
    "unitid": "7",
    "dataType": "HoldingRegister",
    "adr": "33",
    "quantity": "2",
    "rate": "1",
    "rateUnit": "m",
    "delayOnStart": false,
    "startDelayTime": "",
    "server": "5416182ed1fd1208",
    "useIOFile": false,
    "ioFile": "",
    "useIOForPayload": false,
    "emptyMsgOnFail": false,
    "x": 120,
    "y": 380,
    "wires": [
    [
    "bfddfaae38d576b1",
    "03d62c18b4e27c4f"
    ],
    []
    ]
    },
    {
    "id": "03d62c18b4e27c4f",
    "type": "function",
    "z": "cc95679c3902ed7a",
    "name": "Convert",
    "func": "msg.payload = (msg.payload[0]/10);\nreturn msg;\n",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 300,
    "y": 400,
    "wires": [
    [
    "56bd67b6eb946b7f",
    "d7c6c271fd2f5d4d"
    ]
    ]
    },
    {
    "id": "a49f976292e55ad4",
    "type": "modbus-response",
    "z": "cc95679c3902ed7a",
    "name": "",
    "registerShowMax": 20,
    "x": 330,
    "y": 440,
    "wires": []
    },
    {
    "id": "f3894060ba13ae0d",
    "type": "modbus-read",
    "z": "cc95679c3902ed7a",
    "name": "PnlAirFlw",
    "topic": "",
    "showStatusActivities": false,
    "logIOActivities": false,
    "showErrors": false,
    "unitid": "7",
    "dataType": "HoldingRegister",
    "adr": "7",
    "quantity": "2",
    "rate": "5",
    "rateUnit": "m",
    "delayOnStart": false,
    "startDelayTime": "",
    "server": "5416182ed1fd1208",
    "useIOFile": false,
    "ioFile": "",
    "useIOForPayload": false,
    "emptyMsgOnFail": false,
    "x": 120,
    "y": 480,
    "wires": [
    [
    "a49f976292e55ad4"
    ],
    [
    "6d26a8cf5807e20f"
    ]
    ]
    },
    {
    "id": "6d26a8cf5807e20f",
    "type": "function",
    "z": "cc95679c3902ed7a",
    "name": "Convert",
    "func": "const buf = Buffer.from(msg.payload.buffer);\nconst value = buf.readUInt32BE();\nmsg.payload = value;\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 300,
    "y": 500,
    "wires": [
    [
    "c1f68a78ccb4b58d",
    "282120aedb513057"
    ]
    ]
    },
    {
    "id": "68b2a54d6d2251df",
    "type": "toFloat",
    "z": "cc95679c3902ed7a",
    "name": "",
    "toFixed": "2",
    "x": 490,
    "y": 80,
    "wires": [
    [
    "e31f2ab61cab6c2c",
    "190ccafc55fc1da8"
    ]
    ]
    },
    {
    "id": "6689235833f6b38c",
    "type": "influxdb out",
    "z": "cc95679c3902ed7a",
    "influxdb": "fa6f8066b6ecbcbe",
    "name": "FlowRate",
    "measurement": "WeldGas",
    "precision": "",
    "retentionPolicy": "",
    "database": "database",
    "precisionV18FluxV20": "ms",
    "retentionPolicyV18Flux": "",
    "org": "organisation",
    "bucket": "bucket",
    "x": 840,
    "y": 80,
    "wires": []
    },
    {
    "id": "e31f2ab61cab6c2c",
    "type": "debug",
    "z": "cc95679c3902ed7a",
    "name": "GasFlRt",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 820,
    "y": 40,
    "wires": []
    },
    {
    "id": "e8022ff8d3348d8a",
    "type": "influxdb out",
    "z": "cc95679c3902ed7a",
    "influxdb": "fa6f8066b6ecbcbe",
    "name": "FlowRate",
    "measurement": "Panel",
    "precision": "",
    "retentionPolicy": "",
    "database": "database",
    "precisionV18FluxV20": "ms",
    "retentionPolicyV18Flux": "",
    "org": "organisation",
    "bucket": "bucket",
    "x": 840,
    "y": 400,
    "wires": []
    },
    {
    "id": "281b70e454a3cae4",
    "type": "influxdb out",
    "z": "cc95679c3902ed7a",
    "influxdb": "01269350df8fd048",
    "name": "FlowTotal",
    "measurement": "Panel",
    "precision": "",
    "retentionPolicy": "",
    "database": "database",
    "precisionV18FluxV20": "ms",
    "retentionPolicyV18Flux": "",
    "org": "organisation",
    "bucket": "bucket",
    "x": 840,
    "y": 500,
    "wires": []
    },
    {
    "id": "56b9b1f3f661b365",
    "type": "influxdb out",
    "z": "cc95679c3902ed7a",
    "influxdb": "01269350df8fd048",
    "name": "FlowTotal",
    "measurement": "WeldGas",
    "precision": "",
    "retentionPolicy": "",
    "database": "database",
    "precisionV18FluxV20": "ms",
    "retentionPolicyV18Flux": "",
    "org": "organisation",
    "bucket": "bucket",
    "x": 840,
    "y": 140,
    "wires": []
    },
    {
    "id": "e61c2b3844e3776b",
    "type": "debug",
    "z": "cc95679c3902ed7a",
    "name": "GasFlow-Float",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 840,
    "y": 240,
    "wires": []
    },
    {
    "id": "56bd67b6eb946b7f",
    "type": "debug",
    "z": "cc95679c3902ed7a",
    "name": "PnlAirFlRt",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 820,
    "y": 360,
    "wires": []
    },
    {
    "id": "282120aedb513057",
    "type": "debug",
    "z": "cc95679c3902ed7a",
    "name": "PnlAirFlw",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 820,
    "y": 460,
    "wires": []
    },
    {
    "id": "190ccafc55fc1da8",
    "type": "function",
    "z": "cc95679c3902ed7a",
    "name": "Store",
    "func": "msg.payload = {\n data: \"WeldGas\",\n dataval:msg.payload\n };\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 670,
    "y": 80,
    "wires": [
    [
    "6689235833f6b38c"
    ]
    ]
    },
    {
    "id": "bb08745cbb0625b7",
    "type": "function",
    "z": "cc95679c3902ed7a",
    "name": "Store",
    "func": "msg.payload = {\n data: \"WeldGas\",\n dataval:msg.payload\n };\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 670,
    "y": 140,
    "wires": [
    [
    "56b9b1f3f661b365"
    ]
    ]
    },
    {
    "id": "c1f68a78ccb4b58d",
    "type": "function",
    "z": "cc95679c3902ed7a",
    "name": "Store",
    "func": "msg.payload = {\n data: \"Panel\",\n dataval:msg.payload\n };\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 670,
    "y": 500,
    "wires": [
    [
    "281b70e454a3cae4"
    ]
    ]
    },
    {
    "id": "d7c6c271fd2f5d4d",
    "type": "function",
    "z": "cc95679c3902ed7a",
    "name": "Store",
    "func": "msg.payload = {\n data: \"Panel\",\n dataval:msg.payload\n };\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 670,
    "y": 400,
    "wires": [
    [
    "e8022ff8d3348d8a"
    ]
    ]
    },
    {
    "id": "79c6e520d8431c40",
    "type": "debug",
    "z": "cc95679c3902ed7a",
    "name": "Convert1",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 820,
    "y": 200,
    "wires": []
    },
    {
    "id": "46410512aaf01603",
    "type": "function",
    "z": "cc95679c3902ed7a",
    "name": "Conv1",
    "func": "const buf = Buffer.from(msg.payload.buffer);\nvar val1 = buf.readUInt8(0);\nvar val2 = buf.readUInt8(1);\nvar val3 = buf.readUInt8(2);\nvar val4 = buf.readUInt8(3);\nvar Arrayval = [val1,val2,val3,val4];\nmsg.payload = Arrayval;\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 330,
    "y": 200,
    "wires": [
    [
    "79c6e520d8431c40"
    ]
    ]
    },
    {
    "id": "8c52ba9e407e1941",
    "type": "function",
    "z": "cc95679c3902ed7a",
    "name": "Conv2",
    "func": "const buf = Buffer.from(msg.payload.buffer);\nconst value = buf.readFloatBE();\nmsg.payload = value;\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 330,
    "y": 240,
    "wires": [
    [
    "e61c2b3844e3776b"
    ]
    ]
    },
    {
    "id": "14f1d0cde6873538",
    "type": "function",
    "z": "cc95679c3902ed7a",
    "name": "Conv3",
    "func": "const buf = Buffer.from(msg.payload.buffer);\nconst val1 = buf.readUInt8(0);\nconst val2 = buf.readUInt8(1);\nconst val3 = buf.readUInt8(2);\nconst val4 = buf.readUInt8(3);\nconst array1 = [val1<<8+val2];\nconst array2 = [val3<<8+val4];\nconst array = array2<<16 + array1;\n//const buf1 = array;\n//const value= buf.readFloatBE();\n//msg.payload = value;\nmsg.payload = array;\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 330,
    "y": 280,
    "wires": [
    [
    "7273c1f3a5752358"
    ]
    ]
    },
    {
    "id": "7273c1f3a5752358",
    "type": "debug",
    "z": "cc95679c3902ed7a",
    "name": "conv3",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 810,
    "y": 280,
    "wires": []
    },
    {
    "id": "0fe5f962b71582e1",
    "type": "modbus-client",
    "name": "Gas",
    "clienttype": "tcp",
    "bufferCommands": true,
    "stateLogEnabled": false,
    "queueLogEnabled": false,
    "tcpHost": "172.25.124.5",
    "tcpPort": "503",
    "tcpType": "DEFAULT",
    "serialPort": "/dev/ttyUSB",
    "serialType": "RTU-BUFFERD",
    "serialBaudrate": "9600",
    "serialDatabits": "8",
    "serialStopbits": "1",
    "serialParity": "none",
    "serialConnectionDelay": "100",
    "unit_id": "1",
    "commandDelay": "1",
    "clientTimeout": "1000",
    "reconnectOnTimeout": true,
    "reconnectTimeout": "2000",
    "parallelUnitIdsAllowed": true
    },
    {
    "id": "5416182ed1fd1208",
    "type": "modbus-client",
    "name": "Panl",
    "clienttype": "tcp",
    "bufferCommands": true,
    "stateLogEnabled": false,
    "queueLogEnabled": false,
    "tcpHost": "172.25.124.5",
    "tcpPort": "503",
    "tcpType": "DEFAULT",
    "serialPort": "/dev/ttyUSB",
    "serialType": "RTU-BUFFERD",
    "serialBaudrate": "9600",
    "serialDatabits": "8",
    "serialStopbits": "1",
    "serialParity": "none",
    "serialConnectionDelay": "100",
    "unit_id": "7",
    "commandDelay": "1",
    "clientTimeout": "1000",
    "reconnectOnTimeout": true,
    "reconnectTimeout": "2000",
    "parallelUnitIdsAllowed": true
    },
    {
    "id": "fa6f8066b6ecbcbe",
    "type": "influxdb",
    "hostname": "localhost",
    "port": "8086",
    "protocol": "http",
    "database": "FlowRate",
    "name": "FlowRate",
    "usetls": false,
    "tls": "",
    "influxdbVersion": "1.x",
    "url": "http://localhost:8086&quot;,
    "rejectUnauthorized": true
    },
    {
    "id": "01269350df8fd048",
    "type": "influxdb",
    "hostname": "localhost",
    "port": "8086",
    "protocol": "http",
    "database": "FlowCum",
    "name": "FlowTotal",
    "usetls": false,
    "tls": "",
    "influxdbVersion": "1.x",
    "url": "http://localhost:8086&quot;,
    "rejectUnauthorized": true
    }
    ]

    1. Hi
      Can you just send me the part with the register values. The Json file seems to have Javascript code jumbled with it.
      Just copy the buffer values from the debug node.
      Rgds
      Steve

Leave a Reply

Your email address will not be published. Required fields are marked *