# Receiving NaN when reading float registers from energy meter

**URL:** <https://discourse.nodered.org/t/receiving-nan-when-reading-float-registers-from-energy-meter/2118>\
**Category:** General\
**Created:** [6 August 2018 17:43 UTC](https://discourse.nodered.org/t/receiving-nan-when-reading-float-registers-from-energy-meter/2118 "2018-08-06T17:43:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iridiu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iridiu/32/1213_2.png) [@iridiu](https://discourse.nodered.org/u/iridiu)\
**Post date:** [6 August 2018 17:43 UTC](https://discourse.nodered.org/t/receiving-nan-when-reading-float-registers-from-energy-meter/2118/1 "2018-08-06T17:43:38Z")

</div>

Hi Node Red community,

I'm trying to read some values of the energy meter (Float32) in Node-Red. Interestingly, I can read some accurate values, but they are also some of the values for which I receive "NaN".  
The configuration consists of a [Schneider A9MEM3350 energy meter](https://www.schneider-electric.com/en/product/A9MEM3350/iem3350-energy-meter---125-a---modbus/) with a RS485 serial interface, a Modbus TCP gateway and Node Red running on a Raspberry Pi 3.  
Initially I had used an Arduino with RS485 transciever to read the values, with exactly the same result. In the following lines I attach some pictures and Node Red example flow, maybe someone can help me figure out what is wrong.

![NodeRed](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/be6456de40c59e7caf7ce8ae944cb64aa91dd438.jpg)

 ![NodeRed2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/ce8c4f7f6bc333c135e7fa3e41d14e5dbfb43efb.jpg)

````
```js [{"id":"788a1b70.8a44a4","type":"function","z":"1faa546d.dcd77c","name":"FC3 - I2: phase 2 current","func":"msg.payload = {\n 'fc': 3, \n 'unitid': 2, \n 'address': 3002, \n 'quantity': 2 \n}; \nreturn msg;","outputs":1,"noerr":0,"x":370,"y":80,"wires":[["1b9bebc8.6b6614"]]},{"id":"68fb9ce2.83d234","type":"modbus-response","z":"1faa546d.dcd77c","name":"","registerShowMax":20,"x":610,"y":240,"wires":[]},{"id":"4938af43.b6975","type":"function","z":"1faa546d.dcd77c","name":"","func":"// Create new Buffer based on array bytes\nconst buf = Buffer.from(msg.payload.buffer).swap16();\n\n// Represent these bytes as Float32\nconst value = buf.readFloatLE().toFixed(2);\n\n// save the value\nmsg.payload = value;\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":40,"wires":[["9113bce6.bab6c","4bd66b40.ec2424"]]},{"id":"9113bce6.bab6c","type":"ui_gauge","z":"1faa546d.dcd77c","name":"L1","group":"fbce3164.ebb78","order":0,"width":"2","height":"2","gtype":"compass","title":"L1","label":"A","format":"{{value | number:2 }}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1310,"y":40,"wires":[]},{"id":"c3177dab.69072","type":"function","z":"1faa546d.dcd77c","name":"","func":"// Create new Buffer based on array bytes\nconst buf = Buffer.from(msg.payload.buffer).swap16();\n\n// Represent these bytes as Float32\nconst value = buf.readFloatLE().toFixed(2);\n\n// save the value\nmsg.payload = value;\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":80,"wires":[["fa027e26.53958","a00fa66b.b7a5d8"]]},{"id":"751f4017.88405","type":"function","z":"1faa546d.dcd77c","name":"","func":"// Create new Buffer based on array bytes\nconst buf = Buffer.from(msg.payload.buffer).swap16();\n\n// Represent these bytes as Float32\nconst value = buf.readFloatLE().toFixed(2);\n\n// save the value\nmsg.payload = value;\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":120,"wires":[["21ae7ef0.3b84f2","32401ab7.44bee6"]]},{"id":"12fadbc5.393184","type":"function","z":"1faa546d.dcd77c","name":"","func":"// Create new Buffer based on array bytes\nconst buf = Buffer.from(msg.payload.buffer).swap16();\n\n// Represent these bytes as Float32\nconst value = buf.readFloatLE().toFixed(2);\n\n// save the value\nmsg.payload = value;\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":160,"wires":[["8985b39f.3726d","b61745c4.fa9eb8"]]},{"id":"fa027e26.53958","type":"ui_gauge","z":"1faa546d.dcd77c","name":"L2","group":"fbce3164.ebb78","order":0,"width":"2","height":"2","gtype":"compass","title":"L2","label":"A","format":"{{value | number:2 }}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1310,"y":80,"wires":[]},{"id":"21ae7ef0.3b84f2","type":"ui_gauge","z":"1faa546d.dcd77c","name":"L3","group":"fbce3164.ebb78","order":0,"width":"2","height":"2","gtype":"compass","title":"L3","label":"A","format":"{{value | number:2 }}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1310,"y":120,"wires":[]},{"id":"8985b39f.3726d","type":"ui_gauge","z":"1faa546d.dcd77c","name":"Current Avg.","group":"fbce3164.ebb78","order":0,"width":"6","height":"4","gtype":"compass","title":"Average current","label":"A","format":"{{value | number:2 }}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1290,"y":160,"wires":[]},{"id":"26a18739.d0a098","type":"modbus-flex-getter","z":"1faa546d.dcd77c","name":"I1: phase 1 current","showStatusActivities":true,"showErrors":false,"server":"675fd2c6.3dfa3c","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":610,"y":40,"wires":[[],["4938af43.b6975"]]},{"id":"c058e06d.a3159","type":"function","z":"1faa546d.dcd77c","name":"FC3 - I1: phase 1 current","func":"msg.payload = {\n 'fc': 3, \n 'unitid': 2, \n 'address': 3000, \n 'quantity': 2 \n}; \nreturn msg;","outputs":1,"noerr":0,"x":370,"y":40,"wires":[["26a18739.d0a098"]]},{"id":"1b9bebc8.6b6614","type":"modbus-flex-getter","z":"1faa546d.dcd77c","name":"I2: phase 2 current","showStatusActivities":true,"showErrors":false,"server":"675fd2c6.3dfa3c","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":610,"y":80,"wires":[[],["c3177dab.69072"]]},{"id":"a38d5c4c.fbe27","type":"modbus-flex-getter","z":"1faa546d.dcd77c","name":"I3: phase 3 current","showStatusActivities":true,"showErrors":false,"server":"675fd2c6.3dfa3c","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":610,"y":120,"wires":[[],["751f4017.88405"]]},{"id":"af608401.50f618","type":"modbus-flex-getter","z":"1faa546d.dcd77c","name":"Current Avg","showStatusActivities":true,"showErrors":false,"server":"675fd2c6.3dfa3c","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":590,"y":160,"wires":[[],["68fb9ce2.83d234","12fadbc5.393184"]]},{"id":"e8bb19f5.9a5a98","type":"function","z":"1faa546d.dcd77c","name":"FC3 - I2: phase 2 current","func":"msg.payload = {\n 'fc': 3, \n 'unitid': 2, \n 'address': 3004, \n 'quantity': 2 \n}; \nreturn msg;","outputs":1,"noerr":0,"x":370,"y":120,"wires":[["a38d5c4c.fbe27"]]},{"id":"bb9fa83f.baf8d8","type":"function","z":"1faa546d.dcd77c","name":"FC3 - Current Avg","func":"msg.payload = {\n 'fc': 3, \n 'unitid': 2, \n 'address': 3010, \n 'quantity': 2 \n}; \nreturn msg;","outputs":1,"noerr":0,"x":350,"y":160,"wires":[["af608401.50f618"]]},{"id":"e9cd218c.1680b","type":"inject","z":"1faa546d.dcd77c","name":"1 sec","topic":"","payload":"","payloadType":"str","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":100,"wires":[["c058e06d.a3159","788a1b70.8a44a4","e8bb19f5.9a5a98","bb9fa83f.baf8d8"]]},{"id":"b61745c4.fa9eb8","type":"modbus-response","z":"1faa546d.dcd77c","name":"","registerShowMax":20,"x":970,"y":240,"wires":[]},{"id":"4bd66b40.ec2424","type":"modbus-response","z":"1faa546d.dcd77c","name":"","registerShowMax":20,"x":1250,"y":240,"wires":[]},{"id":"a00fa66b.b7a5d8","type":"modbus-response","z":"1faa546d.dcd77c","name":"","registerShowMax":20,"x":1250,"y":280,"wires":[]},{"id":"32401ab7.44bee6","type":"modbus-response","z":"1faa546d.dcd77c","name":"","registerShowMax":20,"x":1250,"y":320,"wires":[]},{"id":"fbce3164.ebb78","type":"ui_group","z":"","name":"Current","tab":"8e5db1d7.c63a7","order":1,"disp":true,"width":"6","collapse":false},{"id":"675fd2c6.3dfa3c","type":"modbus-client","z":"","name":"iEM3350","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"192.168.1.1","tcpPort":"10502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"2","commandDelay":"1","clientTimeout":"1000","reconnectTimeout":"2000"},{"id":"8e5db1d7.c63a7","type":"ui_tab","z":"","name":"Power meter","icon":"dashboard","order":3}]
````

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [6 August 2018 20:25 UTC](https://discourse.nodered.org/t/receiving-nan-when-reading-float-registers-from-energy-meter/2118/2 "2018-08-06T20:25:31Z")

</div>

So you are trying to post something that is "Not A Number" i.e NAN

You could try writing the values to a file, or send it to a debug to allow you to determine what it is being received to then allow you to filter them out.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [6 August 2018 21:04 UTC](https://discourse.nodered.org/t/receiving-nan-when-reading-float-registers-from-energy-meter/2118/3 "2018-08-06T21:04:03Z")

</div>

Normally the modbus response node should be connected to the second output of a modbus read/write node.

In your flow the response node is connected to a function node. I am not sure if this will work.

What do you get if you replace the modbus response node by the regular debug node ?

---

<div class="post-metadata">

**Author:** ![iridiu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iridiu/32/1213_2.png) [@iridiu](https://discourse.nodered.org/u/iridiu)\
**Post date:** [7 August 2018 12:43 UTC](https://discourse.nodered.org/t/receiving-nan-when-reading-float-registers-from-energy-meter/2118/4 "2018-08-07T12:43:23Z")

</div>

Thank you @ukmoose and @Andrei, I have made some readings to a file, in first example I connected the output to the first output (up) of the modbus node:

 ![NodeRed3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/88e6a45653203c923149ec5d3f10289d670e10f4.jpeg)

[L1.txt](https://discourse.nodered.org/uploads/short-url/pltvT1vAH2Q1fszj7MJJ3YkDjf9) (3.4 KB)  
[L2.txt](https://discourse.nodered.org/uploads/short-url/mF5oqhqXwvVXz4GYTkvvLfB0qWP) (3.4 KB)  
[L3.txt](https://discourse.nodered.org/uploads/short-url/5fHsSJnwpOJFrkSo14UHKgC1D3t) (3.4 KB)  
[Avg.txt](https://discourse.nodered.org/uploads/short-url/eEJBL8Qie5VYnmjs1335DktUyY4) (18.2 KB)

And in the second example is the output of the second connection of the modbus node (down) as shown in the image:

 ![NodeRed4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a82137400a5480c8dc95069b1537d05c23979999.jpeg)

[L1-2.txt](https://discourse.nodered.org/uploads/short-url/KJlO8SiStKuewezsDHak7edeGn) (10.3 KB)  
[L2-2.txt](https://discourse.nodered.org/uploads/short-url/s1IHVer3PCwWFZeBetTcrn6tr28) (10.5 KB)  
[L3-2.txt](https://discourse.nodered.org/uploads/short-url/xZMPtfW4c2AyTpnxRKeta0XXiyD) (10.6 KB)  
[Avg-2.txt](https://discourse.nodered.org/uploads/short-url/8DVj5L47j9nekzc5r896Wd0gQpp) (10.6 KB)
