1

I have a python script (taken from the forums here) that reboots my RPI when a button is pressed.

It works great, no issues, except that it refuses to start automatically (either on boot, login, anything). I have tried various options listed here (rc.local, .bashrc, idit.d tab, systems, crontab) and nothing seems to work.

Is it something as simple as my script actually not being very good, and something in there is stopping it from working?

 #!/usr/bin/python
import RPi.GPIO as GPIO
import time
import os
def button_callback(channel):
 print("Button was pushed!")
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def Restart(channel):
 os.system("sudo shutdown -r now")
GPIO.add_event_detect(16,GPIO.RISING,callback = Restart, bouncetime = 2000)
message = input()
GPIO.cleanup()
asked Apr 12, 2020 at 15:22
2

1 Answer 1

1

At a guess the script is immediately terminated when run in the background because of the message = input() line. The script's input and output will not be set to the devices you expect (screen and keyboard).

Replace that line with an eternal while loop. Something like the following.

while True:
 time.sleep(60)
answered Apr 12, 2020 at 15:30
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.