Last active
January 20, 2022 08:05
-
-
Save tomoto/2c301abb34f7603e286a141b74993a4d to your computer and use it in GitHub Desktop.
Raspberry Pi Shutdown Button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import RPi.GPIO as GPIO | |
import subprocess | |
import time | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
while True: | |
GPIO.wait_for_edge(3, GPIO.FALLING, bouncetime=100) | |
if GPIO.wait_for_edge(3, GPIO.RISING, timeout=2900) is None: | |
subprocess.call(['wall.sh', "THE SYSTEM IS SHUTTING DOWN"], shell=False) | |
time.sleep(3) | |
subprocess.call(['shutdown', '-h', 'now'], shell=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
for f in /dev/pts/[0-9]* | |
do | |
echo "Broadcast message from $(whoami)@$(hostname) ($(date +'%a %b %d %H:%M:%S %Y')):" > $f | |
echo $* > $f | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This modification is made on this article https://howchoo.com/g/mwnlytk3zmm/how-to-add-a-power-button-to-your-raspberry-pi , in order to require the button to be pressed for 3 seconds and broadcast the message to the virtual terminals on GUI before shutting down.