# How to convert and store modbus data into csv file

**URL:** <https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851>\
**Category:** General\
**Created:** [14 September 2020 06:56 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851 "2020-09-14T06:56:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Energycharges](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Energycharges](https://discourse.nodered.org/u/Energycharges)\
**Post date:** [14 September 2020 06:56 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/1 "2020-09-14T06:56:42Z")

</div>

While connecting modbus , I got 1 part of the output.

Working on other part , modbus data to convert and store harmonics data into csv file.

Running separately Im getting output in debug , while connecting along with function node its showing NaN error , or sometimes no output.

I guess , need to do some modifications in function node

Can you please help me out ?

Can u please guide me , to get my data stored into csv file ?

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

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

Regards,  
Energycharges

---

<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:** [14 September 2020 07:57 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/2 "2020-09-14T07:57:41Z")

</div>

The first thing to do is to use debug nodes to work out where the problem is occurring. Once you have done that, if you need further help, then post what a debug node showing what is going into the node that is not working shows and also tell us what is coming out and what should come out. If it is a function node then post the contents of the node (use the `</>` button when pasting it here).  
If it is a function node that is failing then first look at the node red docs page Writing Functions which has help on debugging functions.

---

<div class="post-metadata">

**Author:** ![Energycharges](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Energycharges](https://discourse.nodered.org/u/Energycharges)\
**Post date:** [14 September 2020 08:09 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/3 "2020-09-14T08:09:55Z")

</div>

Thanks for your response Colin.

After Join node i checked with Debug node , it is working fine.

While connecting that join with function node , receiving error on my side.

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

Appreciate , your effort in notifying the issue  
thank you !

Energycharges

---

<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:** [14 September 2020 08:33 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/4 "2020-09-14T08:33:48Z")

</div>

Do you mean the output of the function node is not correct? If so please read my post again. First go and read the document I linked to and attempt to debug the function node yourself. If you still cannot get it working then show us what is going into the function node, what is coming out of the function node and the code of the function node.

---

<div class="post-metadata">

**Author:** ![Energycharges](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Energycharges](https://discourse.nodered.org/u/Energycharges)\
**Post date:** [14 September 2020 11:28 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/5 "2020-09-14T11:28:38Z")

</div>

Thanks for you response colin.

Current update is function mode is working fine , i added csv and file node along with it.  
My current flow

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

outputs below  
1.Join,  
2.function node  
3.file node  
4.debug node  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/71e281ec6d20760fa3b3c05577feda9cacd5ebca.png)

But in csv file only headers are present, no data is filled in .csv file

Can u guide me with Any reference documents and help me out with solution

Appreciate , your effort in notifying the issue  
thank you !

Energycharges

---

<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:** [14 September 2020 15:40 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/6 "2020-09-14T15:40:48Z")

</div>

What do you see if you look in the file?

---

<div class="post-metadata">

**Author:** ![Energycharges](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Energycharges](https://discourse.nodered.org/u/Energycharges)\
**Post date:** [14 September 2020 15:56 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/7 "2020-09-14T15:56:05Z")

</div>

Thanks for your response Colin

Only headers and Timestamp are getting stored in .csv file , but no data found

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95409060cb198c4c0c4f7934ceedeeb797455488.png)

Can you please guide me to get data stored in .csv file

Regards  
Energycharges

---

<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:** [14 September 2020 16:10 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/9 "2020-09-14T16:10:48Z")

</div>

Show us how you have configured the file node and also open the file with a straight text editor and see what is there.

---

<div class="post-metadata">

**Author:** ![Energycharges](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Energycharges](https://discourse.nodered.org/u/Energycharges)\
**Post date:** [14 September 2020 16:21 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/10 "2020-09-14T16:21:15Z")

</div>

Thanks for your kind response

File node

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

Text editor

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

Regards,  
Energy charges

---

<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:** [14 September 2020 17:14 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/11 "2020-09-14T17:14:41Z")

</div>

Can you show us again what is going into the file node please. Make it a bit bigger on the screen if possible, it was not clear on the previous one. Just what is going into the file node.

---

<div class="post-metadata">

**Author:** ![Energycharges](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Energycharges](https://discourse.nodered.org/u/Energycharges)\
**Post date:** [14 September 2020 19:38 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/12 "2020-09-14T19:38:48Z")

</div>

Thanks for your timely help  
I have done everything as per your instruction. I am able to read many parameters in single go. But I am stuck with CSV file . I changed the flow and did some modifications too, but same error exists again.

Other part of flow for energy is running successfully.

Flow

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

Output of debug window

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/0461a4dfef77f63141391d6003874ee02f1872d4.png)

output of CSV file

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

Text editor ouput

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

Appreciate , your effort in notifying the issue  
thank you !

Energycharges

---

<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:** [14 September 2020 19:59 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/13 "2020-09-14T19:59:12Z")

</div>

That makes a bit more sense now, with the csv node before the file. You had the csv file after the file node before which is why I could not understand how csv data was getting into the file. I rather suspect that the debug output you showed the first time was with this flow.  
So now we have to see why the csv node is not doing what you want. You need to show us how you have configured the csv node. Remember we are not telepathic so it is not possible to know these things unless you show us.

---

<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:** [14 September 2020 20:02 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/14 "2020-09-14T20:02:45Z")

</div>

Colin, also there is a comma after the date, in the Timestamp. Could that misaligned the csv ?

---

<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:** [14 September 2020 20:13 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/15 "2020-09-14T20:13:07Z")

</div>

Actually, I don't think that is the problem. Having said that we are not telepathic I am now going to predict that you have provided a list of headings in the csv node (Timestamp, HV1\_0, ...). The node uses those to determine which properties of the object you pass in to put into the csv data. Unfortunately none of the properties in the header list are present in the data you are passing in (except the timestamp), so the columns are all empty.

---

<div class="post-metadata">

**Author:** ![Energycharges](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Energycharges](https://discourse.nodered.org/u/Energycharges)\
**Post date:** [14 September 2020 20:16 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/16 "2020-09-14T20:16:15Z")

</div>

Thanks for your reply Colin

Sorry. Next time i will provide you all the necessary nodes and output. While raising my questions.

CSV node

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

File node

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

Join node

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

Appreciate , your effort in notifying the issue  
thank you !

Energycharges

---

<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:** [14 September 2020 20:22 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/17 "2020-09-14T20:22:58Z")

</div>

You have gone over the top now in providing data 🙂  
Now we know that it is the csv node that is not behaving as you expect then that is what we need.  
Did you see my reply a few minutes ago, explaining what the problem is?

---

<div class="post-metadata">

**Author:** ![Energycharges](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Energycharges](https://discourse.nodered.org/u/Energycharges)\
**Post date:** [14 September 2020 20:32 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/18 "2020-09-14T20:32:16Z")

</div>

Thank you Colin

Even i tried Posted my program, Notified as program exceeded the character limit.Unable to post it

You have given solution for it. sorry i didnt view it, i will check and update you

Yes Colin. i have done a same set of data with different parameters , the difference is i need that data to be sent to Cloud bd via CSV using q-gate. with your guidance i have achieved my output.

Working on this second part. got struck up with CSV file. Tried many times before raising the issue. But i couldnt solve it.

Im Seeking Help with you all. so that any1 can guide me in getting output in flow

Appreciate , your effort in notifying the issue  
thank you !

Energycharges

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 September 2020 21:56 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/19 "2020-09-14T21:56:10Z")

</div>

As Colin predicted... In the debug you can see HAV1\_0 etc. And yet in the CSV node you ask for HV1\_0 etc. Which doesn't exist, so you get blanks. It is important they are the same..

---

<div class="post-metadata">

**Author:** ![Energycharges](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@Energycharges](https://discourse.nodered.org/u/Energycharges)\
**Post date:** [15 September 2020 09:40 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/20 "2020-09-15T09:40:13Z")

</div>

Thank you @Colin 😃and @dceejay for your timely help 😃

Thank you @dceejay  
Finally, I got output from DEBUG window. Few changes with parameters in function node and CSV node , reached the output

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

Regards,  
Energycharges

---

<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:** [29 September 2020 09:40 UTC](https://discourse.nodered.org/t/how-to-convert-and-store-modbus-data-into-csv-file/32851/21 "2020-09-29T09:40:15Z")

</div>

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