Apr 102012
 

I’ve got a piece of crap wireless network device. It disconnects or the server part just locks up, or dies, or I have no idea, but it stops working. I am not fond of this behavior. It seems to work pretty well after it’s reset. It could be any misbehaving device like a modem, router, wireless cam, network security camera, bridge, or repeater.

This runs on my linux box running ubuntu server. It runs the job every 5 minutes, pings the crap device and the router. If the router has reset itself (very crappy unreliable century link DSL service) it makes note of this. The router usually comes back within 5 minutes.

If the device has stopped responding to ping and the router is up, it uses my CM11a X10 interface with heyu to turn off the appliance module the crap device is plugged in to. It’s not nice on the crap device, but beating on its power supply is a fair punishment for just stopping work after about a week.


raging@watchdog:~$ crontab -l

# m h  dom mon dow   command
*/5 * * * * /usr/bin/perl /usr/local/bin/pingtest.pl >> "/tmp/pingtest.log" 2>&1

raging@watchdog:/usr/local/bin$ cat pingtest.pl

Advertisement:
#!/usr/bin/perl
use Net::Ping;

$device = "a5";
$host = "192.168.1.80";
$router = "192.168.1.1";

$kill_it = "/usr/local/bin/heyu off $device";
$start_it = "/usr/local/bin/heyu on $device";

$p = Net::Ping->new();
$pr = Net::Ping->new();
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
printf "%02d/%02d/%4d\t%02d:%02d:%02d\t", $month + 1, $dayOfMonth, $yearOffset + 1900, $hour, $minute, $second;

if ( !($pr->ping($router)) ){
print "$router down.\n";
}

if ( $p->ping($host) ){
        print "$host is alive.\n";
} else {
        sleep(15);
        if ( $p->ping($host) ){
                print "$host is sort of alive.\n";
        } else {
                print "$host is dead.\n";
                open (LOG, ">>/home/raging/cameralog.txt");
                ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
                printf LOG "%02d/%02d/%4d\t%02d:%02d:%02d", $month + 1, $dayOfMonth, $yearOffset + 1900, $hour, $minute, $second;
                system "$kill_it";
                sleep(5);
                system "$start_it";
                print LOG "\t$host reset.\n";
                close (LOG);
        }
}

$p->close();
$pr->close();

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)