# File Storage to a text file

**URL:** <https://discourse.nodered.org/t/file-storage-to-a-text-file/43826>\
**Category:** General\
**Created:** [7 April 2021 17:15 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826 "2021-04-07T17:15:09Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![dirtydredrt](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@dirtydredrt](https://discourse.nodered.org/u/dirtydredrt)\
**Post date:** [7 April 2021 17:15 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/1 "2021-04-07T17:15:09Z")

</div>

I have a BME280 sending out Temp, humidity, pressure, heatindex, dewpoint, temp F, pressure Hg.  
i'm only using 3 outputs  
I have three gauges temperature 70.0 Humidity 29.6 and Pressure 30.1 i have added filters to eliminate trailing digits.  
I send the data to the file node and the text file reads  
70.12345678946  
29.12318641684  
30.16512565668  
The data from the BME280 node goes to a change node then to the file node.  
Can i place a function node between the change node and the file node to filter trailing digits.

---

<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:** [7 April 2021 17:20 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/2 "2021-04-07T17:20:08Z")

</div>

> [@dirtydredrt](#):
>
> Can i place a function node between the change node and the file node to filter trailing digits

Yes you can.

---

<div class="post-metadata">

**Author:** ![dirtydredrt](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@dirtydredrt](https://discourse.nodered.org/u/dirtydredrt)\
**Post date:** [7 April 2021 17:21 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/3 "2021-04-07T17:21:31Z")

</div>

can you help with a formula for the function

---

<div class="post-metadata">

**Author:** ![dirtydredrt](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@dirtydredrt](https://discourse.nodered.org/u/dirtydredrt)\
**Post date:** [7 April 2021 17:21 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/4 "2021-04-07T17:21:54Z")

</div>

```auto
[{"id":"72043f3d.827cc","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"272eb534.be29ca","type":"ui_gauge","z":"72043f3d.827cc","name":"","group":"5d511d53.994404","order":3,"width":"6","height":"3","gtype":"gage","title":"Temperature","label":"DEG F","format":"{{value | number :1}}","min":"32","max":"100","colors":["#00ff00","#e6e600","#ca3838"],"seg1":"90","seg2":"100","x":870,"y":100,"wires":[]},{"id":"90116c44.f3074","type":"inject","z":"72043f3d.827cc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":60,"wires":[["74df22fe.74f7fc"]]},{"id":"74df22fe.74f7fc","type":"Bme280","z":"72043f3d.827cc","name":"Pressure","bus":"1","address":"0x76","topic":"bme280","extra":true,"x":240,"y":60,"wires":[["fea6e758.ad9fb8","394f61c4.52fb5e","417ed70d.ece5f8","ed34257d.0fc748"]]},{"id":"262fcf86.9db6b","type":"ui_gauge","z":"72043f3d.827cc","name":"","group":"5d511d53.994404","order":5,"width":"6","height":"3","gtype":"gage","title":"Barometric Pressure","label":"Hg","format":"{{value | number :1}}","min":0,"max":"100","colors":["#02f702","#e6e600","#ca3838"],"seg1":"","seg2":"","x":900,"y":180,"wires":[]},{"id":"fea6e758.ad9fb8","type":"change","z":"72043f3d.827cc","name":"Temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature_F","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":60,"wires":[["272eb534.be29ca","b4bf63bb.4fada","9a93c487.465258"]]},{"id":"394f61c4.52fb5e","type":"change","z":"72043f3d.827cc","name":"Humidity","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.humidity","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":180,"wires":[["2843b6a1.bc350a","6114affc.6f54b","9a93c487.465258"]]},{"id":"417ed70d.ece5f8","type":"change","z":"72043f3d.827cc","name":"Barometric Pressure","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.pressure_Hg","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":120,"wires":[["262fcf86.9db6b","9a93c487.465258","dc699213.a7ffa"]]},{"id":"2843b6a1.bc350a","type":"ui_gauge","z":"72043f3d.827cc","name":"","group":"5d511d53.994404","order":4,"width":"6","height":"3","gtype":"gage","title":"Humdity","label":"%","format":"{{value | number :1}}","min":0,"max":"100","colors":["#00ff00","#e6e600","#ca3838"],"seg1":"40","seg2":"80","x":860,"y":260,"wires":[]},{"id":"b4bf63bb.4fada","type":"debug","z":"72043f3d.827cc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":60,"wires":[]},{"id":"6114affc.6f54b","type":"debug","z":"72043f3d.827cc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":220,"wires":[]},{"id":"dc699213.a7ffa","type":"debug","z":"72043f3d.827cc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":140,"wires":[]},{"id":"9a93c487.465258","type":"file","z":"72043f3d.827cc","name":"","filename":"/home/pi/dynotests/dynorun.log","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":770,"y":400,"wires":[[]]},{"id":"d2aef49b.9bbe88","type":"file","z":"72043f3d.827cc","name":"","filename":"/home/pi/dynotests/dynorun.log","appendNewline":true,"createDir":false,"overwriteFile":"delete","encoding":"none","x":750,"y":460,"wires":[[]]},{"id":"aaf4dc78.c238a","type":"inject","z":"72043f3d.827cc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":400,"wires":[["9a93c487.465258"]]},{"id":"f9bead26.2ce08","type":"inject","z":"72043f3d.827cc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":460,"wires":[["d2aef49b.9bbe88"]]},{"id":"ed34257d.0fc748","type":"debug","z":"72043f3d.827cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1100,"y":40,"wires":[]},{"id":"5d511d53.994404","type":"ui_group","name":"Weather","tab":"70eb2da0.452ad4","order":2,"disp":true,"width":"6","collapse":false},{"id":"70eb2da0.452ad4","type":"ui_tab","name":"LANGE RACING","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<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:** [7 April 2021 17:22 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/5 "2021-04-07T17:22:11Z")

</div>

Can you share your flow and screen shot the data please?

(Need more info to assist)

Edit...  
You beat me to it 😂

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [7 April 2021 17:23 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/6 "2021-04-07T17:23:05Z")

</div>

Hi @dirtydredrt

In JavaScript, numbers have a function on them called `toFixed` that will convert them to a String with the required number of decimal places.

[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Number/toFixed](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)

In your case, you'd need a Function that calls `toFixed(1)` (to match what you've done with the gauges) on each of the properties.

Without more details on what you message looks like, it is hard to be any more specific.

---

<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:** [7 April 2021 17:27 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/7 "2021-04-07T17:27:24Z")

</div>

@dirtydredrt

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

the issue I see is you only send the payload to the file. How can you differentiate each value?

Also, this data will be a simple list of number and not really great for other uses (I imagine you are going to load the values into excel or something else later?)

* * *

A better solution would be to join all three values and create a CSV of data.

Is that of interest?

---

<div class="post-metadata">

**Author:** ![dirtydredrt](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@dirtydredrt](https://discourse.nodered.org/u/dirtydredrt)\
**Post date:** [7 April 2021 17:34 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/8 "2021-04-07T17:34:29Z")

</div>

This is part of a engine dyno that Colin help me create.  
At the end of the run i press a button on the dashboard and get th results of the run  
start RPM  
Finish RPM  
Date time  
weather info temp humidity and pressure  
the output file is OK, I would like to organize the output like  
Date time  
weather info  
Start run RPM  
Finish RPM  
Run time

---

<div class="post-metadata">

**Author:** ![dirtydredrt](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@dirtydredrt](https://discourse.nodered.org/u/dirtydredrt)\
**Post date:** [7 April 2021 17:36 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/9 "2021-04-07T17:36:23Z")

</div>

If needed i can copy my complete flow if that helps

---

<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:** [7 April 2021 17:43 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/10 "2021-04-07T17:43:05Z")

</div>

> [@dirtydredrt](#):
>
> i can copy my complete flow if that helps

No thanks 😆

Here is a small demo you can build upon.

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

```auto
[{"id":"51c8307b.a00d5","type":"function","z":"ddf1cb1b.a8f668","name":"fomrat values","func":"var p = {\n temperature: msg.payload.temperature_F.toFixed(2),\n humidity: msg.payload.humidity.toFixed(2),\n pressure: msg.payload.pressure_Hg.toFixed(2)\n}\nmsg.payload = p;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":300,"y":340,"wires":[["d7c152a1.a6876"]]},{"id":"d7c152a1.a6876","type":"csv","z":"ddf1cb1b.a8f668","name":"","sep":",","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":"temperature,humidity,pressure","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":470,"y":340,"wires":[["e741916.0221a7"]]}]

```

#### Info

Since the Bme280 has all properties in the msg, instead splitting the values out and writing them individually to the file, it is probably a better bet to write all values at once.

Look at the function code & what it does (add a debug node to the function output)  
Look at the column names entered in the CSV node.  
Look at the output of the CSV node

You should see how it fits together.

---

<div class="post-metadata">

**Author:** ![dirtydredrt](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@dirtydredrt](https://discourse.nodered.org/u/dirtydredrt)\
**Post date:** [7 April 2021 17:45 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/11 "2021-04-07T17:45:23Z")

</div>

this is my run file```  
test run

40  
400  
4 / 7 / 2021 10:42:25  
73.328  
3822

```auto

```

---

<div class="post-metadata">

**Author:** ![dirtydredrt](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@dirtydredrt](https://discourse.nodered.org/u/dirtydredrt)\
**Post date:** [7 April 2021 17:46 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/12 "2021-04-07T17:46:44Z")

</div>

Thanks Steve-Mcl  
i will give it a go

---

<div class="post-metadata">

**Author:** ![dirtydredrt](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@dirtydredrt](https://discourse.nodered.org/u/dirtydredrt)\
**Post date:** [7 April 2021 18:04 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/13 "2021-04-07T18:04:53Z")

</div>

you have fixed the readout .00  
Can I add Headings in the function  
This id my file now  
New file data  
4  
40  
72.91, 28.43, 30.09  
can we add a header  
temp 72.91  
Humidity 28.43  
Pressure 30.09

---

<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:** [6 June 2021 18:05 UTC](https://discourse.nodered.org/t/file-storage-to-a-text-file/43826/14 "2021-06-06T18:05:14Z")

</div>

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