Author Topic: Motorola SURFboard SB5100 woes and a workaround Perl script  (Read 4071 times)

0 Members and 1 Guest are viewing this topic.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
For the last few weeks, my usually-reliable Comcast connection via a Motorola SURFboard SB5100 has been acting up, and the modem will loose the internet connectivity with the  "Send" green light slowly flashing (third light down from the top).  A reboot using the config screen clears it up right away.  I've had Comcast out and tested both modem and line, and NTF was the result.  Grumble.

So, I wrote a small Perl script to run every 5 minutes via Windows Scheduler that will check the status of the modem and if not operational, do a soft-reboot of the modem.  The script keeps a daily log (named YYYYMMDD.txt) with timestamped entries that look like this
Code: [Select]
16-Jun-2009 12:48:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 39 dB
16-Jun-2009 12:53:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 39 dB
16-Jun-2009 12:58:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 38 dB
16-Jun-2009 13:03:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 38 dB
16-Jun-2009 13:08:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 39 dB
16-Jun-2009 13:13:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (3 dBmV ) S/N 39 dB
16-Jun-2009 13:18:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 39 dB
16-Jun-2009 13:23:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 39 dB
16-Jun-2009 13:28:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 39 dB
16-Jun-2009 13:33:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 39 dB
16-Jun-2009 13:38:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 38 dB
16-Jun-2009 13:43:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 39 dB
16-Jun-2009 13:48:00 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 39 dB
16-Jun-2009 13:53:00 Online Up CH: 12 @ 37000000Hz (49 dBmV ) Dn 723000000Hz (2 dBmV ) S/N 39 dB

When a reboot is necessary, it also records the detailed status and the modem log like this test
Code: [Select]
16-Jun-2009 12:35:27 Online Up CH: 10 @ 25300000Hz (47 dBmV ) Dn 735000000Hz (2 dBmV ) S/N 39 dB
16-Jun-2009 12:35:27 ---Modem status---
Status Acquire Downstream Channel Done
Status Obtain Upstream Parameters Done
Status Upstream Ranging Done
Status Establish IP Connectivity using DHCP Done
Status Establish Time Of Day Done
Status Transfer Operational Parameters through TFTP Done
Status Register Connection Done
Status Cable Modem Status Operational
Status Initialize Baseline Privacy Done
16-Jun-2009 12:35:27 ---Log data---
Log 2009-06-16 08:36:30 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-15 17:24:30 3-Critical C205.0 DCC aborted no UCD for new upstream channel
Log 2009-06-15 04:46:32 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 18:56:27 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 18:52:58 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 18:52:04 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 18:48:39 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 18:48:28 3-Critical C206.0 DCC aborted unable to communicate on new upstream channel
Log 2009-06-14 18:48:28 3-Critical R003.0 Init RANGING Critical Ranging Request Retries exhausted
Log 2009-06-14 18:48:28 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 14:03:33 3-Critical R005.0 Started Unicast Maintenance Ranging - No Response received - T3 time-out
Log 2009-06-14 14:00:33 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 13:26:29 3-Critical C205.0 DCC aborted no UCD for new upstream channel
Log 2009-06-14 13:14:39 3-Critical R005.0 Started Unicast Maintenance Ranging - No Response received - T3 time-out
Log 2009-06-14 13:02:30 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:42:06 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:38:47 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:38:43 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:35:21 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:35:13 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:31:55 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:31:38 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:28:25 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:28:06 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:24:45 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:23:40 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:20:19 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:20:11 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:16:57 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:16:52 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:13:39 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:13:32 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:10:18 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:10:16 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 12:10:15 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 12:10:14 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 12:10:12 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 12:10:11 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 12:10:03 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 12:10:03 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 12:10:01 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 12:10:01 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 12:10:00 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 12:10:00 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 12:09:58 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 12:09:58 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 12:09:56 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:06:44 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:06:37 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 12:03:21 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 12:02:59 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:59:37 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:59:28 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:56:14 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:54:45 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:51:20 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:51:14 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:47:54 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:47:44 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:41:04 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:40:46 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:37:15 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:35:17 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 11:35:12 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 11:35:12 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 11:35:11 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 11:35:11 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 11:35:02 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 11:34:58 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:34:55 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:31:32 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:31:29 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:28:06 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:27:49 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:24:29 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:24:22 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:20:55 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:20:48 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:14:00 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:13:47 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 11:13:45 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 11:13:45 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 11:13:34 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 11:13:33 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 11:13:32 3-Critical T002.0 SYNC Timing Synchronization failure - Failed to acquire FEC framing
Log 2009-06-14 11:13:32 3-Critical T001.0 SYNC Timing Synchronization failure - Failed to acquire QAM/QPSK symbol timing
Log 2009-06-14 11:13:29 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:13:25 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:10:08 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:10:04 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 11:06:47 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 11:00:03 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 10:56:48 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 10:56:41 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 10:53:28 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 10:53:01 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 10:49:42 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 10:49:31 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received
Log 2009-06-14 10:46:07 3-Critical R002.0 No Ranging Response received - T3 time-out
Log 2009-06-14 10:46:03 3-Critical D001.0 DHCP FAILED - Discover sent, no offer received

