The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Device::Modem::GSM - Perl module to communicate with a GSM cell phone connected via some sort of Serial port (including but not limited to most USB data cables, IrDA, ... others ?).


 use Device::Modem::GSM;
 my $gsm = new Device::Modem::GSM(
     port     => '/dev/ttyUSB0',
     log      => 'file,gsm_pb.log',
     loglevel => 'info');
 if ($gsm->connect(baudrate => 38400)) {
     print "Connected\n";
 else {
     die "Couldn't connect, stopped";
 if (not $gsm->pb_storage("SM")) {
     croak("Couldn't change phonebook storage");
     index => 0,
     text => "Daddy",
     number => '+1234567');

 $entries = $gsm->pb_read_entries(1,10);
 # or even $entries = $gsm->pb_read_all;
 foreach (@$entries) {
     print $_->{index}, ':', $_->{text}, ':', $_->{number}, "\n";


Device::Modem::GSM extends Device::Modem (which provides the basic communication layer) to provide access to high-level GSM functionnalities (such as access to phonebook or dealing with SMSes).

This module inherits from Device::Modem so if you need lower level access methods, start looking there.



    pb_storage must be called before any other method dealing with the phonebook. This method will set the storage on which other method calls will operate.

    Supported storages will depend on the cell phone, but the following should always exist :


    SM is the SIM card


    ME is the phone memory

    Ex : $gsm->pb_storage("SM");


    This method will write an entry into the phonebook.

    Ex :

         index => 1,
         text => 'John Doe',
         number => '+3312345');

    The "index" parameter specifies the storage slot to fill. If none specified, then the first empty is used.


    This method will erase the entry at the specified index of the storage

    Ex : $gsm->pb_erase(10);


    This method will clear the whole phonebook for the used storage. Handle with care !

    Ex : $gsm->pb_erase_all;


    This method will fetch the specified entries in the phonebook storage and return them in a reference to an array. Each cell of the array is a reference to a hash holding the information.

    Ex :

     my $entries = $gsm->pb_read_entries(1,10);
     foreach (@$entries) {
         print $_->{index}, ':', $_->{text}, ':', $_->{number}, "\n";

    With 2 arguments, the arguments are interpreted as an index range and entries inside of this range are returned.

    With 1 argument, the argument is interpreted as an index and only this entry is returned.


    This is equivalent to a pb_read_entry where the range extends from the beginning of the phonebook storage to its end.


    This method will let you send an SMS to the specified phone number

    Ex :

     $gsm->sms_send("+33123456", "Message to send as an SMS");


Feel free to contact me at my email for questions or suggestions.


Stephane KATTOOR,


(c) 2007, Stephane KATTOOR,

This library is free software; you can only redistribute it and/or modify it under the same terms as Perl itself.