Guest
Public paste!

pitombera

By: a guest | Jan 27th, 2009 | Syntax: Perl | Size: 1.55 KB | Hits: 156 | Expires: Never
Copy text to clipboard
  1. #!/usr/bin/perl
  2. #
  3.  
  4. use strict;
  5. use Device::Gsm;
  6.  
  7. #
  8. die "use: $0 number ex: echo \"msg\" | (perl) $0 dd12345678\n" unless( $ARGV[0] && length( $ARGV[0] ) == 10  );
  9.  
  10. # Conf
  11. my $myport = $^O =~ /freebsd/ ? '/dev/ttyU0' : '/dev/ttyACM0'; # Define device
  12. my $mypin  = '0000'; # Define pin
  13.  
  14. my $gsm = new Device::Gsm( port => $myport, pin => $mypin, log => 'file,send.log' );
  15.  
  16. die "cannot create Device::Gsm object!" unless $gsm;
  17.  
  18. #
  19. # If you have problems with bad characters being trasmitted across serial link,
  20. # try different baud rates, as below...
  21. #
  22. # .---------------------------------.
  23. # | Model (phone/modem) |  Baudrate |
  24. # |---------------------+-----------|
  25. # | Falcom Swing (A2D)  |      9600 |
  26. # | Motorola v3/v550    |      9600 |
  27. # | Siemens C35/C45     |     19200 |
  28. # | Digicom             |      9600 |
  29. # | Nokia Communicator  |      9600 |
  30. # `---------------------------------'
  31. #
  32.  
  33. $gsm->connect( baudrate => 9600 ) or die "cannot connect to GSM device on [$myport]\n";
  34. $gsm->register() or die "cannot register on GSM network: check pin and/or network signal!";
  35.  
  36. print "\nok! connected and registered to network.\n";
  37.  
  38. # +557188116605
  39. my $prefix = '+55';
  40.  
  41. my $number = $prefix . $ARGV[0];
  42.  
  43. my $content;
  44. do {
  45. #       print "\nSMS Text (max 160 chars):\n";
  46.         chomp( $content = <STDIN> );
  47. } until $content;
  48.  
  49. $content = substr( $content, 0, 160 );
  50.  
  51. my $lOk = $gsm->send_sms(
  52.         content => $content,
  53.         recipient => $number,
  54.         class     => 'normal'     # try `flash'
  55. );
  56.  
  57. $lOk ? exit 0 : exit 1;