Location of file for file node access (CSV-file)...

1,471 views
Skip to first unread message

Tobias Persson

unread,
Apr 3, 2017, 2:38:39 AM4/3/17
to Node-RED
I´m a newbie to Node-RED and haven´t found an answer in here to a (very) basic question of mine.

I´m trying to parse a .csv-file and send the data in it, stored per row, as MQTT messages.

The messaging part works just fine and I have that in another flow, connecting to test.mosquitto.org without an problems.

In this flow I just want to find, open, read and parse a simple .csv file stored locally on my machine.

Starting up my local Node-RED instance I get the following path information:

3 Apr 08:00:37 - [info] Settings file  : /Users/tope1/.node-red/settings.js

3 Apr 08:00:37 - [info] User directory : /Users/tope1/.node-red

3 Apr 08:00:37 - [info] Flows file     : /Users/tope1/.node-red/flows_GOT-VINNTER-TOPE1.local.json


I then try to place my file directly under /Users/top1/.node-red but the file node does not find it there.

I used the file name string "2.5_day_3_rows.csv" in the file node. I also tried the file name string

"home/2.5_day_3_rows.csv" and "/home/2.5_day_3_rows.csv", all producing the same No Such File or Directory

error.


What am I missing? Where should I place the file? And what path string should I use?


Or should I possibly place the file in some other "home" directory of Node-RED?



Grateful for swift replies.



Mark Setrem

unread,
Apr 3, 2017, 2:50:17 AM4/3/17
to Node-RED
Use the full path to the directory you are storing the CSV
file e.g. /home/Pi/data/mycsvfile.txt

Tobias Persson

unread,
Apr 3, 2017, 3:02:24 AM4/3/17
to Node-RED
I tried the path "home/filename.csv" and then placed the file directly under ".../.node-red

It does not find the file I´m afraid.

Below is my exported flow 

"[{"id":"c626eddd.1cd26","type":"inject","z":"dae2cff7.9b095","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":140,"y":180,"wires":[["180b6add.e0ce25"]]},{"id":"ab930922.9553f8","type":"csv","z":"dae2cff7.9b095","name":"CSV parser","sep":",","hdrin":true,"hdrout":"","multi":"one","ret":"\\n","temp":"A,B,C,D","x":530,"y":180,"wires":[["6aa5f0ca.76bb5"]]},{"id":"180b6add.e0ce25","type":"file in","z":"dae2cff7.9b095","name":"File Reader","filename":"2.5_day_3_rows.csv","format":"utf8","x":330,"y":180,"wires":[["ab930922.9553f8"]]},{"id":"fbfdc763.2d4248","type":"debug","z":"dae2cff7.9b095","name":"","active":true,"console":"true","complete":"true","x":890,"y":180,"wires":[]},{"id":"6aa5f0ca.76bb5","type":"function","z":"dae2cff7.9b095","name":"","func":"var csv = msg.payload;\nreturn csv;","outputs":1,"noerr":0,"x":730,"y":180,"wires":[["fbfdc763.2d4248"]]}]"

Mark Setrem

unread,
Apr 3, 2017, 3:13:30 AM4/3/17
to node...@googlegroups.com
The file path for your csv file has nothing to do with node-red or the .node-red directory

If you are on a unix box in a terminal window cd to the directory you are storing your  data in ( personally I would NOT put it in .node-red)

and type pwd

e.g.
pi@raspberrypi:~ $ pwd
/home/pi


then append your filename to it

/home/pi/mycsvfile.txt

and try that in the file node 







--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/IXogxrE71jQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/d905a104-60f4-4b3e-96bc-ea7625eb14c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tobias Persson

unread,
Apr 3, 2017, 3:22:21 AM4/3/17
to Node-RED
Great - the full path actually worked fine.

But now I have another problem, that is probably easy to solve.

I use two different ways to access the .csv-file for testing purposes.

The first way is to use a http node and accessing the csv-file from a specific URL.

When I do this the output comes out parsed "as it should" with properties assigned.

When I try to use the same file but getting from a file node the output comes out as an Object but only with one property (see below).

With the http node:

"object
time"2017-04-02T13:19:06.380Z"
latitude63.2885
longitude-150.4405
depth128.3
mag2.6
magType"ml"
rms0.42
net"ak"
id"ak15660340"
updated"2017-04-02T13:33:55.545Z"
place"75km W of Cantwell, Alaska"
type"earthquake"
depthError0.6
status"automatic"
locationSource"ak"
magSource"ak" "

And using the file node:
"object
time"2017-03-28T13:46:30.150Z,36.114,-98.7575,5,2.5,mb_lg,,84,0.33,0.25,us,us20008vaq,2017-03-28T14:23:28.040Z,"20km ENE of Taloga, Oklahoma",earthquake,1.1,1.9,0.18,8,reviewed,us,us"

Any idea on what is going on here?

The actual flow used is this:
"[{"id":"48a750d.0e78db","type":"inject","z":"a39f949e.17d788","name":"Quakes","topic":"","payload":"","payloadType":"str","repeat":"900","crontab":"","once":true,"x":400,"y":140,"wires":[["c735c03b.02398"]]},{"id":"c735c03b.02398","type":"http request","z":"a39f949e.17d788","name":"","method":"GET","url":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.csv","tls":"","x":578.5,"y":139.999755859375,"wires":[["fbed0e7a.d33e9"]]},{"id":"fbed0e7a.d33e9","type":"csv","z":"a39f949e.17d788","name":"","sep":",","hdrin":true,"hdrout":"","multi":"one","ret":"\\n","temp":"","x":750,"y":140,"wires":[["ef43840f.69f9d8"]]},{"id":"e2ab84a9.eb54b8","type":"comment","z":"a39f949e.17d788","name":"Earthquake !!!","info":"","x":393.3333435058594,"y":89.95831298828125,"wires":[]},{"id":"ef43840f.69f9d8","type":"debug","z":"a39f949e.17d788","name":"","active":true,"console":"false","complete":"payload","x":930,"y":140,"wires":[]},{"id":"8e7a8ef5.dfa26","type":"inject","z":"a39f949e.17d788","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":400,"y":300,"wires":[["9174df52.c9af8"]]},{"id":"9174df52.c9af8","type":"file in","z":"a39f949e.17d788","name":"File Reader","filename":"/Users/tope1/.node-red/node_modules/2.5_day.csv","format":"utf8","x":570,"y":300,"wires":[["fbed0e7a.d33e9"]]}]"

Mark Setrem

unread,
Apr 3, 2017, 8:17:38 AM4/3/17
to node...@googlegroups.com
I'm not in front of my computer but it looks as if your csv file doesn't have a header row with the column titles and yet within the csv node you appear to have the option for a header row ticked. What do you get if you untick this option?



Sent from my iPhone
--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/IXogxrE71jQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Paul Woodard

unread,
Apr 3, 2017, 9:51:13 AM4/3/17
to Node-RED
Tobias, it looks like you have posted this in two threads. Try to only use one thread so you don't waste people's time reading multiple copies of the same thing. Thanks!
Reply all
Reply to author
Forward
0 new messages