16-Jun-2009 12:35:27 ---Log data end---
16-Jun-2009 12:35:27 ---Reboot---
HTTP/1.0 200 OK
Pragma: no-cache
Pragma: no-cache
Content-Type: text/html
Expires: Wed, 30 Apr 1975 02:00:00 GMT
Client-Date: Tue, 16 Jun 2009 19:35:27 GMT
Client-Peer: 192.168.100.1:80
Client-Response-Num: 1

<HTML>
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="Wed, 30 Apr 1975 02:00:00 GMT">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#485A91"
VLINK="#7B2939" ALINK="#7B2939">
<CENTER><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 ALIGN="CENTER">
<TR><TH BGCOLOR="#000000">
<FONT COLOR="White" FACE="Arial , Helvetica"><CENTER>
Configuration Manager
</CENTER></FONT></TH>
</TR>
<TR><TH BGCOLOR="#666600">
<FONT COLOR="White" FACE="Arial , Helvetica"><CENTER>Messages
</CENTER></FONT></TH>
</TR>
</TABLE>
</CENTER><TABLE WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=5
ALIGN="CENTER" BGCOLOR="#000000">
<TR>
<TD BGCOLOR="#FFFFFF">
This page displays status information.

</TD>
</TR>
</TABLE>
<IMG SRC="/line.gif" WIDTH="100%">
<P>
</P>
<H4><FONT COLOR = #008000>Your Cable Modem is rebooting in 10 Seconds.
</FONT></H4><P>
<IMG SRC="/line.gif" WIDTH="100%">
<P>
</P>
</BODY>
</HTML>
16-Jun-2009 12:35:27 ---Reboot end---

When a reboot is done, an entry is made in reboot-log.txt showing
Code: [Select]
16-Jun-2009 12:35:27 Modem Online .. rebooted (as a test of script) so you can go to the YYYYMMDD.txt file and see the details around the reboot event.

You will need to install Device::CableModem::SURFboard package, available from CPAN or via ppm (perl package manager) on your Perl installation.

Ok, enough blather... here's the script:

Code: [Select]
#!/usr/bin/perl
#
# Check Surfboard 5100 modem for current connection, log status and
#  restart modem if disconnected
#
# Perl script by Ken True webmaster@saratoga-weather.org
#
# Version 1.00 - 16-Jun-2009 - Initial release
#
#  uses Device::CableModem::SURFboard package, available from CPAN or via ppm
#  uses LWP for reboot function (normally installed with Perl package).
#
#  this script is customized for a Motorola SB5100 modem.  You can adapt it for use with
#  other Motorola cable modem models as needed.
#
# OUTPUT:
#  ${logsDir}YYYYMMDD.txt  daily logfile
#  ${logsDir}reboot-log.txt   records date/time of reboot so you can check the YYYYMMDD.txt
#                             file for details before the reboot takes place.
#
# Run via Windows Scheduler or Linux cron .. all output is to the log file(s)
#
# ---- configurable settings ----

 $logsDir = "./modem-logs/"; # place to store the YYYYMMDD.txt and reboot-log.txt files
 $testIT = 0;  # set =1 to try the reboot.

 $modemIP = '192.168.100.1';       #local IP address for webserver on cable modem
 $modemPage = '/configdata.html';  # SB51000 modem specific
 $resetCode = 'BUTTON_INPUT=Restart Cable Modem';# SB51000 modem specific

