shigetsu has asked for the wisdom of the Perl Monks concerning the following question:
$modem->atsend("AT+CGMS=$recipient\cm$msg\cz");
$recipient consists of valid mobile number and $msg contains a message such as "The quick brown fox jumps over the lazy dog". Whatever result I receive via$modem->answer();
and per SMS, some leading characters get truncated; I tried chomp and autoflush, but neither of them works. When I type the string manually via the minicom console, then the entire string gets delivered.Code excerpt:
#!/usr/bin/perl use strict; use warnings; use Device::Modem; use Getopt::Std; $| = 1; my (%opts, @recipients); my ($modem, $msg); my $device = '/dev/ttyS1'; my $pin = ''; parse_args(); check_len_msg(); main(); sub main { foreach my $recipient (@recipients) { init(); set_opts(); send_cmds($recipient); disconnect(); } } sub parse_args { getopts('S:', \%opts); @recipients = @ARGV; chomp(@recipients); usage() unless defined $opts{S}; $msg = $opts{S}; } sub usage { print <<EOT; $0 [-S] recipient(s) EOT exit(1); } sub check_len_msg { die "message exceeds size of 130 character!\n" if length($msg) > 130; } sub init { $modem = Device::Modem->new(port => $device); if ($modem->connect(baudrate => 9600)) { print "Connecting...\n"; } else { print "Sorry, no connection with serial port!\n"; } } sub set_opts { $modem->is_active(); $modem->echo(0); $modem->verbose(1); } sub send_cmds { my $recipient = shift; $modem->atsend("AT\r"); my $answer = $modem->answer()."\n"; print $answer; $modem->atsend("AT+CSCS=GSM\r"); $answer = $modem->answer()."\n"; print $answer; $modem->atsend("AT+CPIN=?\r"); $answer = $modem->answer()."\n"; print $answer; $modem->atsend("AT+CPIN?\r"); $answer = $modem->answer()."\n"; $answer =~ s/(?:\+CPIN:\s\w+)\s*(.*)/$1/; print $answer; $modem->atsend("AT+CMGC=?\r"); $answer = $modem->answer()."\n"; print $answer; $modem->atsend("AT+CMGF=1\r"); $answer = $modem->answer()."\n"; print $answer; $modem->atsend("AT+CMGS=$recipient\cm$msg\cz"); $answer = $modem->answer()."\n"; print $answer; } sub disconnect { $modem->disconnect(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lost characters using Device::Modem
by roboticus (Chancellor) on Nov 24, 2006 at 15:12 UTC | |
by shigetsu (Hermit) on Nov 24, 2006 at 15:27 UTC | |
|
Re: Lost characters using Device::Modem
by shmem (Chancellor) on Nov 24, 2006 at 15:16 UTC | |
|
Re: Lost characters using Device::Modem
by jbert (Priest) on Nov 24, 2006 at 18:41 UTC | |
by roboticus (Chancellor) on Nov 24, 2006 at 22:46 UTC | |
by jbert (Priest) on Nov 26, 2006 at 19:34 UTC | |
|
Re: Lost characters using Device::Modem
by polettix (Vicar) on Nov 26, 2006 at 23:36 UTC |