Sensor Data to CSV file

Hi,

I am trying to write the logged sensor data in CSV file. I am getting the file with “i” {x,y,z} values and want to write that data to a CSV file.
Has anyone done it before? What would you recommend looking at first?

Hi @arystan

  1. Which ncd sensor are you using?
  2. What data would you like to write in the CSV file?

I’m asking because we are developing ncd Node-RED Dashboard with the function to save CSV data.

For now they are available for:

and more coming soon.

But if you are using another type, don’t worry, I could help you create your own flow.

Hi Eduardo,

We are using NCD 2-channel vibration sensor plus. The file below is the vibration we are reading (testing it right now). I want to write X Y and Z to CSV file.

Data_points.txt (112.2 KB)

We were able to read the device temperature separately.
I have not tried reading data through modbus yet, but I believe it could be an easier way to collect data through modbus and write it to CSV. Json file is attached below:
vibrationflows.json (16.7 KB)

Thank you!

Best regards,

I share you a basic flow to save CSV file for “i” {x,y,z} values:

[{"id":"846bf67135d18c8c","type":"csv","z":"554db30249c9d434","name":"building CSV","sep":",","hdrin":false,"hdrout":"none","multi":"one","ret":"\\r\\n","temp":" key, value_x, value_y, value_z","skip":"0","strings":true,"include_empty_strings":true,"include_null_values":true,"x":650,"y":200,"wires":[["96fe9348b70f10f3"]]},{"id":"96fe9348b70f10f3","type":"file","z":"554db30249c9d434","name":"Add your local path","filename":"","filenameType":"str","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":830,"y":200,"wires":[["b2df274e1d839634"]]},{"id":"b2df274e1d839634","type":"debug","z":"554db30249c9d434","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":200,"wires":[]},{"id":"abea9099e3c8c3b0","type":"function","z":"554db30249c9d434","name":"getData","func":"var data = msg.payload.data;\nfor (const property in data) {\n  msg.payload = {\n    key : property, \n    value_x : data[property].x,\n    value_y : data[property].y,\n    value_z : data[property].z,\n  };\n  node.send(msg);\n}\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":200,"wires":[["846bf67135d18c8c"]]}]
  1. Copy JSON.

  2. Go to Node-RED instance, click on main menu and select “Import” option.
    Screenshot from 2024-04-01 18-19-59

  3. Paste JSON in textbox (pink color):

  4. Click on “Import” button.

  5. Connect the output of your ncd node (2-Channel Vibration Plus) to input function node:

  1. Double clic on “Add your local path” node and type the path where you want to save the CSV file and add the file name at the end of the path with the CSV extension, for example:
  • C:\Users<username>\Desktop<yourFileName>.csv

Screenshot from 2024-04-01 18-23-55

  1. Click on DEPLOY button, and if everything is correct, as soon as a new message arrives from the sensor, you should be able to observe in the debug window the data being written:

Screenshot from 2024-04-01 18-16-50

Then go to the path you assigned and open the “log.csv” file to verify the data.

I hope you find the flow useful, let me know if you have any questions or if I can help you with anything else,
Thanks
Eduardo M.

1 Like