Organising Data for a temperature logger

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
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:

[{"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"]]}]

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.

1 Like

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

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?

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.

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.

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.

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