# Modbus TCP float to value

**URL:** <https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393>\
**Category:** General\
**Created:** [15 February 2022 14:18 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393 "2022-02-15T14:18:27Z")\
**Posts on this page:** 17\
**Page:** 2

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2022 08:53 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/21 "2022-02-16T08:53:43Z")

</div>

can you set your modbus to read from **Register 0** for **Length 16**

Then use the "Copy Value" button in the debug sidebar to copy the exact payload - post that in a reply please?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cf303e036a665451cbdb84ecca329abf3a9a9a79.png)

* * *

I have managed to get 237 from your earlier data but i suspect the data is 2 byte off because I had to SWAP16 and use float LE function - this is in contradiction to your manual.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/5/1550d231369be879d92c552da8329e9c95f1fd42.png)

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 09:03 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/22 "2022-02-16T09:03:18Z")

</div>

[19017,17258]

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2022 09:28 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/23 "2022-02-16T09:28:02Z")

</div>

that is not 16 long & it is not a copy of the payload like I asked otherwise it would look something like...

```auto
{
  "data": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],
  "buffer": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
}

```

> [@Steve-Mcl](#):
>
> use the "Copy Value" button in the debug sidebar to copy the exact payload - post that in a reply please?
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cf303e036a665451cbdb84ecca329abf3a9a9a79.png)

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 09:42 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/24 "2022-02-16T09:42:24Z")

</div>

I don't get that values, can you maybe send your script?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2022 09:45 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/25 "2022-02-16T09:45:27Z")

</div>

I don't have any script. Did you set modbus read to Reg 0 and the Length to 16?

Do you have debug node attached to modbus read?

When you read modbus data, do you get entry in debug sidebar?

Use the copy value button as I have shown.

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 09:51 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/26 "2022-02-16T09:51:59Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0fd4851da8f1fd12ed3eae687b7bd60d567da98a.png)  
this is what I have

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2022 10:06 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/27 "2022-02-16T10:06:13Z")

</div>

You haven't set the modbus node to read more items. It's still set to read 2 items.

Can you please set the register to 0 and the length to 16 and capture the data as I explained.

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 10:14 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/28 "2022-02-16T10:14:25Z")

</div>

[47513,17255,44234,17255,43211,15956,49509,15873,6404,16006,39183,15947,54165,17255,50869,17255]

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [16 February 2022 11:07 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/29 "2022-02-16T11:07:06Z")

</div>

Milan .. also set your Debug node (that is wired to Modbus node) to **complete message** in order to see and more easily copy the value of the buffer which should be in `msg.responseBuffer.buffer`

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e60d3f4332bd3490f294b0ca34770c41d14add44.png)

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 12:19 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/30 "2022-02-16T12:19:35Z")

</div>

{"topic":"polling","payload":[1432,17256,64922,17255,63669,15958,46993,15878,8440,16007,35711,15951,8520,17256,6466,17256],"responseBuffer":{"data":[1432,17256,64922,17255,63669,15958,46993,15878,8440,16007,35711,15951,8520,17256,6466,17256],"buffer":[5,152,67,104,253,154,67,103,248,181,62,86,183,145,62,6,32,248,62,135,139,127,62,79,33,72,67,104,25,66,67,104]},"input":{"topic":"polling","from":"","payload":{"unitid":"61","fc":3,"address":"0","quantity":"16","messageId":"620cebbcc893dad1cfa8649e"},"queueLengthByUnitId":{"unitId":61,"queueLength":0},"queueUnitId":61,"unitId":61},"sendingNodeId":"7d810a3e3e7d705f","\_msgid":"a9d5b88e2ddf90b5"}

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [16 February 2022 12:48 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/31 "2022-02-16T12:48:58Z")

</div>

I get this:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/a/fa323f2c6a5451f75a6b12933889246d62246e54.png)

```auto
[
    {
        "id": "579d064f73357cb4",
        "type": "inject",
        "z": "9fc0f809.f00518",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[5,152,67,104,253,154,67,103,248,181,62,86,183,145,62,6,32,248,62,135,139,127,62,79,33,72,67,104,25,66,67,104]",
        "payloadType": "bin",
        "x": 330,
        "y": 1160,
        "wires": [
            [
                "bbd8805693f01e58"
            ]
        ]
    },
    {
        "id": "bbd8805693f01e58",
        "type": "buffer-parser",
        "z": "9fc0f809.f00518",
        "name": "test",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "floatle",
                "name": "item1",
                "offset": 0,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "floatle",
                "name": "item2",
                "offset": 4,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "floatle",
                "name": "item3",
                "offset": 8,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "floatle",
                "name": "item4",
                "offset": 12,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "floatle",
                "name": "item5",
                "offset": 16,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "floatle",
                "name": "item6",
                "offset": 20,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "floatle",
                "name": "item7",
                "offset": 24,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "floatle",
                "name": "item8",
                "offset": 28,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "swap16",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "output",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 450,
        "y": 1160,
        "wires": [
            [
                "6ac769f038435cd4"
            ]
        ]
    },
    {
        "id": "6ac769f038435cd4",
        "type": "debug",
        "z": "9fc0f809.f00518",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 590,
        "y": 1160,
        "wires": []
    }
]

```

