Recently, I have seen an issue where my router is losing its internet connection for an extended period. The way that I have noticed to fix this is to reboot the router by unplugging it from the wall. If I don’t do that, it can take forever to come back on its own. Other than this issue, I can’t complain about the service with U-Verse. From the speed test below, you can see that it is pretty fast.
To get around the random router hangs, I put an SSR that I have lying around to use. I have these from a Christmas light project that I was working on, and they were pretty cheap and easy to build. They are DirkCheapSSRs. I remembered that I could trigger them from my Raspberry Pi that is already running on the network. The Raspberry Pi runs PiHole, and it is already sitting next to the router. I wrote a small python script to trigger the GPIO pins on the Raspberry Pi based on certain conditions. Essentially, the Pi cycles the power on the router based on it being able to ping google.com, and it checks for the ping every five seconds. If the ping fails, it waits ten minutes before it starts the check again.
from __future__ import print_function import RPi.GPIO as GPIO, time, os log = open("/home/pi/reboot/logs/reboot.log","a") GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) try: while True: if os.system("ping -c 1 google.com") != 0: print('Ping failed. The router is being rebooted.', file = log) GPIO.output(18,GPIO.HIGH) time.sleep(5) GPIO.output(18,GPIO.LOW) time.sleep(600) else: GPIO.output(18,GPIO.LOW) time.sleep(5) except KeyboardInterrupt: print('Program quit.', file = log) finally: GPIO.cleanup()
Here is a picture of the Raspberry Pi and the SSR in the closet. I could technically control all four outputs on the SSR, but I am only using one at the moment. I had to change my Pi’s case some because it didn’t have access to the GPIO pins.
The cheapest way that I could find to do this when searching was around $100. From what I remember, the DirkCheapSSR cost me around $7 with the case.