[SOLVED] Adafruit permission denied

Hi there

I’m running openhab 2 on a raspberry pi 3+ series and getting a permission denied error in my .rules file when I call the adafruit library for ws2801 and gpio.

I accidentally installed the adafruit package under a local user account so the openhab user can not access it causing the error.

How do I fix this permission issue?

Thanks,
Tony.

Use chmod and chgrp to add group permissions for the openhab user.that is the simplest answer.

Google the two commands there is plenty of help. You will need something like chmod 755 somefiles this will give rwx permissions for owner and read execute for group.

You may need to change the group with chgrp though. Without more info in your file structure hard to give precise commands.

It may not hurt to install the library in a common area, if it is not already in a common area.

Thanks @Thedannymullen!

I’ve tried changing permissions with no joy.

I’ve used chmod +X on the package folder and I’ve added openhab user to the spi group.

I was hoping to just uninstall the adafruit package and then reinstall under the root account. Just not sure how to do that.

Your thoughts?

@OpenHabitat - Hello (I assume this is a continuation of the discussion we had in the comments of my video? :wink:

@Thedannymullen - I don’t have experience using external libraries with OH on RPI, but shouldn’t they be placed in the openhab-sys/runtime/lib folder? Wouldn’t that place it in a folder that already has permissions for the openhab user (would still likely require a chmod to the .lib file itself for openhab to access), i.e.:

chown adafruit.lib openhab
1 Like

@OpenHabitat try what bk said. Also if you did chmod +x directory this usually only does the top level you may need the recursive flag possibly to get the files underneath.

1 Like

@bartus wow you found me!! LOL…

Will absolutely try these suggestions and report back!

1 Like

Trying:

chmod +x /usr/local/lib/python3.5/dist-packages/Adafruit_GPIO

as this is the directory I get permission denied.

And…no dice!

I get this permission error:

File "/home/openhabian/HomeAutomation/FireplaceLED/ws2801color.py", line 20, in <module>

    pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE), gpio=GPIO)

  File "/usr/local/lib/python3.5/dist-packages/Adafruit_GPIO/SPI.py", line 42, in __init__

    self._device.open(port, device)

PermissionError: [Errno 13] Permission denied

Sorry - add “sudo” in front of the statement

1 Like

Also recursive -r or -R I don’t remember

1 Like

So that worked, thanks!

sudo chmod +x -R /usr/local/lib/python3.5/dist-packages/Adafruit_GPIO

So the permission error has gone, and now I get this:

File "/etc/openhab2/scripts/ws2801color.py", line 8, in <module>

    import Adafruit_WS2801

  File "/usr/local/lib/python3.5/dist-packages/Adafruit_WS2801/__init__.py", line 1, in <module>

    from .WS2801 import *

  File "/usr/local/lib/python3.5/dist-packages/Adafruit_WS2801/WS2801.py", line 24, in <module>

    import Adafruit_GPIO.SPI as SPI

  File "/usr/local/lib/python3.5/dist-packages/Adafruit_GPIO/__init__.py", line 3, in <module>

    from Adafruit_GPIO.GPIO import *

ImportError: No module named 'Adafruit_GPIO.GPIO'

Seems there is something missing from the library?

And now its started popping this error:

File "/home/openhabian/HomeAutomation/FireplaceLED/ws2801color.py", line 20, in <module>

    pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE), gpio=GPIO)

  File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/SPI.py", line 42, in __init__

IOError: [Errno 13] Permission denied

Hmm seems it does not like accessing libraries from the local user directory…

Final ditch effort :slight_smile:
I copied my script to so it has local access to adafruit library:
/usr/local/openhab_scripts/fireplace

But I get this crazy import error again…

 File "/usr/local/openhab_scripts/fireplace/ws2801color.py", line 8, in <module>

    import Adafruit_WS2801

  File "/usr/local/lib/python3.5/dist-packages/Adafruit_WS2801/__init__.py", line 1, in <module>

    from .WS2801 import *

  File "/usr/local/lib/python3.5/dist-packages/Adafruit_WS2801/WS2801.py", line 24, in <module>

    import Adafruit_GPIO.SPI as SPI

  File "/usr/local/lib/python3.5/dist-packages/Adafruit_GPIO/__init__.py", line 3, in <module>

    from Adafruit_GPIO.GPIO import *

ImportError: No module named 'Adafruit_GPIO.GPIO'

First question can you run the commands from command line as another user?

1 Like

Yes I have - I think im getting really close now:

var String ResultOutput = executeCommandLine("sudo -u openhab /usr/bin/python3 /etc/openhab2/scripts/ws2801color.py " + red.toString + " " + green.toString + " " + blue.toString ,1000) 

Now the error I get is:

openhab is not in the sudoers file.  This incident will be reported.

I’ve added openhab user to the sudo group, but I think it might be prompting for a password when the script gets executed?

OK I found the solution and how is working!!

Here were my steps:
TO fix the permission error:

Based on: OpenHAB sudo [Exec Binding]

  1. sudo chmod +x /etc/openhab2/scripts/ws2801color.py

  2. sudo addgroup openhab spi

  3. sudo pip3 uninstall adafruit-ws2801
    (then remove any adafruit files and libraries found in /usr/local/lib/python3.5/dist-packages/)

  4. sudo visudo -f /etc/sudoers.d/010_pi-nopasswd

  5. type in the file:
    openhab ALL=(ALL) NOPASSWD: ALL
    (this ensures that no password will be prompted when running the script)

Thats it!

Enjoy some LED stip craziness!

1 Like

As stated in the post above it is not recommended to give sudo rights to openhab.

Add the user openhab to the group gpio and spi.

sudo adduser openhab gpio
sudo adduser openhab spi

Logout and log in again or just restart the pi for the user rights to take effect.

Try if the changes work out by executing your command in the commandline as user openhab.

sudo -u openhab  /usr/bin/python3 /etc/openhab2/scripts/ws2801color.py ...

If it works remove the sudo from the commandline.

var String ResultOutput = executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/ws2801color.py " + red.toString + " " + green.toString + " " + blue.toString ,1000) 
1 Like