Router's / modem's / ISP connections tend to need a kick once in a while. Here's my setup to give my gear a kick when my server can no long ping a site (google.com).
The circuit is pretty basic. An opto-coupler takes the signal from a pin off the parallel port, isolates it and feeds it into a transistor which boosts the current high enough to pull a relay in. The relay is setup to be normally closed. This way minimal power is used for normal state.
The following script runs every 10 minutes. It tests a ping to google - twice, in case the first one was a false postive. If both fail to come back, it pulls the pin high for 30 seconds. It pauses for 2 minutes to give the gear a chance to restart. It tests again. If successful, I'm notified. If not, it gives up.
#!/usr/bin/perl
#
use strict;
use warnings;
use Device::ParallelPort;
if (`ping -c 1 google.com | grep "1 received"`)
{
# print "\nALIVE\n";
} else {
print "Dead?\n";
sleep(10);
if (`ping -c 1 google.com | grep "1 received"`)
{ ; } else {
# restart process
print "DEAD!\n";
my $port = Device::ParallelPort->new();
# toggle bit 0 ON
$port->set_bit(0,1);
print "Bit 0 ON\n";
# wait 30 seconds
sleep(30);
# toggle bit 0 OFF
$port->set_bit(0,0);
print "Bit 0 OFF\n";
sleep(120);
if (`ping -c 1 google.com | grep "1 received"`)
{
print "Success!\n";
my $t_commTime = time;
system("/home/alex/furnace/tweet d ehud42 Communication restared at time stamp: $t_commTime");
} else {
print "Left for dead\n";
}
}
}
A clip of the gadgetry working on my bench: