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()
lukenm
  • 193
  • 2
  • 2
  • 7

1 Answers1

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)
joan
  • 71,024
  • 5
  • 73
  • 106