How to save sensor data in text file?

Hello everybody,

I'm not very familiar with Node-RED and programming in general, so I probably have a very simple question.
I have a project in which I read out 15 temperature sensors in parallel and also have to save the data. I use ESP8266 microcontrollers and DS18B20 sensors. The transmission takes place via a pi server. The measured values ​​are displayed wonderfully on the dashboard, but how do I get the data saved?
I have already tried the "File" function and created a text file, but nothing appears in this text file.
It would be great if someone could help me, it's probably pretty easy, but unfortunately I can't get any further :slight_smile:
Thanks in advance

[{"id":"532afdc6.4f7d24","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"dfa0b7d9.597e58","type":"mqtt in","z":"532afdc6.4f7d24","name":"","topic":"esp/ds18b20/temperature1","qos":"1","datatype":"auto","broker":"bc121263.3a247","x":150,"y":140,"wires":[["932d1e01.700a2","23e316df.b94faa"]]},{"id":"932d1e01.700a2","type":"ui_chart","z":"532afdc6.4f7d24","name":"","group":"3c4c1da2.870402","order":3,"width":"0","height":"0","label":"","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"","dot":true,"ymin":"15","ymax":"75","removeOlder":"8","removeOlderPoints":"1000","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":370,"y":140,"wires":[["23e316df.b94faa"]]},{"id":"23e316df.b94faa","type":"file","z":"532afdc6.4f7d24","name":"","filename":"C:\\Users\\Dave\\Desktop\\test.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"utf8","x":610,"y":140,"wires":[[]]},{"id":"bc121263.3a247","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"3c4c1da2.870402","type":"ui_group","name":"Temperature 1","tab":"f22c20d9.f0bff","order":3,"disp":true,"width":"7","collapse":false},{"id":"f22c20d9.f0bff","type":"ui_tab","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

You need the other file node. File in is for reading files.

1 Like

Ah sorry, I meant that I use "file" (write msg.payload in a file ...) and not "file in". #
Actually, I should only have to enter the text path from the text file into "file", into which the measured values ​​are then written, right?
Unfortunately the text file always remains empty.

Can you provide your flow so we can see what you are doing. In order to make code more readable and importable it is important to surround your code with three backticks

```like this```

You can edit and correct your post by clicking the pencil icon.

See this post for more details - How to share code or flow json

Long term, you will probaby want to save the data to a database....depending on what you want to use it for.

1 Like

The data are saved and processed immediately after the measurement. So I don't need a database on which the data has to be stored over a long period of time.
I would like to save everything directly on the PC. A measurement takes approx. 3 hours and approx. 150 measured values ​​are recorded per sensor.
I would then copy the data out of the text file and format the text file again, then the new measurement would come.

I hope I can express my concerns in an understandable way, thanks for the feedback, I'm really a total beginner :smiley:

[{"id":"532afdc6.4f7d24","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"dfa0b7d9.597e58","type":"mqtt in","z":"532afdc6.4f7d24","name":"","topic":"esp/ds18b20/temperature1","qos":"1","datatype":"auto","broker":"bc121263.3a247","x":150,"y":140,"wires":[["932d1e01.700a2","23e316df.b94faa"]]},{"id":"932d1e01.700a2","type":"ui_chart","z":"532afdc6.4f7d24","name":"","group":"3c4c1da2.870402","order":3,"width":"0","height":"0","label":"","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"","dot":true,"ymin":"15","ymax":"75","removeOlder":"8","removeOlderPoints":"1000","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":370,"y":140,"wires":[["23e316df.b94faa"]]},{"id":"23e316df.b94faa","type":"file","z":"532afdc6.4f7d24","name":"","filename":"C:\\Users\\Dave\\Desktop\\test.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"utf8","x":610,"y":140,"wires":[[]]},{"id":"bc121263.3a247","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"3c4c1da2.870402","type":"ui_group","name":"Temperature 1","tab":"f22c20d9.f0bff","order":3,"disp":true,"width":"7","collapse":false},{"id":"f22c20d9.f0bff","type":"ui_tab","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Your flow works for me (though I did add an inject to send data and changed the path because I'm on a Mac) but why are you sending the output of the mqtt-in and ui-chart to the file?
If you move the chart node you will see what I mean

1 Like

I noticed what you mean, when moving both topics were connected to the file, I have now fixed it.
But what is right to log the data from the mqtt-in or the ui-chart?
For further understanding: I followed the instructions below:

Everything works fine, but I cannot save the data via "file" as if there was no connection to my PC in this direction :thinking:

Oh the file nodes will be writting the file out on the device running node-red. Are you running it on your PC or on another device?

As to the format of the data in the file, what do you want it to look like?

1 Like

Mate, you were absolutely right. When I opened the memory of the raspi there were all the files I had created.
I must have had a huge knot in my brain :exploding_head:
Thank you for taking the time to solve my problem, now everything works fine and I can log the data.

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