Here we try to fix up the permissions for accessing the digital photo frame I am using to display information about what is playing.
After a great deal of effort to build dpf-ax for the 7DayShop Pebble photo frame, it was a bit disappointing to only be able to access it as root - If I try to access it as a normal user, then it fails. I have to use sudo to get access.
Here's some things I found out:
- Both the Python and C libraries allow you to connect to the dpf either as a SCSI device or a USB device
- However, after you have hacked the photo frame, it does not seem to want to appear as a SCSI device any more, so your only option is to access it as a USB device.
- Normally the system would set a USB device with relaxed permissions so users could access it. However the the photo frame is not being managed by the system, so has the restrictive default access applied. Only root can read and write to it.
- We (i.e. the C/Python libraries) need to write to it, so try to open it with write permissions. Because only root can write to the device, this fails unless you run as root.
Here's how I fixed it on my Ubuntu machine (fix still pending on Pi)
Notes included with reference to revision 40 of dpf-ax
- Find the device, all of these photo frames seem to have a vendor ID of 1908 and a device ID of 0102. This particular one has no description string.
dpflib note - It is the vendor ID and device ID that the library looks for in usbraw.c. If it does not find it you get the "No matching USB device found!" error. If it cannot open the device once it finds it (e.g. because there is a permissions problem) then you get "Failed to claim usb device!"$lsusb
Bus 002 Device 006: ID 1908:0102
$ls -l /dev/bus/usb/002crw-rw-r-- 1 root root 189, 133 2013-03-06 19:19 006
You get the Bus number and device number from lsusb to use in the ls command to see what the permissions are. - So that's the problem. To fix it - you first need to make a new group and add to that group all the users you want to access the device, and root as well.
$sudo groupadd lcdusers
$sudo adduser pi lcdusers
$sudo adduser rootlcdusers - Then you have to add a udev rule. A udev rule basically gets run every time there's some interesting activity with the connected devices, including when the device boots up. This new rule I'm adding will give the group above read and write access to the photo frame usb device, and since pi is a member of that group, he should get write access as well.
Put this single line in the file and save it:$sudo gedit /etc/udev/rules.d/70-dpf.rules
ATTRS{idVendor}=="1908", ATTRS{idProduct}=="0102", GROUP="lcdusers", MODE="0660"
- That should be it as the change is supposed to be picked up, but I found I had to restart because the device vanished and the dpf library could no longer find it, it came back after the restart. Now:
This wills show that it's worked - anyone in the group lcdusers can both read and write to the device, you can go ahead and access the screen via the library with no sudo.$ls -l /dev/bus/usb/002crw-rw---- 1 root lcdusers 189, 129 2013-03-06 19:53 002