File Lister node not returning filename unless Pi is logged in

Hi,

I'm trying to use the filename node to find a file on a USB drive and use this to tell the File Write node where to write to. However, this is not working unless the Pi is logged in and I'm getting a "File could not be Accessed" in the debug.

Any ideas how I can get this working? I need to keep the pi signed out so that it keeps the console etc secure.

Thanks,
Gregor

Have you checked the permissions on the file? Is Node-RED running under a user id that has access?

Thanks for the reply, how would I got about checking the permissions on the file?

The easiest way is to fire up a terminal on the Pi - personally I always use SSH - I never run the desktop on the Pi as it is too resource hungry.

Then:

ls -lah /mnt/usb

or whatever your usb drive is mounted as.

Actually, that could be the other issue. Possibly it is the desktop that is mounting the usb drive rather than the OS itself? Well, you will soon find out I guess.

I'm getting "ls: cannot access '/mnt/usb': No such file or directory"

That would be causing the problem :slight_smile:
How are you mounting your usb drive?

1 Like

I literally just plugged it in and the node red was able to write to it (when the Pi was signed in of course).

I've set up the flow so that if a USB containing the file "WriteFanData.txt" is not detected, it logs the data to the SD card as opposed to the USB

Check that it isn't something else. check if anything is mounted under /mnt

Otherwise, as I said, this indicates that only the desktop is auto-mounting the usb drive.

I'm afraid it's been a while since I thought about how to auto-mount USB drives under Linux, you will need to look that up.

So when I use "ls-lah /mnt" I get the result:

total 8.0K
drwxr-xr-x 2 root root 4.0K Apr 8 10:37 .
drwxr-xr-x 22 root root 4.0K Jun 6 09:49 ..

So basically, i need to set it up through ssh so that the OS is mounting the USB on boot, rather than it waiting for the desktop to mount the USB?

Yep, seems that you still don't get auto-mounting of usb drives!

sudo blkid

Will show you what is available:

pi@pi3:~ $ sudo blkid
/dev/mmcblk0p1: LABEL="boot" UUID="A365-6756" TYPE="vfat" PARTUUID="bf4e8db9-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="90a83158-560d-48ee-9de9-40c51d93c287" TYPE="ext4" PARTUUID="bf4e8db9-02"
/dev/mmcblk0: PTUUID="bf4e8db9" PTTYPE="dos"
/dev/sda1: LABEL="USB DISK" UUID="9B1A-3144" TYPE="vfat" PARTUUID="c3072e18-01"
pi@pi3:~ $

You can see there that I have a usb stick available called "USB DISK" (original I know!). So you can mount that.

References:

https://www.raspberrypi.org/forums/viewtopic.php?t=205016

In fact, here we go, this is what you need (from that first reference):

Installation steps of usbmount:

  1. Install the package:
sudo apt-get install usbmount
  1. Make sure it works in Stretch by changing MountFlags=slave to MountFlags=shared here:
sudo nano /lib/systemd/system/systemd-udevd.service
  1. Reboot

Thanks for that, I'll look into setting that up justnow.

One quick question about this, does this allow me to remove a USB and add another USB drive in its place or would I need to set up the auto-mount again for the new USB drive?

These Pi's are going to be used in remote locations with datalogging saved on the USB, and once in a while someone will go to site and swap the USB drives to allow us to get the information.

I think so. I think that I've used it in the past but I can't totally remember I'm afraid. I expect the docs will tell you.

Allowing dynamic USB use is something of a security issue so you should read up on that possibly depending on the criticality of the devices and their data.

I assume that the devices don't have network access otherwise that would, of course, be a much better option.

You should also remember that USB pen drives do fail with depressing regularity, especially if you are writing to them regularly. You should allow for regular replacement of the drives themselves and not leave it too long between swaps.

Hi,

Thanks for getting back to me. I've followed your instructions but it still isn't allowing Node-Red to read the file until I log into the Pi.

Is there another step (other than the sudo apt-get install usbmount and the sudo nano /lib/systemd/system/systemd-udevd.service and reboot) that I've missed?

I note that there are further suggestions further down the referenced post:

https://www.raspberrypi.org/forums/viewtopic.php?t=205016#p1479794

Maybe try those? I set it up a long time ago and only on my aging Pi2 not on the newer Pi3. So I don't remember everything that I did.

Thanks for your help so far.

I think I've managed to get it to mount without signing in as a sudo cat /proc/mounts shows /dev/sda1 /media/usb0 vfat rw, sync, nodev, noexec, noatime, nodiratime, fmask=0022, dmask=0022, codepage=437, iocharset=ascii, shortname=mixed, errors=remount-ro 0 0

I don't quite understand what this means but the fact it can see my drive seems promising.

However, I still am unable to write to it with node-red until I sign in.

Is there possibly a way to use Node-Red to mount the drives using the Exec function?

I'm out of my depth here so just grasping at straws.

Thanks

Tested it with my flow and it appears that the file lister node can now see the files, however I can no longer edit/delete/append the files - even when logged in. It doesn't allow me to edit the files even when using the GUI. I'm not sure how I've managed to do this.

permissions... go back up this thread to where how to check was previously mentioned

Using ls -lah /media/usb0 returns

total 52K
drwxr-xr-x 4 root root 16K Jan 1 1970 .
drwxr-xr-x 13 root root 4.0K Jun 25 10:33 ..
drwxr-xr-x 4 root root 16K Jun 12 15:55 logs
drwxr-xr-x 2 root root 16K Jun 11 10:34 System Volume Information
-rwxr-xr-x 1 root root 0 Jun 5 13:57 WriteFanData.txt

I notice that everything is set to "root root", as I sign in through the "pi" user how would I edit these permissions so that node-red can access these files?

To get it to be able to read the file I've used:

apt-get install udisks-glue policykit-1

sudo nano /etc/udisks-glue.conf

and then changed the file to match:

filter disks {
    optical = false
    partition_table = false
    usage = filesystem
}

match disks {
    automount = true
    automount_options = { sync, noatime, dmask=0000}
}

I still can't get Node-Red to write to the file.

1 Like