Hi sonycman,
here's the poweroff script:
- Code: Select all
#!/usr/bin/env python2
# hw-poweroff.py
import RPi.GPIO as GPIO
# import time
import subprocess
GPIO.setmode(GPIO.BCM)
# Select unused GPIO header pin to be used for shutdown
InputPin = 26
# Set selected pin to input, and enable internal pull-up
GPIO.setup(InputPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Wait for a button press on the selected pin (pulled to ground, falling edge)
GPIO.wait_for_edge(InputPin, GPIO.FALLING)
# When pressed, execute a shutdown, or any other command
print "*** Soft shutdown activated ***"
subprocess.call("shutdown now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# End of program
And here the service file to start that at boot:
- Code: Select all
[Unit]
Description=RuneAudio Poweroff
After=mpd.service
[Service]
ExecStart=/usr/bin/python2 /home/root/hw-control/hw_poweroff.py
[Install]
WantedBy=multi-user.target
It's gonna be interesting how you will manage to completely
and safely cut power from the Pi with a script. Looking forward to that!
@
breizheau:
I can try to guide you through the coding part, although my focus is more on the hardware side too and i'm also copy pasting code snippets.
Do you know the basic unix commands to navigate in your filesystem?
If not here they are:
https://wiki.archlinux.org/index.php/core_utilities#Basic_commandsYou will mainly use cd, cp, ls, nano (text editor) and chmod +x
Use
cd.. to move up 1 directory and
cd /root to get to your home directory
I have created a directory for all my script in /root
If you want a script to be started at boot you have to create a service file like the one above in this directory:
- Code: Select all
/usr/lib/systemd/system
For both script and service it is important to make them executable with
- Code: Select all
chmod +x
I
think, that with the latest runeuadio installation you won't need anything more to install to run a simple python2 script like the one above, maybe be Frank can confirm that?
To try out whether a script works, you can simply type
- Code: Select all
python2 scriptname.py
Is that about what you needed to start off?
Cheers and i am glad to help,
P