Plusbery Pi shutdown script

Hello, i bought plusberry pi box for my pi2.(Plusberry Pi - Media Box running on Raspberry Pi | Indiegogo)
i try a script for shutdown with te box button whith google search.

My “.off_button.py” in /home:

#!/bin/python
#This script was authored by AndrewH7 and belongs to him (www.instructables.com/member/AndrewH7)
#You have permission to modify and use this script only for your own personal usage
#You do not have permission to redistribute this script as your own work
#Use this script at your own risk

import RPi.GPIO as GPIO
import os

gpio_pin_number=24
#Replace YOUR_CHOSEN_GPIO_NUMBER_HERE with the GPIO pin number you wish to use
#Make sure you know which rapsberry pi revision you are using first
#The line should look something like this e.g. “gpio_pin_number=7”

GPIO.setmode(GPIO.BCM)
#Use BCM pin numbering (i.e. the GPIO number, not pin number)
#WARNING: this will change between Pi versions
#Check yours first and adjust accordingly

GPIO.setup(gpio_pin_number, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#It’s very important the pin is an input to avoid short-circuits
#The pull-up resistor means the pin is high by default

try:
GPIO.wait_for_edge(gpio_pin_number, GPIO.FALLING)
#Use falling edge detection to see if pin is pulled
#low to avoid repeated polling
os.system(“sudo shutdown -h now”)
#Send command to system to shutdown
except:
pass

GPIO.cleanup()
#Revert all GPIO pins to their normal states (i.e. input = safe)

and my rc.local in /etc

#!/bin/sh -e

rc.local

This script is executed at the end of each multiuser runlevel.

Make sure that the script will “exit 0” on success or any other

value on error.

In order to enable or disable this script just change the execution

bits.

By default this script does nothing.

python /home/.off_button.py

exit 0

at boot i see this message:Failed to start /etc/rc.local Compatibility.

(i"am new in linux) Please help me , the support of plusberry on indiego is too long !
thank’s

please i need help !

The monitoring script the PlusberryPi developers posted for OpenELEC seems to work for me. I’m starting the monitoring script manually for now (sudo bash shutdown.sh) but will investigate the proper way to make this auto-start.

http://plusberrypi.com/setting-up-the-shutdown-button/

#!/bin/bash
# monitor GPIO pin 24 (wiringPi pin 1) for shutdown signal
# export GPIO pin 24 and set to input with pull-up
echo "24" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio24/direction
# wait for pin to go low
while [ true ]
do
if [ "$(cat /sys/class/gpio/gpio24/value)" == '0' ]
then
echo "Raspberry Pi Shutting Down!"
halt &
exit 0
fi
sleep 1
done

Ok, i think this works but don’t shoot the messenger if it doesn’t. Actualy i’m fairly sure this IS NOT WORKING as expected. Fairly sure it’s just turning off the power without shutting down the OS nicely.

SSH into your Pi and create the shutdown script somewhere, i just made mine in my user directory (/home/osmc).
nano shutdown.sh

Copy/paste in the shutdown script;

#!/bin/bash -
# monitor GPIO pin 24 (wiringPi pin 1) for shutdown signal
# export GPIO pin 24 and set to input with pull-up
echo "24" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio24/direction
# wait for pin to go low
while [ true ]
do
if [ "$(cat /sys/class/gpio/gpio24/value)" == '0' ]
then
 echo "Raspberry Pi Shutting Down!"
 halt &
 exit 0
fi
sleep 1
done

Mark the shutdown script as executable
sudo chmod +x shutdown.sh

Create a systemd service file to auto-start the shutdown script
sudo nano /etc/systemd/system/plusberrypi.shutdown.service

Copy/paste this into the systemd serivce file

[Unit]
Description=PlusberryPi shutdown button watchdog

[Service]
TimeoutStartSec=0
ExecStart=/home/osmc/shutdown.sh

[Install]
WantedBy=multi-user.target

Enable the systemd service
sudo systemctl enable /etc/systemd/system/plusberrypi.shutdown.service

Start the systemd service
sudo systemctl start plusberrypi.shutdown.service

1 Like

Thank’s a lot!
i will try. (this for shutdown with the button)

is this possible to power down the plusberry pi with a scrpit when i shutdown by osmc menu ?

No, apparently that will never work. The PlusberryPi can tell the Pi when the button is pressed but the Pi can’t tell the PlusberryPi when it’s ready for power to be turned off.

You can turn off the Pi via the menu and then do a long press on the PlusberryPi power button to shut off the power, that is the safest way to go for now till the shutdown script is working properly.

Ok! Thank’s!

how can i control by ssh that the O S close before the plusberry power down ?

That’s something I’m still looking at. There seems to be a non-configurable time delay of 7 to 8 seconds from pressing the power button on the PlusberryPi to the power being cut off and I’m not sure if that’s really going to be sufficient to shut OSMC down properly.

i have a look at this:Support for RemotePi Board 2015 and RemotePi Board Plus 2015