Hello,
I am using the following script to shutdown or reboot my MotionEyeOS installation based on GPIO-Pins:
open SSH connection to MotionEyeOS (bash), mount the folder writable:
• > mount -o remount,rw /
• > nano /usr/sbin/checkGPIOshutdownReboot.py
• copy script into editor, save and close the editor (ctrl-o, Return, ctrl-x)
• make the script executable:
• > chmod +x /usr/sbin/checkGPIOshutdownReboot.py
• check it by running it from bash: python /usr/sbin/checkGPIOshutdownReboot.py
• make the script autostart at every reboot (I gave it 300 seconds delay - in case of any troubles I would be able to open again ssh connection and stop the script)
• > nano /data/etc/userinit.sh
• copy the following into userinit.sh
• (/bin/sleep 300 && python /usr/sbin/checkGPIOshutdownReboot.py)&
Script checkGPIOshutdownReboot.py:
#!/usr/bin/python3
# HW-Pin-Zaehlung verwendet!!
# FHEM: /home/scripts/checkGPIOshutdownReboot.py
# MotionEyeOS: /usr/sbin/checkGPIOshutdownReboot.py
# MotionEyOS: mount -o remount,rw /
import os, sys, time, RPi.GPIO as gpio
gpio.setmode(gpio.BOARD) # Pin-Nummern des P1/J8-Headers
# chan_list = [5,40]
# gpio.setup(chan_list, gpio.IN, pull_up_down = gpio.PUD_UP)
gpio.setup(5, gpio.IN, pull_up_down = gpio.PUD_UP) # Pin 5 ist Reboot - 3. Reihe
gpio.setup(40, gpio.IN, pull_up_down = gpio.PUD_UP) # Pin 40 ist Poweroff - letzte Reihe bei USB Buchse
while 1:
print "checking..."
if gpio.input(5)==gpio.LOW:
print "ok - reboot now"
os.system("reboot")
sys.exit()
if gpio.input(40)==gpio.LOW:
print "ok - power off now"
os.system("poweroff")
sys.exit()
time.sleep(5)
Good luck :)
cheers.