# How to convert integer value coming from modbus to float value

**URL:** <https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273>\
**Category:** General\
**Created:** [27 September 2022 06:49 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273 "2022-09-27T06:49:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![aminulhaq](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@aminulhaq](https://discourse.nodered.org/u/aminulhaq)\
**Post date:** [27 September 2022 06:49 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/1 "2022-09-27T06:49:43Z")

</div>

Hi i am using energy meter and reading float type value but it is comming as integer in two different byte i want to convert this to float value to make this value usable  
Thanks

 ![energy meter read value conversion](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/eb14b7beebefcd6a568439c9dc9e0bf1248106ac.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:** [27 September 2022 10:53 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/2 "2022-09-27T10:53:14Z")

</div>

Look at your flow. You are debugging the modbus node pin 1 but you have connected buffer parser to pin 2.

---

<div class="post-metadata">

**Author:** ![aminulhaq](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@aminulhaq](https://discourse.nodered.org/u/aminulhaq)\
**Post date:** [27 September 2022 11:34 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/3 "2022-09-27T11:34:36Z")

</div>

I am now able to get the values after parser but it is not showing correct like i am reading frequency which is 49.567 hz but value after parser showing wrong value i have tried with 16bit 32bit uint int etc but not getting correct value i am not understanding how to set parser configurition according to our need

---

<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:** [27 September 2022 16:07 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/4 "2022-09-27T16:07:42Z")

</div>

For anyone to help, you need to provide the input data and expected output value(s).

You can grab a copy of the input data by using the "copy value" button on the debug output of the modbus data.

Also, show us a screen shot of the buffer parser.

Lastly, do you have a link to the manual and the modbus address you are using? Some modbus devices do not pack the data in IEEE formats (instead use a custom data format)

---

<div class="post-metadata">

**Author:** ![aminulhaq](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@aminulhaq](https://discourse.nodered.org/u/aminulhaq)\
**Post date:** [28 September 2022 04:57 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/5 "2022-09-28T04:57:54Z")

</div>

Hi,  
kindly see the parser setting and value which i want to read from energy meter  
[DPM-C530 Operation Manual (deltronics.ru)](http://www.deltronics.ru/images/manual/DPM-C530_OM_EN_20180926.pdf)

 ![parser](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/4/44e7aa18c30328e21a9ee2961340aead2ab7d785.png)  
 ![value that want to read](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d2754c01905c5f1318e37b4793b200bf7ad48299.png)

---

<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:** [28 September 2022 15:49 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/6 "2022-09-28T15:49:47Z")

</div>

Hi .. and how have you configured the Modbus node ?

One thing i notice from that table is that the first column .. the **hex** representation of the address  
142 hex in decimal is 322 and 143 hex is 323 dec

So as a test can you start reading the two registers needed for the Hz from 322 and Quantity 2

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

and in Buffer parser set as a **float**

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

---

<div class="post-metadata">

**Author:** ![aminulhaq](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@aminulhaq](https://discourse.nodered.org/u/aminulhaq)\
**Post date:** [29 September 2022 05:56 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/7 "2022-09-29T05:56:15Z")

</div>

I have successful in getting frequency data by following setting

 ![success in getting frequency data](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/13ed2693d05284df882c3b82e2b45555b78db346.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:** [29 September 2022 05:57 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/8 "2022-09-29T05:57:23Z")

</div>

There should be no need to byte swap the data if you use float BE.

---

<div class="post-metadata">

**Author:** ![aminulhaq](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@aminulhaq](https://discourse.nodered.org/u/aminulhaq)\
**Post date:** [29 September 2022 06:00 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/9 "2022-09-29T06:00:35Z")

</div>

Hi i have displayed this frequency data to dashboard but it is not looking much fancy and showing frequency with its label too i want wo make good visual any one can suggest how to do that or how to correct value upto 4 decimal places  
Thanks

 ![dashboard adjustement required](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/877e03dc7ab4a63012f238cb8a179f674f820fa1.png)  
 ![guage setting](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9bd263e75d8b65035e12c2455b2fcb5905919c03.png)  
 ![text editor setting](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/eba5fefd27b717345da133508fcc90cdcd46e1e8.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:** [29 September 2022 06:04 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/10 "2022-09-29T06:04:57Z")

</div>

1. Instead of using msg.payload you should be using msg.payload.item1
2. To format the number on the dashboard use angular pipes [How to limit temp display on dashboard to 2 decimals - #3 by Steve-Mcl](https://discourse.nodered.org/t/how-to-limit-temp-display-on-dashboard-to-2-decimals/45622/3)

---

<div class="post-metadata">

**Author:** ![aminulhaq](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@aminulhaq](https://discourse.nodered.org/u/aminulhaq)\
**Post date:** [29 September 2022 06:10 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/11 "2022-09-29T06:10:24Z")

</div>

Thanks, is ther any batter dashboard or other application which i can use with node red to make its look batter

---

<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:** [29 September 2022 06:22 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/12 "2022-09-29T06:22:18Z")

</div>

You can write your own web pages if you wish using whatever web technology you are capable of using. But that is a whole other question. If you are finished with this question then please mark the solution. If you want to ask more about dashboards, please start a new thread.

---

<div class="post-metadata">

**Author:** ![aminulhaq](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@aminulhaq](https://discourse.nodered.org/u/aminulhaq)\
**Post date:** [29 September 2022 06:56 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/13 "2022-09-29T06:56:00Z")

</div>

I wnat to know that how we decide wethere use int16be or float(be) of uint etc in parser the concept is not clear to me  
Thanks

---

<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:** [29 September 2022 07:13 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/14 "2022-09-29T07:13:43Z")

</div>

To understand that you need to understand the [endianess](https://en.wikipedia.org/wiki/Endianness) of the modbus device and the byte packing order the device programmer uses.

For example, if the device is supposed to return the hexadecimal value `0x1234` and you get `0x3412` then it is little-endian (or LE)

There are thousands of articles around the internet if you want to go farther down the rabbit hole.

In truth, you often do not know what processor or encoding a device manufacturer uses - so look at the data using BE functions, if it looks wrong try LE or SWAP16 etc until you get sensible data.

---

<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:** [29 September 2022 07:16 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/15 "2022-09-29T07:16:42Z")

</div>

> [@aminulhaq](#):
>
> decide wethere use int16be or float(be)

This depends on what you are reading and how the device was programmed to provide values. Typically the manual will state "INT" or "INT16" then it will be `int16be` or `int16le`. If the manual states "unsigned int" or "unsigned integer" or "UINT" etc then typically chose the `UINT16be` function. If the manual states `float` or `IEEE 754` then use `float (be)` or `float (le)` etc.

A lot of this comes down to experience and training. I have spent more years than I care to mention working with PLCs and hardware devices. If you wish to understand more, then you need to read, read, read & try, try, try.

---

<div class="post-metadata">

**Author:** ![aminulhaq](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@aminulhaq](https://discourse.nodered.org/u/aminulhaq)\
**Post date:** [29 September 2022 07:46 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/17 "2022-09-29T07:46:09Z")

</div>

Hi, i have configured the voltage reading too on node red and it was showing correct value but i then restarted my laptop and run nodered now it is showing error on voltage parser see pic and error for referednce  
error : Error: data is not an array or a buffer

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea2341ad9df54bef3701daa5f1669258a5c28bef.png)  
 ![voltage parser error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/48e40ef594dcd90e61250d43319d3d059ee21879.png)  
 ![voltage setting](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/71477263ec28f5d8f88e700fbc33e3a6498b2083.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:** [29 September 2022 07:59 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/18 "2022-09-29T07:59:13Z")

</div>

> [@aminulhaq](#):
>
> error : Error: data is not an array or a buffer
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea2341ad9df54bef3701daa5f1669258a5c28bef.png)

Same as last time - look at the image you posted...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/57195652aedb10d48308ebf63868a32dce64b440.png)

Also, are you reading values close to each other in modbus?

If you are reading registers 240-241 AND registers 256-257 then I strongly recommend you read all registers from 240~257 in one MODBUS node and use the parser to pick out the values of interest. This has the following advantages....

1. values are read at the same scan of the device (and are therefore consistent)
2. reading 1 modbus poll of 28 items is faster than 2 modbus polls. This will only get worse with each additional single read/poll.
3. Individual modbus comms lead to contention on the wire (and eventually timeouts - search the forum - covered many times)

---

<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:** [29 September 2022 08:00 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/19 "2022-09-29T08:00:35Z")

</div>

> [@aminulhaq](#):
>
> ![voltage parser error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/48e40ef594dcd90e61250d43319d3d059ee21879.png)

PS, as I said before...

> [@Steve-Mcl](#):
>
> There should be no need to byte swap the data if you use float BE

---

<div class="post-metadata">

**Author:** ![aminulhaq](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@aminulhaq](https://discourse.nodered.org/u/aminulhaq)\
**Post date:** [29 September 2022 08:08 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/20 "2022-09-29T08:08:05Z")

</div>

if i use from 240 to 257 then how to pic perticular two address in parser because i didnt fint any selection there,  
Also what is this second dot for in modbus read node as you told i just change dot connection and it is working

---

<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:** [29 September 2022 08:14 UTC](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273/21 "2022-09-29T08:14:00Z")

</div>

> [@aminulhaq](#):
>
> if i use from 240 to 257 then how to pic perticular two address in parser because i didnt fint any selection there

Use the `offset` to access other bytes,

| MB address | Returns | offset byte |
| --- | --- | --- |
| 240 | 16 bit integer (2 bytes) | 0 |
| 241 | 16 bit integer (2 bytes) | 2 |
| 242 | 16 bit integer (2 bytes) | 4 |
| 243 | 16 bit integer (2 bytes) | 6 |
| 244 | 16 bit integer (2 bytes) | 8 |
| 245 | 16 bit integer (2 bytes) | 10 |
| 246 | 16 bit integer (2 bytes) | 12 |
| 247 | 16 bit integer (2 bytes) | 14 |
| 248 | 16 bit integer (2 bytes) | 16 |
| 249 | 16 bit integer (2 bytes) | 18 |
| 250 | 16 bit integer (2 bytes) | 20 |
| 251 | 16 bit integer (2 bytes) | 22 |
| 252 | 16 bit integer (2 bytes) | 24 |
| 253 | 16 bit integer (2 bytes) | 26 |
| 254 | 16 bit integer (2 bytes) | 28 |
| 255 | 16 bit integer (2 bytes) | 30 |
| 256 | 16 bit integer (2 bytes) | 32 |
| 257 | 16 bit integer (2 bytes) | 34 |

e.g...

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

  

> [@aminulhaq](#):
>
> Also what is this second dot for in modbus read node as you told i just change dot connection and it is working

The second output is for "i dont know but pretty sure it is documented in the built in help for that node" 🙂

[Next page](https://discourse.nodered.org/t/how-to-convert-integer-value-coming-from-modbus-to-float-value/68273.md?page=2)
