I have a cluster of Pis that sometimes one of them fails and I cannot access it remotely until I come to the device and unplug and plug it again. I want a solution that if a Pi fails, I can remotely restart it. I learned that some people use a button in between for restarting but this still needs me to be present. I also see that some people connect GPIO 3 + Ground to restart using a button in between. But, this solution also needs access to the Pi which is impossible when it has failed. Is there a way that I can restart the Pi by connecting a wire from its pins to the pins of a spare Pi and command the spare Pi to reboot the failed Pi? I mean everything by coding without a button or relay, so it does not need me to be present for a reboot.
A working example. I have two Pi 3. I wire is connected on one end to the first Pi on GPIO 17 and on the other end on the 'Run' pin. I have the following code on the first Pi.
#!/usr/bin/env python3
import RPi.GPIO as GPIO
import time
PIN=17
GPIO.setmode(GPIO.BCM) # set the pin numbering scheme to BCM
GPIO.setup(PIN, GPIO.OUT) # set up GPIO 17 as an output
GPIO.output(PIN, GPIO.LOW) # trigger the restart by pulling GPIO 17 low
time.sleep(1) # wait for 1 second
GPIO.output(PIN, GPIO.HIGH) # release GPIO 17 to allow the Raspberry Pi to start up
# release the GPIO channel
GPIO.cleanup(PIN)
TBH, I got this from ChatGPT. When I run this code, the second Pi gets restarted. I think this is considered a hard restart. My question is that,
- 1- Is this an appropriate solution to get a crashed Pi that you cannot even SSH to back?
- 2- Is there a better way to soft restart the second Pi using the first Pi? (Assume the second Pi has crashed and we cannot SSH and we do not want to physically unplug or change wirings)
- 3-This only worked on Pi 3 and did not work on Pi 4, why?