Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location of Files created in Node Red or Node Red Reading a File #36

Closed
Paulf007 opened this issue Nov 2, 2019 · 10 comments
Closed

Location of Files created in Node Red or Node Red Reading a File #36

Paulf007 opened this issue Nov 2, 2019 · 10 comments

Comments

@Paulf007
Copy link
Contributor

Paulf007 commented Nov 2, 2019

Doing some more Testing I have found the Node Red does not seem to be able to read files within the home file. I have created a quick flow to test and if you select Create the directory if it doesn't exist it seems to create the new file but I cannot find it in the location where I added it.
Where do I locate a file that is written in Node-Red and how can I link a file in Node-Red?

@gcgarner
Copy link
Owner

gcgarner commented Nov 2, 2019

Containers run in a sandbox that don't have access to the host file system. For nodred the host can see the contents of the "/data" folder by means of the volume mapping but as far as nodered is concerned the host is a totally different computer.

If you want to share files between nodered and the host then you will need to save it in the "bridge" of ~/IOTstack/volumes/nodered/data:/data. If there is a specific host file that you want to access you could make a symbolic link into the volume, that way it is in a convenient place in your host and in the /data folder in nodered. All files in the nodered volume have root permissions so you would need to take that into account

@Paulf007
Copy link
Contributor Author

Paulf007 commented Nov 2, 2019

Thank you Graham it makes sence and will have to look at the bridge option. Just one more thing on the tpoic. Where would the file be store if created in Node red?
Have a look at this flow.
[{"id":"30fa8a04.e5f166","type":"inject","z":"40aad96e.d871f8","name":"","topic":"","payload":"test","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":4440,"wires":[["413b64ee.bbbdac"]]},{"id":"413b64ee.bbbdac","type":"file","z":"40aad96e.d871f8","name":"","filename":"testfile.txt","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":450,"y":4440,"wires":[["10a9ec01.ed6f64"]]},{"id":"10a9ec01.ed6f64","type":"debug","z":"40aad96e.d871f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":4440,"wires":[]}]
If you freate a new file where is it strored on the system? I just cant find any of the test files created

@gcgarner
Copy link
Owner

gcgarner commented Nov 2, 2019

Have a look at the screenshot below. And let me know if this makes it clearer. I just made a wiki entry on this. wiki link

The file name i specified was /data/test.txt and in the terminal I listed the files in ls ~/IOTstack/volumes/nodered/data

anything that gets created in the container in the /data folder appears in ~/IOTstack/volumes/nodered/data

Have a look at the docker-compose.yml file, it shows for each container (service) where the host file system is mapped to the container file system.

image

@gcgarner
Copy link
Owner

gcgarner commented Nov 2, 2019

Here is another two ways:
1 using hard links)
Linux gives you the ability to make links. So i can make link from a file in my home directory into the host using the ln source destination. You can link any file or directory into the container file system. Problem is are you going to remember what you linked and where in 6 months time? And Hard links are really difficult to trace.

image

2 using the volume command)
This one would be the better option.
The other method is you can simply use the docker-compose.yml file to make a link for you. In when you forget where you saved it you can easily go find it

    volumes:
      - ./volumes/nodered/data:/data
      - ~/myfolder/:/share

the next time you run docker-compose up -d it will create a new directory in nodered called /share and any files that were in ~/myfolder would be visible in the container

@Paulf007
Copy link
Contributor Author

Paulf007 commented Nov 3, 2019

Thank you Graham for the explanation the wiki cleared it up quite well. I guess one is getting near attempting to cater for "personal needs" and that would not be feasible.
One thought thou :
Looking at option 2 would it not be a good idea to have the shared folder linked for all the containers that could use it. That way you will have a central "data" folder that could link the applications.
Personally I think Openhab , Node red and Home Assistant could benefit from this.

@gcgarner
Copy link
Owner

gcgarner commented Nov 3, 2019

I think you hit the nail on the head with "personal needs" getting one solution that will fit everyone is very tricky. And so does sharing volumes between containers. Its quite easy to do the link but to make sure everyone has the correct read and write permissions is tricky.

And the whole point about containers are they are supposed to be separate from the host and each other for security...

@Paulf007
Copy link
Contributor Author

Paulf007 commented Nov 3, 2019

I agree but as Openhab / Home Assistant in quite a lot of cases use node-red as rules engine it could be a useful addition else maybe an alternative install.

@gcgarner
Copy link
Owner

gcgarner commented Nov 3, 2019

I'm not familiar with hassio, what would be a typical use case where you would need to share files between it and nodered? I can always find a way to get it working

@Paulf007
Copy link
Contributor Author

Paulf007 commented Nov 3, 2019

I use Openhab so with node-red I do most of my custom rules. The one way is that I have a network scan app that scans the network every x time. It then logs the Ip's extra. Once all is done I use node-red to write a simple index file to Openhab via Node red with MQTT. That way I keep track of all "custom" stuff. I also use a couple of TXT files to keep track of important soft switches. So should the Pi Restart it will read the last command status from the txt file (These used to be in Openhab so I moved it to the data file.).

As a note the more I think about it the more I think we could hold for a moment, at least until someone else also ask for the same thing, There quite a bit of other work that can take precedence over this.

@Paulf007 Paulf007 closed this as completed Nov 3, 2019
@gcgarner
Copy link
Owner

gcgarner commented Nov 3, 2019

I think working in containers have some limitations. A quick look on the web and i found this on persistent variables in nodered. But for keeping logs a SQL database would work. That is just another thing to learn unfortunately as you are familiar with your workflow.

If another request comes in then it will be worth while making something available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants