Automatically reset your cable modem when the Internet goes missing — part 2

My previous post was about writing a script to automatically reset a cable modem when the Internet dies.  My cable modem goes nuts from time to time and needs to be reset to get the Internet connection back.  This isn’t that big a deal, in fact it’s not an uncommon problem to have; but, I do access services running at home remotely and I’d like to have it set up to fix itself whenever this happens.

As noted in my previous post, I discovered that my particular cable modem has a web interface and you can reset it from the web interface.  However, I’ve already discovered instances where it’s gone crazy and does not respond to the http reset command, requiring a full power cycle to get things back in order.  Also, some people may not be able to reset the modem from the web interface, so this new method will help them out as well.

To reset the cable modem when it will not respond to commands issued through the web interface, I need to be able to perform an automated power cycle.  To do this, I picked up a couple of X10 home automation devices — specifically, a CM19A, which is a USB device that can transmit X10 commands via RF, and a TM751, which receives RF commands and can be used to turn on and off a connected device.  (I purchased them from here if you are interested.)

To get them to work on Windows, you need to download the ActiveHome SDK.  Go here and click the link to download the complete package.  After the download, run the installer.  At the end of the install, the installer will prompt you to connect the USB devices so that the driver can be installed.  Go ahead and plug in the CM19A, and it should take care if the driver installation without issue.

The SDK installs a system service called the “X10 Device Network Service” which needs to be running for the X10 stuff to work.  The service is set to start automatically but the installer doesn’t actually start it — you’ll need to start it yourself or reboot your machine to get it up and running.

To be able to issue commands to the TM751, you’ll need a tool to do it with.  The SDK comes with the source to a tool called ahcmd, a command-line tool that can be used to issue commands.  Compile it (or download mine), and test it out if you like.  The syntax is like:

ahcmd sendrf a1 off
ahcmd sendrf a1 on

Of course, the TM751 has a dial on it that allows you to select a letter.  If you set the letter to “B” you should use “b1” instead of “a1” to control it, etc.

Plug the TM751 into an outlet and the modem into the TM751 and now your computer can power-cycle the modem.  An update to the script that I included in my previous post now power-cycles the modem when the web reset command fails:

@ECHO OFF

REM This script checks for an active Internet connection by trying to access
REM five different web sites. If all five checks fail, it will reset the cable
REM modem.

wget --tries=1 --timeout=10 -O - "http://www.google.com/"
IF %ERRORLEVEL%==0 GOTO done
echo Google failed.

wget --tries=1 --timeout=10 -O - "http://www.bing.com/"
IF %ERRORLEVEL%==0 GOTO done
echo Bing failed.

wget --tries=1 --timeout=10 -O - "http://www.yahoo.com/"
IF %ERRORLEVEL%==0 GOTO done
echo Yahoo! failed.

wget --tries=1 --timeout=10 -O - "http://www.facebook.com/"
IF %ERRORLEVEL%==0 GOTO done
echo Facebook failed.

wget --tries=1 --timeout=10 -O - "http://www.twitter.com/"
IF %ERRORLEVEL%==0 GOTO done
echo Twitter failed.

REM If we got here... The Internet appears to be broken.
echo Restarting cable modem. >> C:\Users\Aaron\log\internet-check.log
echo Restarting cable modem.
wget --tries=1 --timeout=60 -O - "http://192.168.100.1/reset.htm?reset_modem=Restart+Cable+Modem"
IF %ERRORLEVEL%==0 GOTO restart

echo Failed to restart cable modem; forcing power cycle. >> C:\Users\Aaron\log\internet-check.log
echo Forcing power cycle.

C:\Users\Aaron\bin\ahcmd.exe sendrf a1 off
sleep 10
C:\Users\Aaron\bin\ahcmd.exe sendrf a1 on

date /T >> C:\Users\Aaron\log\internet-check.log
time /T >> C:\Users\Aaron\log\internet-check.log
echo --- >> C:\Users\Aaron\log\internet-check.log

exit 2

:restart

date /T >> C:\Users\Aaron\log\internet-check.log
time /T >> C:\Users\Aaron\log\internet-check.log
echo --- >> C:\Users\Aaron\log\internet-check.log

exit 1

:done

echo The Internet appears to be working.
exit 0

I was planning on connecting both my modem and my router to the TM751, but the outlet on the TM751 does not include the ground connector so my “octopus” three-plug adapters will not fit.  It’s not a big deal, though… I’ve had my router for years and I’ve only ever had to reset it once or twice.  If it causes any trouble in the future, I can always pick up another appliance module that would allow me to control it separately.  (The TM751 transmits the X10 commands it receives over the power line that it is attached to, so a non-RF-capable appliance module should be sufficient for controlling additional devices, if they are all connected to lines that don’t hamper communication between them.)

Giving credit:  This blog post, this forum thread, and this article helped me figure this stuff out.  If you use Linux, the information here might help you get a similar solution up and running.

4 thoughts on “Automatically reset your cable modem when the Internet goes missing — part 2”

  1. I was reading a national newspaper when the answer hit me, inside the paper was a classified adverts section and right in the top of the page was a little advertisment, extolling the virtues of a good height and providing to give the reader that additional height by indicates of a miracle new item, heel Lifts !!I was delighted, here was a opportunity to order heel Lifts via the post, have them delivered to my door, in a plain brown package, no require for a traumatic trip towards the local shops, no need for any embarrassment while asking a stunning shop girl where the heel Lifts had been shelved

    http://4321.in/userinfo.php?uid=6028

Leave a Reply

Your email address will not be published. Required fields are marked *

*