[Solved] Octoprint-Filament-Reloaded-OrangePi

I'm having an issue with this plugin: Octoprint-Filament-Reloaded-OrangePi

The board is an orange pi zero plus (H5) Armbian:

pi@octo:~$ uname -a
Linux octo 4.14.65-sunxi64 #6 SMP Mon Aug 20 20:01:45 CEST 2018 aarch64 GNU/Linux

The following error appears in the log:

"IOError: [Errno 13] Permission denied: '/sys/class/gpio/gpio14/direction'"

The plugin appears to set up the pin correctly via:

pi@octo:~$ cat /sys/class/gpio/gpio14/direction
in

ls -al  /sys/class/gpio/
-rwxrwx---  1 root gpio 4096 Aug 27 20:07 export
lrwxrwxrwx  1 root root    0 Aug 27 20:16 gpio14 -> ../../devices/platform/soc/1c20800.pinctrl/gpiochip1/gpio/gpio14
lrwxrwxrwx  1 root root    0 Dec 31  1969 gpiochip0 -> ../../devices/platform/soc/1c20800.pinctrl/gpio/gpiochip0
lrwxrwxrwx  1 root root    0 Dec 31  1969 gpiochip352 -> ../../devices/platform/soc/1f02c00.pinctrl/gpio/gpiochip352
-rwxrwx---  1 root gpio 4096 Aug 27 19:55 unexport

The gpio permissions seem to be proper; I can do the following as pi user (without sudo):

pi@octo:~$ echo out | tee /sys/class/gpio/gpio14/direction
out
pi@octo:~$ echo in | tee /sys/class/gpio/gpio14/direction
in

As pi user, I can:

pi@octo:~$ echo out | tee /sys/class/gpio/gpio14/direction
out
pi@octo:~$ echo 0 > /sys/class/gpio/gpio14/value
pi@octo:~$ cat /sys/class/gpio/gpio14/value
0
pi@octo:~$ echo 1 > /sys/class/gpio/gpio14/value
pi@octo:~$ cat /sys/class/gpio/gpio14/value
1

Seems to be an issue with the plugin.

Thanks for your feedback.

if you look at the readme on the github of that plugin the issue is with the opi gpio library that had a race condition, here used to be a patch for that library that would allow it to properly work, but recently they fixed the library so if you have latest gpio library it will work ok ...

so from the readme:

OrangePI OS Configuration

Since we are accessing the GPIO as a non root user we need to configure the OS to allow this. Here's the copy of the library documentation on how to do it:

If you want to be able to use the library as a non root user, you will need to setup a UDEV rule to grant you permissions first.
This can be accomplished as follows:

$ sudo usermod -aG gpio <current_user>
$ sudo nano /etc/udev/rules.d/99-gpio.rules

That should add your user to the GPIO group, create a new UDEV rule, and open it in the Nano text editor.
Enter the following into Nano

  SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'" 
  SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"

press ctrl-x, Y, and ENTER to save and close the file.
Finally, reboot and you should be ready to use OPi.GPIO as a non root user.

Issues with OPI GPIO library

https://github.com/rm-hull/OPi.GPIO/pull/28 solves the issues with PI GPIO library and the race condition that was preventing normal operations. It is available in release v0.3.4 and up so make sure you have latest OPI GPIO library. To upgrade to latest OPI GPIO library login to your octoprint server as user pi and execute:

 $ cd OctoPrint/ 
 $ venv/bin/pip install --upgrade OPi.GPIO