Write msg.payload to a file on my synology NAS

I am running nodered on my Synology NAS.
I want to write a message (msg.payload) that arrives from a temperature sensor on my nodered server to a csv file on my Synology NAS. I have big problems with the correct formulation of the file path.

Can someone give me an example of how to enter the path?

Hi and welcome to the world of Node-Red.

When you say write a csv file.... Do you mean each value would be written to the end of the file to create a csv file?

So, basically:

You get msg.payload with the value you want.

You want to write that to a file (appending).

And each entry would be separated by a ,.

receive msg.payload. Put that into a template node (the orange one)
and in the field you would put:
, {{payload}}

You then send that to a write file node and set the name of the file.

That's about it.

Show us the node red startup log, that will tell us about the folder structure you are operating under.

where can i find the startup log or how can i generate it when i run nodered on my synology nas?

my problem is that i don't know exactly how to enter the path to the file if the file is on my NAS. It always says that the file cannot be found.

This is how I entered the path:

\192.168.1.194\volume1\docker\nodered\storage/test1.csv

Assuming that node-red and the file are both on the NAS then you don't need the ip address. However, I see that node red is running in a docker container so you need to enter the path from inside the container. If the place where you want to save it is not directly accessible from inside the container then you will have to mount that folder in the container. Docker is a pain.

If you add an Exec node to the flow and in it put the command
pwd
and feed that into a debug node, what does it show? Trigger it from an Inject node obviously. That may give us a clue about the file structure.

Thank you for your help!
This is the output:
/usr/src/node-red


image

Unfortunately, even with this information on the file structure, I am still not making any progress.

Also unfortunately no-one here (so far) seems to know about the file structure on this device.

Do you need to run node-red there rather than on something more appropriate?

That isn't true Colin. A number of us have Synology NAS's. We are missing critical information though.

Is Node-RED running in Docker on the NAS?

If so, as seems likely, the OP needs to give the Docker Node-RED config access to that location since, by default, it will only have writable access to the /data folder (which is another folder somewhere in volume1 most likely).

Synology NAS's are not full-featured Linux implementations. For example, they only have Busybox and not a full BASH environment. But they do have decent web admin interfaces and it should be easy enough to assign the correct folder to the Node-RED Docker config.

I don't use docker on my NAS because the NAS is rather chock full of files and is primarily used for doing backups from/to cloud. So though it is an Intel processor version, and has upgraded memory, running Docker processes tends to occasionally bring the file and backup handling to a crawl - even without Docker running, I regularly get notifications that the disk I/O is at 99% utilisation. There are a LOT of files and folders. :grinning:

1 Like

This recent thread may be useful Docker - Node Red - add and access additional volume?

1 Like

Hello @sigi3360 , you will not be able to write/read directly to/from your NAS file.

in this thread i have explained how I map/bind a NAS drive to my docker image, and in this post I have explained how you can read/write to a file on your NAS when mapped

That is why I said 'so far', meaning that no-one who has seen the post has the knowledge to help, but I think my wording was not clear.

Hello together
I have come one step further.
I found out that there is already a drive mapped to my Synology NAS.
image

I have placed the csv file in which I want to save my data directly in this folder. I have entered the following path for the node:
image

The payload is written correctly to the file and looks like this:
{"end_device_ids":{"device_id":"eui-a840413aa1844bb6","application_ids":{"application_id":"eschenweg11tempkeller"},"dev_eui":"A840413AA1844BB6","join_eui":"A840410000000101","dev_addr":"260B02E0"},"correlation_ids":["gs:uplink:01J0PGJA1XACWJ8KPYX0VN0W3A"],"received_at":"2024-06-18T20:28:13.449518301Z","uplink_message":{"session_key_id":"AYLfEYQASCGoMuEcCRCw9w==","f_port":2,"f_cnt":190476,"frm_payload":"DkYAAAEkAAC6AyE=","decoded_payload":{"batteryV":"3.654","hum_sht":"80.1","tempc_sht":"18.60"},"rx_metadata":[{"gateway_ids":{"gateway_id":"loragardener1","eui":"58A0CBFFFE8028ED"},"time":"2024-06-18T20:28:13.108084917Z","timestamp":2115280988,"rssi":-55,"channel_rssi":-55,"snr":11,"location":{"latitude":47.17489679472269,"longitude":7.554766237735748,"altitude":447,"source":"SOURCE_REGISTRY"},"uplink_token":"ChsKGQoNbG9yYWdhcmRlbmVyMRIIWKDL//6AKO0Q3MDS8AcaCwjd28ezBhCI3YF1IODOyYTIjRA=","received_at":"2024-06-18T20:28:13.221250293Z"}],"settings":{"data_rate":{"lora":{"bandwidth":125000,"spreading_factor":7,"coding_rate":"4/5"}},"frequency":"867700000","timestamp":2115280988,"time":"2024-06-18T20:28:13.108084917Z"},"received_at":"2024-06-18T20:28:13.246183773Z","consumed_airtime":"0.061696s","network_ids":{"net_id":"000013","ns_id":"EC656E0000000181","tenant_id":"ttn","cluster_id":"eu1","cluster_address":"eu1.cloud.thethings.network"}}}

Which node do I have to use if I only want to write individual parts of the long payload to my csv file?
What do I have to enter in the node?

The only way to do partial updates on files is to APPEND to the end of the file.

If you want to do anything more complex, you will almost certainly need to use something other than a CSV file.