-
First cut at a python watchdog script
10/23/2019 at 21:50 • 1 commentYou'd run this out of cron, like, every few hours:
#!/usr/bin/python import RPi.GPIO as GPIO import sys import time import subprocess import os import random hosts = ["1.1.1.1", "8.8.8.8", "9.9.9.9"] random.shuffle(hosts) FNULL = open(os.devnull) for host in hosts: res = subprocess.call(["ping", "-c", "3", "-W", "5", host], stdout=FNULL, stderr=FNULL) if (res == 0): sys.exit(0) # it worked. Bail print "All hosts unreachable - resetting router" reset_pin = 18 # Perform the reset operation GPIO.setmode(GPIO.BCM) GPIO.setup(reset_pin, GPIO.OUT, initial=GPIO.LOW) time.sleep(2) GPIO.cleanup() sys.exit(1)
This assumes you're using GPIO pin 18, but you can select any free one you like.
It's probably not entirely kosher to just ping those hosts, so to insure that you don't wind up in hot water, you should only run this script VERY sparingly. And it wouldn't be a bad idea to maybe pick different hosts - hosts close enough to be a good test for whether your router is up or not.
-
Initial cut
10/23/2019 at 21:14 • 0 commentsThe first cut of the hardware design and firmware is done. The boards have been ordered and we'll see what comes of it.
The board's firmware is very paranoid about the signaling it receives. The input needs to be asserted for a full second before the power is cycled, and then it has to remain de-asserted for a full hour before a reboot can be reattempted.
The firmware is paranoid because the signaler in this case is going to be a Linux box, and in general my trust of such systems is... measured.
In any event, the two wires from the control input are ground and an arbitrary GPIO pin. If you want to reboot the router, you set the pin to an output and assert it low for 2 seconds then release it (the normal state for GPIO pins is high impedance, which for us is de-asserted).
Having done that, you must not attempt to do so for at least an hour, as any attempts in the meantime will reset the hour hold-off timer, potentially extending it into perpetuity.
So in principle, what's called for here is a cron job. That job should attempt to ping a bunch of Internet places of interest, and if any of them succeed, you're done. If all of them fail, then you hit the history eraser button.