Advertisement
Guest User

perlmodem

a guest
Feb 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.88 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # get_gsm_signal.pl
  4. # jp - 01082013
  5. # Connects to wavecom gsm modem on /dev/ttyS0.
  6. # Issues AT+CSQ command to get RSSI and BER
  7. # Outputs ready for collection by cacti.
  8.  
  9. use Device::Modem;
  10.  
  11. my $modem = new Device::Modem( port => '/dev/ttyS0' );
  12.  
  13. if( $modem->connect( baudrate => 9600 ) ) {
  14.   } else {
  15.       print "sorry, no connection with serial port!\n";
  16.   }
  17.  
  18. # Reset the modem, then send in the AT commands.
  19. # Use the builtin carriage return function - or have a bad time.
  20.  
  21. $modem->atsend( 'AT+CSQ' . Device::Modem::CR );
  22. $csq = $modem->answer();
  23.  
  24. # Some wrangling - its content over style I'm afraid
  25.  
  26. $csq =~ s/OK//g;
  27.  
  28. # Remove all newline chars to get sensible output.
  29. $csq =~ s/\r\n//g;
  30.  
  31. $csq =~ s/^\+CSQ\:\ //;
  32. my($sig, $ber) = split(/,/, $csq, 2);
  33.  
  34. # Finally output in a format that cacti expects
  35.  
  36. print "SIG:$sig BER:$ber\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement