# Convert ModBus Float32 to Dec

**URL:** https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975
**Category:** General
**Created:** [20 May 2021 12:08 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975 "2021-05-20T12:08:38Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![TheMisterA](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@TheMisterA](https://discourse.nodered.org/u/TheMisterA)
#### Post date: [20 May 2021 12:08 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/1 "2021-05-20T12:08:38Z")

</div>

Hi everyone,

I have a ModBus register of 2 words in Float32. I can't convert it to decimal to import it into InfluxDB.

I can't config the Buffer Parser...

Help please 🙂

---

<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: [20 May 2021 12:15 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/2 "2021-05-20T12:15:41Z")

</div>

- Attach a debug to the output of the modbus node
  - set the debug to "show complete message"

- copy the value using "copy value" button & paste it into a reply

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/2/229ad657b1041d008bd7531c6c677cb6df01305f.png)

---

<div class="post-metadata">

### Author: ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)
#### Post date: [20 May 2021 12:43 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/3 "2021-05-20T12:43:15Z")

</div>

Have a look to this link. Hope this helps.  
[https://www.unipi.technology/case\_study/sending-temperatures-from-unipi-gate-to-a-thingsboard-cloud-392](https://www.unipi.technology/case_study/sending-temperatures-from-unipi-gate-to-a-thingsboard-cloud-392)

---

<div class="post-metadata">

### Author: ![TheMisterA](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@TheMisterA](https://discourse.nodered.org/u/TheMisterA)
#### Post date: [20 May 2021 12:44 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/4 "2021-05-20T12:44:31Z")

</div>

Here :

> [1,65472]

Except that the Getter ModBus does not deal with Float32 I think because I have two arrays... I don't understand anything anymore...

![mod](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/947f0d63997d7900d196ad1ce814a3c2577bbf9a.png)

Generally, I have these values coming up when I should have 50Hz stable.

![zfgbrt](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b96d589d6d35fa07db072913970b41c83a1c214f.png)

---

<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: [20 May 2021 12:45 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/5 "2021-05-20T12:45:29Z")

</div>

I cant help if you dont do what I ask.

> [@Steve-Mcl](#):
>
> set the debug to "show complete message"

> [@Steve-Mcl](#):
>
> - copy the value using "copy value" button & paste it into a reply
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/2/229ad657b1041d008bd7531c6c677cb6df01305f.png)

---

<div class="post-metadata">

### Author: ![TheMisterA](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@TheMisterA](https://discourse.nodered.org/u/TheMisterA)
#### Post date: [20 May 2021 12:50 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/6 "2021-05-20T12:50:56Z")

</div>

That's what I did. There are two exits from the getter. Here they are:

First output :

> [6554,65472]

Second output :

> {"data":[6554,65472],"buffer":[25,154,255,192]}

---

<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: [20 May 2021 12:53 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/7 "2021-05-20T12:53:46Z")

</div>

Still no dice.

you are clicking the copy button while hovered on the `payload`

you need to click the button top most (the one by itself ) - like in the picture

---

<div class="post-metadata">

### Author: ![TheMisterA](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@TheMisterA](https://discourse.nodered.org/u/TheMisterA)
#### Post date: [20 May 2021 12:57 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/8 "2021-05-20T12:57:26Z")

</div>

Here you go 🙂  
Please forgive me, I am a novice....

First output :

> {"topic":"b08c8b03.0ab7d8","messageId":"60a65c428f2c51a43672ee90","payload":[9700,65472],"queueLengthByUnitId":{"unitId":2,"queueLength":0},"queueUnitId":2,"unitId":2,"modbusRequest":{"value":1621515330131,"unitid":"2","fc":3,"address":"3110","quantity":"2","messageId":"60a65c428f2c51a43672ee90"},"responseBuffer":{"data":[9700,65472],"buffer":[37,228,255,192]},"\_msgid":"587c6c81.d54b34"}

Second output :

> {"topic":"b08c8b03.0ab7d8","messageId":"60a65c428f2c51a43672ee90","payload":{"data":[9700,65472],"buffer":[37,228,255,192]},"queueLengthByUnitId":{"unitId":2,"queueLength":0},"queueUnitId":2,"unitId":2,"modbusRequest":{"value":1621515330131,"unitid":"2","fc":3,"address":"3110","quantity":"2","messageId":"60a65c428f2c51a43672ee90"},"values":[9700,65472],"\_msgid":"587c6c81.d54b34"}

---

<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: [20 May 2021 12:59 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/9 "2021-05-20T12:59:36Z")

</div>

So those values are weird. Do you have a manual - I suspect they are not straight forward float32 values.

also, what registers are you accessing in the modbus node (show picture)

---

<div class="post-metadata">

### Author: ![TheMisterA](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@TheMisterA](https://discourse.nodered.org/u/TheMisterA)
#### Post date: [20 May 2021 13:01 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/10 "2021-05-20T13:01:46Z")

</div>

Yes, it is an IEM 2150 counter : [https://download.schneider-electric.com/files?p\_enDocType=User+guide&p\_File\_Name=7EN02-0361-00.pdf&p\_Doc\_Ref=7EN02-0361](https://download.schneider-electric.com/files?p_enDocType=User+guide&p_File_Name=7EN02-0361-00.pdf&p_Doc_Ref=7EN02-0361)

I would like to know the 3054 register

---

<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: [20 May 2021 13:27 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/11 "2021-05-20T13:27:37Z")

</div>

- Set the modbus node to read from address 3000 & quantity to 77  
**This will return 77 INT16 values (154 `bytes`)**  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/dfd6a45571a01855df44ab5faaf2a6a9c475d107.png)

- Add the below buffer parser (ctrl+i) to your flow and attach it to the top output  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/5/65468e3e7b25e9add7e18017a310b95198dabac9.png)

What this will do is ...

- modbus will return an array of 77 INT16 values (and a buffer of 154 bytes) for REGISTER 3000~3076 in an array (e.g. `[val_of_3000,val_of_30001,etc,etc,etc]`)
- It will also return these values as a `Buffer` in `msg.responseBuffer.buffer` - we will access these in the buffer parser
  - The buffer parser is set to grab a 32bit float (4 bytes) from byte offset 0 (aka Register 3000) and return it as `msg.payload.current` (see image below for ref)
  - The buffer parser is set to grab the next 32bits float (4 bytes) from byte offset 56 (aka Register 3028) and return it as `msg.payload.voltage` (see image below for ref)
  - etc etc

Why...

- Because making 5 single requests is MUCH slower than grabbing all the data at once
- Because grabbing individual values causes "inconsistent data"

//for reference

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

---

<div class="post-metadata">

### Author: ![TheMisterA](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@TheMisterA](https://discourse.nodered.org/u/TheMisterA)
#### Post date: [21 May 2021 07:56 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/12 "2021-05-21T07:56:27Z")

</div>

Ok, thanks for your reply !  
But, the response of the Buffer Parser is :

> RangeError [ERR\_OUT\_OF\_RANGE]: The value of "offset" is out of range. It must be \>= 0 and \<= 0. Received 56

Here the flow :

```auto
[{"id":"46d3f8ff.5cfc08","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b08c8b03.0ab7d8","type":"modbus-getter","z":"46d3f8ff.5cfc08","name":"","showStatusActivities":true,"showErrors":false,"logIOActivities":false,"unitid":"2","dataType":"HoldingRegister","adr":"3000","quantity":"2","server":"111e1e7d.08f902","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":420,"y":300,"wires":[["e61cc957.8e5ee8"],[]]},{"id":"55d05965.f27718","type":"inject","z":"46d3f8ff.5cfc08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":300,"wires":[["b08c8b03.0ab7d8"]]},{"id":"e61cc957.8e5ee8","type":"buffer-parser","z":"46d3f8ff.5cfc08","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"current","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"voltage","offset":56,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"activePower","offset":108,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"reactivePower","offset":136,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"apparentPower","offset":152,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":true,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":670,"y":300,"wires":[[]]},{"id":"111e1e7d.08f902","type":"modbus-client","name":"","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU","serialBaudrate":"19200","serialDatabits":"8","serialStopbits":"1","serialParity":"even","serialConnectionDelay":"100","unit_id":10,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true}]

```

---

<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: [21 May 2021 08:08 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/13 "2021-05-21T08:08:22Z")

</div>

You are requesting 2 registers from modbus...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e02180b87e7ba5861b83935b80a8b733941c22e.png)  
... 2 registers is == **4 bytes**

  

