Hi guys,
I just wanted to let you know that I spent around 4 hrs to make my new OnOFF SHIM running on my RPi 3 with LibreELEC 12.0.2. I tried to use the scripts described in the thread [How to] Pimoroni OnOff SHIM with LibreELEC but it didn't work.
First of all, I had troubles to run the shell scripts because the GPIO points were incorrect.
Secondly, when making a Python script, I had troubles with RPi.GPIO which was replaced by gpiozero.
Ad.1.
While preparing a shell script, I found out that in order to define the GPIO point correctly, you have to add a value of 512 to the number of the GPIO point.
So my shutdown.sh file looks like this now:
#!/bin/sh
#
if [ "$1" != "reboot" ]; then
poweroff_pin="516"
led_pin="529"
trigger_pin="529"
echo $trigger_pin > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio$led_pin/direction
for iteration in 1 2 3; do
echo 0 > /sys/class/gpio/gpio$led_pin/value
sleep 0.2
echo 1 > /sys/class/gpio/gpio$led_pin/value
sleep 0.2
done
sleep 2
echo $poweroff_pin > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio$poweroff_pin/direction
echo 0 > /sys/class/gpio/gpio$poweroff_pin/value
fi
Display More
And after it shuts down RPi, it cuts of the power. So there is a success.
Ad.2.
There was a problem with python script. As the script itself, when running from shell, worked like a charm- if I clicked the button, it would shut down the environment. But when the script was executed automatically, there were some errors in the systemctl logs.
Anyway, my off.py script looks like this now:
#!/usr/bin/python
from time import sleep
import sys, os, time
sys.path.append("/storage/.kodi/addons/virtual.rpi-tools/lib")
from gpiozero import Button
from signal import pause
os.environ['LG_WD'] = '/tmp'
button = Button(17)
def shutdown():
os.system("sync")
time.sleep(1)
os.system("shutdown -h now")
sys.exit()
button.when_pressed = shutdown
pause()
Display More
The most important thing was to put that os.environ['LG_WD'] thing so that the internal processes got writable rights to operate in temporary folder and so the script could start running in the background.
Finally, I created the autostart.sh and entered a line:
So now, I can use the button to shut down the system - the python script initiates the shutdown pocess which cuts of the power eventually. If I use the option within the libreELEC environment, RPi runs the shell script directly.
I hope this decent post will help someone else who uses the OnOff SHIM by Pimoroni.
Best Reagards,
Przemek