# Organising Data for a temperature logger

**URL:** <https://discourse.nodered.org/t/organising-data-for-a-temperature-logger/26375>\
**Category:** General\
**Created:** [9 May 2020 11:51 UTC](https://discourse.nodered.org/t/organising-data-for-a-temperature-logger/26375 "2020-05-09T11:51:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hylkebab](https://avatars.discourse-cdn.com/v4/letter/h/91b2a8/32.png) [@Hylkebab](https://discourse.nodered.org/u/Hylkebab)\
**Post date:** [9 May 2020 11:51 UTC](https://discourse.nodered.org/t/organising-data-for-a-temperature-logger/26375/1 "2020-05-09T11:51:48Z")

</div>

Hello,

Im doing a project where I need to log temperatures into a file so that I can later make a model from it. This is my first time ever using Node Red/programming. Right now my flow produces the information I need and puts it in a .csv file, but it doesn't always put it in the right order. The correct order of things is the following picture:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/2863c3311a2f1bd31e7e753cfad4cb9e317f8d3b.png)  
This sometimes does happen, but it is inconsistent. Sometimes it shows temperature 4 first and then time and so on.

I've searched quite a bit and found something about msg.parts, though im not sure if this would help nor how it works since i know basically nothing about coding.

Im wondering if someone has a solution for my problem so that the data stays consistent. Following is a picture of my current flow:

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

```auto
[{"id":"3df14878.d252a8","type":"inject","z":"f2c9682d.170b58","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":240,"wires":[["41e561c7.8c85b","a3b74dd6.ce121","705db031.32cc","b0c0c50c.27b708","b1c75b0e.6da7c8"]]},{"id":"f42eebb5.255ff8","type":"file","z":"f2c9682d.170b58","name":"","filename":"/home/pi/Documents/temperatuur.csv","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":1210,"y":400,"wires":[[]]},{"id":"41e561c7.8c85b","type":"sensor-ds18b20","z":"f2c9682d.170b58","name":"","topic":"","sensorid":"28-00000b6a22d2","timer":"1","repeat":false,"x":330,"y":340,"wires":[["a981cc06.ccafa"]]},{"id":"946d6118.f3616","type":"inject","z":"f2c9682d.170b58","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":100,"wires":[["42a9eb61.da3b04"]]},{"id":"42a9eb61.da3b04","type":"file","z":"f2c9682d.170b58","name":"","filename":"/home/pi/Documents/temperatuur.csv","appendNewline":true,"createDir":false,"overwriteFile":"delete","encoding":"none","x":440,"y":100,"wires":[[]]},{"id":"a981cc06.ccafa","type":"function","z":"f2c9682d.170b58","name":"temp_a22d2","func":"msg.topic = \"B-Temp1\"\npayload = msg.payload.temperature;\nmsg.payload = payload;\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":340,"wires":[["117ce230.28395e"]]},{"id":"a3b74dd6.ce121","type":"sensor-ds18b20","z":"f2c9682d.170b58","name":"","topic":"","sensorid":"28-0300a279b846","timer":"1","repeat":false,"x":330,"y":380,"wires":[["b70f79d5.165f78"]]},{"id":"b70f79d5.165f78","type":"function","z":"f2c9682d.170b58","name":"temp_9b846","func":"msg.topic = \"C-Temp2\"\npayload = msg.payload.temperature;\nmsg.payload = payload;\nreturn msg;","outputs":1,"noerr":0,"x":521,"y":380,"wires":[["117ce230.28395e"]]},{"id":"117ce230.28395e","type":"join","z":"f2c9682d.170b58","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"5","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":750,"y":400,"wires":[["6665dc5b.c56b54","2e7bbdd4.104472"]]},{"id":"705db031.32cc","type":"function","z":"f2c9682d.170b58","name":"time","func":"msg.topic = \"A-tijd\"\nvar d = new Date();\nvar t = d.getTime();\npayload=t;\nmsg.payload=payload;\nreturn msg;","outputs":1,"noerr":0,"x":499,"y":300,"wires":[["117ce230.28395e"]]},{"id":"6665dc5b.c56b54","type":"csv","z":"f2c9682d.170b58","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"x":970,"y":400,"wires":[["f42eebb5.255ff8"]]},{"id":"2e7bbdd4.104472","type":"debug","z":"f2c9682d.170b58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":970,"y":340,"wires":[]},{"id":"b0c0c50c.27b708","type":"sensor-ds18b20","z":"f2c9682d.170b58","name":"","topic":"","sensorid":"28-00000b685e65","timer":"1","repeat":false,"x":330,"y":420,"wires":[["cf7ef99c.17f8d8"]]},{"id":"b1c75b0e.6da7c8","type":"sensor-ds18b20","z":"f2c9682d.170b58","name":"","topic":"","sensorid":"28-00000b68b38d","timer":"1","repeat":false,"x":330,"y":460,"wires":[["761561b5.82e8d"]]},{"id":"cf7ef99c.17f8d8","type":"function","z":"f2c9682d.170b58","name":"temp_85e65","func":"msg.topic = \"D-Temp3\"\npayload = msg.payload.temperature;\nmsg.payload = payload;\nreturn msg;","outputs":1,"noerr":0,"x":522,"y":420,"wires":[["117ce230.28395e"]]},{"id":"761561b5.82e8d","type":"function","z":"f2c9682d.170b58","name":"temp_8b38d","func":"msg.topic = \"E-Temp4\"\npayload = msg.payload.temperature;\nmsg.payload = payload;\nreturn msg;","outputs":1,"noerr":0,"x":523,"y":460,"wires":[["117ce230.28395e"]]}]

```

---

<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:** [9 May 2020 12:09 UTC](https://discourse.nodered.org/t/organising-data-for-a-temperature-logger/26375/2 "2020-05-09T12:09:16Z")

</div>

Don't log CSV, log JSON instead then it won't matter what order (JSON is extensible by design meaning if you later add flow1~4 then need to insert temp5 it doesn't break anything - order is irrelevant)

For this, I'd use the most excellent [node-red-contrib-flogger](https://flows.nodered.org/node/node-red-contrib-flogger).

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 May 2020 12:17 UTC](https://discourse.nodered.org/t/organising-data-for-a-temperature-logger/26375/3 "2020-05-09T12:17:12Z")

</div>

You can set the messages to join automatically and set the index in the order you want. Take a look at the info tab of the `join` node

---

<div class="post-metadata">

**Author:** ![Hylkebab](https://avatars.discourse-cdn.com/v4/letter/h/91b2a8/32.png) [@Hylkebab](https://discourse.nodered.org/u/Hylkebab)\
**Post date:** [9 May 2020 13:11 UTC](https://discourse.nodered.org/t/organising-data-for-a-temperature-logger/26375/4 "2020-05-09T13:11:32Z")

</div>

Thank you for your reply,

I chose for csv as it is quite easy to convert the data to Excel (I forgot to mention that i will further process the data with excel). It seems to be alot harder to the json data to excel, or am i mistaken here?

---

<div class="post-metadata">

**Author:** ![Hylkebab](https://avatars.discourse-cdn.com/v4/letter/h/91b2a8/32.png) [@Hylkebab](https://discourse.nodered.org/u/Hylkebab)\
**Post date:** [9 May 2020 13:24 UTC](https://discourse.nodered.org/t/organising-data-for-a-temperature-logger/26375/5 "2020-05-09T13:24:59Z")

</div>

Thanks for your reply,

Im guessing you are talking about the "parts" tab. I've looked into this before and I think it would solve my problem. The only issue I have with that now is that i dont know how to configurate it, and I wasn't able to find a guide that tells me the information I need. These are the 2 main questions I have:

1: Where do i put the code, in the function node?  
2: How do I give a function the id, I know that the command is: "msg.parts.id" but what comes next; =,{},().

It would be great if you could link an example.

---

<div class="post-metadata">

**Author:** ![Hylkebab](https://avatars.discourse-cdn.com/v4/letter/h/91b2a8/32.png) [@Hylkebab](https://discourse.nodered.org/u/Hylkebab)\
**Post date:** [9 May 2020 14:03 UTC](https://discourse.nodered.org/t/organising-data-for-a-temperature-logger/26375/6 "2020-05-09T14:03:12Z")

</div>

After some searching in the forums about msg.parts I found out how it works, everything is working as it should now. Thank you Steve-Mcl and zenofmud for offering help. I consider this topic case closed.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 May 2020 11:43 UTC](https://discourse.nodered.org/t/organising-data-for-a-temperature-logger/26375/7 "2020-05-10T11:43:17Z")

</div>

> [@Hylkebab](#):
>
> It seems to be alot harder to the json data to excel, or am i mistaken here?

Actually, it isn't that hard as long as you are using newer versions of Excel. Have a look at "PowerQuery". This is a feature of Excel that I use constantly to analyse CSV and other data including JSON. You can easily import a file or folder of files and restructure the data.

---

<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:** [24 May 2020 11:43 UTC](https://discourse.nodered.org/t/organising-data-for-a-temperature-logger/26375/8 "2020-05-24T11:43:29Z")

</div>

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