The buffer parser is set to parse multiple values (current, voltage, etc) from ...

- offset 0 (reg 3000)
- offset 56 (reg 3028)
- offset 108 (reg 3054)
- offset 136 (reg 3068)
- offset 152 (reg 3076)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1fac0843ee34159be20fd4b18724ca3d93a38fa3.png)  
... so needs MORE than 4 bytes

  

If you want this to work, you need to grab all the registers in one go as described...

> [@Steve-Mcl](#):
>
> Set the modbus node to read from address 3000 & quantity to 77  
> **This will return 77 INT16 values (154 `bytes` )**  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/dfd6a45571a01855df44ab5faaf2a6a9c475d107.png)

---

<div class="post-metadata">

### Author: ![TheMisterA](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@TheMisterA](https://discourse.nodered.org/u/TheMisterA)
#### Post date: [26 May 2021 06:18 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/14 "2021-05-26T06:18:15Z")

</div>

Hi Steve,

I found the solution by chance. I turned the buffer parser around until I found my expected value.  
I also called Schneider Electric who pointed out an error in the calculation note: all values in Float32 are expressed in Kilo.  
Moreover, the MSB must be switched to the left for reading.  
Here is the flow:

```auto
[{"id":"bc264764.dff808","type":"buffer-parser","z":"f92e921.524f77","name":"Float 32 to Dec","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"Puissance (Wh)","offset":0,"length":1,"offsetbit":0,"scale":"1000","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":380,"y":120,"wires":[["f704a034.13002"]]}]

```

So simple and so complicated at the same time !

Thanks for your involvement and I hope others can be helped!

---

<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: [9 June 2021 06:18 UTC](https://discourse.nodered.org/t/convert-modbus-float32-to-dec/45975/15 "2021-06-09T06:18:43Z")

</div>

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