I followed the instructions from howto-manually-add-gpio-openelec-raspberry-pi-2-without-addon on a button to shut down and restart my Pi. It only works if I am in Putty and actually start the script first but wont work after that. I've added the RaspiTools Addon bundle and tried it that way and it didin't work that way either so was wondering if anyone got this working on libreelec and could tell me what I am doing wrong? Here is how I wrote the code. I then put it in autostart.sh. Any help would be appreciated.
Code
[code]
#!/usr/bin/python
import sys
sys.path.append('/storage/lib')
import RPi.GPIO as GPIO
import time
import subprocess
# we will use the pin numbering to match the pins on the Pi, instead of the
# GPIO pin outs (makes it easier to keep track of things)
GPIO.setmode(GPIO.BOARD)
# use the same pin that is used for the reset button (one button to rule them all!)
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)
oldButtonState1 = True
while True:
#grab the current button state
buttonState1 = GPIO.input(5)
# check to see if button has been pushed
if buttonState1 != oldButtonState1 and buttonState1 == False:
subprocess.call("shutdown -h now", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
oldButtonState1 = buttonState1
time.sleep(.1)
Display More
[/code]