# ---- end of configurable settings --

 $cur_time = time();
 @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

 $log_filename = ISO_datestamp($cur_time) . ".txt";
 $nice_date = nice_datestamp($cur_time);

 use Device::CableModem::SURFboard;
 my $modem = Device::CableModem::SURFboard->new
        or die "Unable to access cable modem .. " . Device::CableModem::SURFboard->errstr;

 my $TXT = "$nice_date\t";

 my $status = $modem->pageRef('/startupdata.html');

    if ($$status =~ m|Status</FONT>
</TH>
</TR>
(.*?)</TABLE>|gis) { $status_data = $1; }

  # clean up the html a bit for parsing (SB5100 status page specific)
  $status_data =~ s/\n//g;     # drop new lines
  $status_data =~ s!<td>!!ig; # strip table tags
  $status_data =~ s!</td></tr>!|!ig; # strip table tags
  $status_data =~ s"</td>"\t"ig; # strip table tags
  $status_data =~ s!<tr>!Status\t!ig; # strip table tags
  $status_data =~ s/&nbsp;/ /ig; # replace hard spaces
  $status_data =~ s/\s\s+/ /g; # reduce double spaces


  if ($status_data =~ m/Operational/i) { # all working.. nothing to do
    $online = "Online";
  } else {
    $online = "OFFLINE";
  }

# format basic status record for YYYYMMDD.txt log file

  $TXT .= "$online\t";
  $TXT .= "Up CH: " . $modem->channel . ' @ ' . $modem->upFreq() . "Hz ";
  $TXT .= "(" . $modem->upPowerStr . ' ' . $modem->upPowerCheck . ") ";
  $TXT .= "Dn " . $modem->dnFreq() . "Hz";
  $TXT .= " (" . $modem->dnPowerStr . ' ' . $modem->dnPowerCheck. ") ";
  $TXT .= "S/N " .$modem->SNRatioStr . ' ' . $modem->SNRatioCheck. "\n";

  if ($testIT || $status_data !~ m/Operational/i) { # all working.. nothing to do
    # ------ modem offline .. reboot and log


    $logs = $modem->pageRef('/logsdata.html');

    if ($$logs =~ m|<TABLE ALIGN="center" CELLPADDING=8 CELLSPACING=0 BORDER=1(.*?)</TABLE>|gis)
      { $log_data = $1; }

#
    $TXT .= "$nice_date\t---Modem status---\n";
    @stats = split(/\|/,$status_data);
       
    for ($i=0;$i<=$#stats;$i++) {
      $TXT .= $stats[$i] . "\n";
    }
       
    $TXT .= "$nice_date\t---Log data---\n";
    # clean up the html a bit for parsing
    $log_data =~ s/\n//g;     # drop new lines
    $log_data =~ s/^WIDTH(.*)<\/TH><\/TR>(.*)$/$2/gi;     # remove flotsam
    $log_data =~ s!<td>!!ig; # strip table tags
    $log_data =~ s!</td></tr>!|!ig; # strip table tags
    $log_data =~ s"</td>"\t"ig; # strip table tags
    $log_data =~ s!<tr>!Log\t!ig; # strip table tags
    $log_data =~ s/&nbsp;/ /ig; # replace hard spaces
    $log_data =~ s/\s\s+/ /g; # reduce double spaces
    $log_data =~ s/\|/\n/g; # put back new-lines
     
    $TXT .= $log_data . "\n";
    $TXT .= "$nice_date\t---Log data end---\n";

    # Use LWP to send a HTTP POST to the modem to reboot

    use LWP::UserAgent;
    $ua = LWP::UserAgent->new;

    my $req = HTTP::Request->new(POST => "http://${modemIP}${modemPage}");
    $req->user_agent("Mozilla 4.0");
    $req->content_type('application/x-www-form-urlencoded');
    $req->content($resetCode);

    my $res = $ua->request($req);  # do the POST

    $TXT .= "$nice_date\t---Reboot---\n" .  $res->as_string . "\n";
    $TXT .= "$nice_date\t---Reboot end---\n";
 
   } else {
    #  modem is operational .. nothing else needed except to log the status line

  }

  open (OUT,">>${logsDir}${log_filename}");
  print OUT $TXT;
  close OUT;

  if ($testIT || $online !~ m/online/i) {
    open (OUT, ">>${logsDir}reboot-log.txt");
    print OUT "$nice_date\tModem $online .. rebooted";
    if($testIT) {
      print OUT " (as a test of script)";
    }
    print OUT "\n";
    close OUT;
  }

  exit;

# ------  end of main program -----

sub nice_datestamp {
    my $d = shift;
   
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($d);
    my $nicedate = sprintf(
        "%02d\-%s\-%04d %02d\:%02d\:%02d",
        $mday,$months[$mon],$year+1900,$hour,$min,$sec);
    return("$nicedate");

}

sub ISO_datestamp {
    my $d = shift;
   
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($d);
    my $nicedate = sprintf("%04d%02d%02d",$year+1900,$mon+1,$mday);
    return("$nicedate");

}


Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

 

anything