Saturday, April 12, 2008

Send SMS with Perl


#!/usr/bin/perl
use strict;
use warnings;
use Device::Gsm;

my $port = $^O =~ /Win/ ? 'COM6' : '/dev/modem';
my $myport;

my $gsm = new Device::Gsm(
port => $port, log => 'file,send.log'
);
die "cannot create Device::Gsm object!" unless $gsm;

$gsm->send_sms(
content => 'test',
recipient => '+6281220xxxx',
class => 'normal' # try `flash'
);



You can find related modules for SMS|GSM at http://www.cpan.org

Friday, April 11, 2008

Connect to GSM Modem - send raw AT commands


#!/usr/bin/perl
use Device::Modem;

my $modem = new Device::Modem( port => '/dev/modem');
if($modem->connect(baudrate => 9600)) {
print "connected \n";
} else {
print "connect to modem is failed $! \n";
}

$modem->atsend('AT+CMGL="STO UNSENT"' . Device::Modem::CR);
print $modem->answer();


I just connect to modem and send AT+CMGL (Read SMS message, in this case STO UNSENT [message in unsent folder])