you would have gotten this too if you used my example flow: [Modbus TCP float to value - #8 by Becker](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/8)

---

<div class="post-metadata">

**Author:** ![Milanovic](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Milanovic](https://discourse.nodered.org/u/Milanovic)\
**Post date:** [16 February 2022 13:06 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/32 "2022-02-16T13:06:49Z")

</div>

How did you do that?  
Which node did you use and which settings?

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [16 February 2022 13:21 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/33 "2022-02-16T13:21:41Z")

</div>

copy&paste my last example and test yourself with live data

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 February 2022 14:06 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/34 "2022-02-16T14:06:39Z")

</div>

In case you don't know then you can import a flow from here using the menu Import feature.  
If you didn't know that then I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2022 15:07 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/35 "2022-02-16T15:07:31Z")

</div>

that was the data I needed.

So, my point was to demonstrate how you get all the values in one go and convert them to the right format.

Demo...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a8ecd49dfa2d38845aca14c06be36123a7829160.png)

Demo flow (import using CTRL+I)

```auto
[{"id":"36222b89d1539d62","type":"inject","z":"150d20998fc7fe72","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1980,"y":200,"wires":[["52e1a776e983b3f8"]]},{"id":"52e1a776e983b3f8","type":"function","z":"150d20998fc7fe72","name":"fake modbus data","func":"\nmsg = {\n \"topic\": \"polling\",\n \"payload\": [\n 1432,\n 17256,\n 64922,\n 17255,\n 63669,\n 15958,\n 46993,\n 15878,\n 8440,\n 16007,\n 35711,\n 15951,\n 8520,\n 17256,\n 6466,\n 17256\n],\n \"responseBuffer\": {\n \"data\": [\n 1432,\n 17256,\n 64922,\n 17255,\n 63669,\n 15958,\n 46993,\n 15878,\n 8440,\n 16007,\n 35711,\n 15951,\n 8520,\n 17256,\n 6466,\n 17256\n],\n \"buffer\": Buffer.from([\n 5,\n 152,\n 67,\n 104,\n 253,\n 154,\n 67,\n 103,\n 248,\n 181,\n 62,\n 86,\n 183,\n 145,\n 62,\n 6,\n 32,\n 248,\n 62,\n 135,\n 139,\n 127,\n 62,\n 79,\n 33,\n 72,\n 67,\n 104,\n 25,\n 66,\n 67,\n 104\n])\n },\n \"input\": {\n \"topic\": \"polling\",\n \"from\": \"\",\n \"payload\": {\n \"unitid\": \"61\",\n \"fc\": 3,\n \"address\": \"0\",\n \"quantity\": \"16\",\n \"messageId\": \"620cebbcc893dad1cfa8649e\"\n },\n \"queueLengthByUnitId\": {\n \"unitId\": 61,\n \"queueLength\": 0\n },\n \"queueUnitId\": 61,\n \"unitId\": 61\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2055.5555572509766,"y":245.55552864074707,"wires":[["a80bc70fb3ddbe19","c53f4232eb527410"]]},{"id":"a80bc70fb3ddbe19","type":"debug","z":"150d20998fc7fe72","name":"modbus data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2255.5555572509766,"y":245.55552864074707,"wires":[]},{"id":"c53f4232eb527410","type":"buffer-parser","z":"150d20998fc7fe72","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatle","name":"L1_RMS_V","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatle","name":"L1_RMS_FV","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatle","name":"L2_RMS_V","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatle","name":"L2_RMS_FV","offset":12,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatle","name":"L3_RMS_V","offset":16,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatle","name":"L3_RMS_FV","offset":20,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatle","name":"L1L2_RMS_V","offset":24,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatle","name":"L1L2_RMS_FV","offset":28,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"swap16","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":2075.5555572509766,"y":325.55552864074707,"wires":[["70cca1b71057c8e0"]]},{"id":"70cca1b71057c8e0","type":"debug","z":"150d20998fc7fe72","name":"parsed data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2255.5555572509766,"y":325.55552864074707,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [16 February 2022 20:10 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/36 "2022-02-16T20:10:03Z")

</div>

but the values are illogical... L1-L2 should be about 400V.  
🧐

---

<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:** [17 April 2022 20:10 UTC](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/37 "2022-04-17T20:10:59Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393.md?page=1)
