SYNOPSIS

  use Device::Gsm;

  my $gsm = new Device::Gsm( port => '/dev/ttyS1', pin => 'xxxx' );

  if( $gsm->connect() ) {
      print "connected!\n";
  } else {
      print "sorry, no connection with gsm phone on serial port!\n";
  }

  # Register to GSM network (you must supply PIN number in above new() call)
  # See 'assume_registered' in the new() method documentation
  $gsm->register();

  # Send quickly a short text message
  $gsm->send_sms(
      recipient => '+3934910203040',
      content   => 'Hello world! from Device::Gsm'
  );

  # Get list of Device::Gsm::Sms message objects
  # see `examples/read_messages.pl' for all the details
  my @messages = $gsm->messages();

DESCRIPTION

\*(C`Device::Gsm\*(C' class implements basic \s-1GSM\s0 functions, network registration and \s-1SMS\s0 sending.

This class supports also \*(C`PDU\*(C' mode to send \*(C`SMS\*(C' messages, and should be fairly usable. In the past, I have developed and tested it under Linux RedHat 7.1 with a 16550 serial port and Siemens C35i/C45 \s-1GSM\s0 phones attached with a Siemens-compatible serial cable. Currently, I'm developing and testing this stuff with Linux Slackware 10.2 and a Cambridge Silicon Radio (\s-1CSR\s0) \s-1USB\s0 bluetooth dongle, connecting to a Nokia 6600 phone.

Please be kind to the universe and contact me if you have troubles or you are interested in this.

Please be monstruosly kind to the universe and (if you don't mind spending an \s-1SMS\s0) use the \*(C`examples/send_to_cosimo.pl\*(C' script to make me know that Device::Gsm works with your device (thanks!).

Recent versions of \*(C`Device::Gsm\*(C' have also an utility called \*(C`autoscan\*(C' in the \*(C`bin/\*(C' folder, that creates a little profile of the devices it runs against, that contains information about supported commands and exact output of commands to help recognize similar devices.

Be sure to send me your profile by email (if you want to), so I can add better support for your device in the future!

METHODS

The following documents all supported methods with simple examples of usage.

\fInew()\fP

Inherited from Device::Modem. See Device::Modem documentation for more details.

The only mandatory argument is the \*(C`port\*(C' you want to use to connect to the \s-1GSM\s0 device:

my $gsm = Device::Gsm->new( port => '/dev/ttyS0', );

On some phones, you may experience problems in the \s-1GSM\s0 network registration step. For this reasons, you can pass a special \*(C`assume_registered\*(C' option to have Device::Gsm ignore the registration step and assume the device is already registered on the \s-1GSM\s0 network. Example:

my $gsm = Device::Gsm->new( port => '/dev/ttyS0', assume_registered => 1, );

If you want to send debugging information to your own log file instead of the default setting, you can:

my $gsm = Device::Gsm->new( port => '/dev/ttyS1', log => 'file,/tmp/myfile.log', loglevel => 'debug', # default is 'warning' );

\fIconnect()\fP

This is the main call that connects to the appropriate device. After the connection has been established, you can start issuing commands. The list of accepted parameters (to be specified as hash keys and values) is the same of \*(C`Device::SerialPort\*(C' (or \*(C`Win32::SerialPort\*(C' on Windows platform), as all parameters are passed to those classes' connect() method.

The default value for \*(C`baudrate\*(C' parameter is 19200.

Example:

my $gsm = Device::Gsm->new( port=>'/dev/ttyS0', log=>'syslog' ); # ... if( $gsm->connect(baudrate => 19200) ) { print "Connected!"; } else { print "Could not connect, sorry!"; } # ...

\fIdatetime()\fP

Used to get or set your phone/gsm modem date and time.

If called without parameters, it gets the current phone/gsm date and time in \*(L"gsm\*(R" format \*(L"\s-1YY/MM/DD\s0,HH:MN:SS\*(R". For example \*(C`03/12/15,22:48:59\*(C' means December the 15th, at 10:48:59 \s-1PM\s0. Example:

$datestr = $gsm->datetime();

If called with parameters, sets the current phone/gsm date and time to that of supplied value. Example:

$newdate = $gsm->datetime( time() );

where \*(C`time()\*(C' is the perl's builtin \*(C`time()\*(C' function (see \*(C`perldoc -f time\*(C' for details). Another variant allows to pass a \*(C`localtime\*(C' array to set the correspondent datetime. Example:

$newdate = $gsm->datetime( localtime() );

(Note the list context). Again you can read the details for \*(C`localtime\*(C' function with \*(C`perldoc -f localtime\*(C'.

If your device does not support this command, an undefined value will be returned in either case.

\fIdelete_sms()\fP

This method deletes a message from your \s-1SIM\s0 card, given the message index number. Example:

$gsm->delete_sms(3);

An optional second parameter specifies the \*(L"storage\*(R". It allows to delete messages from gsm phone memory or sim card memory. Example:

# Deletes first message from gsm phone memory $gsm->delete_sms(1, 'ME');

# Deletes 3rd message from sim card $gsm->delete_sms(3, 'SM');

By default, it uses the currently set storage, via the \*(C`storage()\*(C' method.

\fIforward()\fP

Sets call forwarding. Accepts three arguments: reason, mode and number. Reason can be the string \*(C`unconditional\*(C', \*(C`busy\*(C', \*(C`no reply\*(C' and \*(C`unreachable\*(C'. Mode can be the string \*(C`disable\*(C', \*(C`enable\*(C', \*(C`query\*(C', \*(C`register\*(C', \*(C`erase\*(C'.

Example:

# Set unconditional call forwarding to +47 123456789 $gsm->forward('unconditional','register','+47123456789');

# Erase unconditional call forwarding $gsm->forward('unconditional','erase');

\fIhangup()\fP

Hangs up the phone, terminating the active calls, if any. This method has been never tested on real \*(L"live\*(R" conditions, but it needs to be specialized for \s-1GSM\s0 phones, because it relies on \*(C`+HUP\*(C' \s-1GSM\s0 command. Example:

$gsm->hangup();

\fIimei()\fP

Returns the device own \s-1IMEI\s0 number (International Mobile Equipment Identifier ???). This identifier is numeric and should be unique among all \s-1GSM\s0 mobile devices and phones. This is not really true, but ... . Example:

my $imei = $gsm->imei();

\fImanufacturer()\fP

Returns the device manufacturer, usually only the first word (example: \*(C`Nokia\*(C', \*(C`Siemens\*(C', \*(C`Falcom\*(C', ...). Example:

my $man_name = $gsm->manufacturer(); if( $man_name eq 'Nokia' ) { print "We have a nokia phone..."; } else { print "We have a $man_name phone..."; }

\fImessages()\fP

This method is a somewhat unstable and subject to change, but for now it seems to work. It is meant to extract all text \s-1SMS\s0 messages stored on your \s-1SIM\s0 card or gsm phone. In list context, it returns a list of messages (or undefined value if no message or errors), every message being a \*(C`Device::Gsm::Sms\*(C' object.

The only parameter specifies the \*(C`storage\*(C' where you want to read the messages, and can assume some of the following values (but check your phone/modem manual for special manufacturer values): Means gsm phone \s-1ME\s0mory Means gsm phone \s-1ME\s0mory on Nokia phones? Means Sim card Memory (default value)

Example:

my $gsm = Device::Gsm->new(); $gsm->connect(port=>'/dev/ttyS0') or die "Can't connect!";

for( $gsm->messages('SM') ) { print $_->sender(), ': ', $_->content(), "\n"; }

\fImode()\fP

Sets the device \s-1GSM\s0 command mode. Accepts one parameter to set the new mode that can be the string \*(C`text\*(C' or \*(C`pdu\*(C'. Example:

# Set text mode $gsm->mode('text');

# Set pdu mode $gsm->mode('pdu');

\fImodel()\fP

Returns phone/device model name or number. Example:

my $model = $gsm->model();

For example, for Siemens C45, $model holds \*(C`C45\*(C'; for Nokia 6600, $model holds 6600.

\fInetwork()\fP

Returns the current registered or preferred \s-1GSM\s0 network operator. Example:

my $net_name = $gsm->network(); # Returns 'Wind Telecom Spa'

my($net_name, $net_code) = $gsm->network(); # Returns ('Wind Telecom Spa', '222 88')

This obviously varies depending on country and network operator. For me now, it holds \*(L"Wind Telecomunicazioni SpA\*(R". It is not guaranteed that the mobile phone returns the decoded network name. It can also return a gsm network code, like \*(C`222 88\*(C'. In this case, an attempt to decode the network name is made.

Be sure to call the \*(C`network()\*(C' method when already registered to gsm network. See \*(C`register()\*(C' method.

\fIsignal_quality()\fP

Returns the measure of signal quality expressed in dBm units, where near to zero is better. An example value is -91 dBm, and reported value is \*(C`-91\*(C'. Values should range from -113 to -51 dBm, where -113 is the minimum signal quality and -51 is the theorical maximum quality.

my $level = $gsm->signal_quality();

If signal quality can't be read or your device does not support this command, an undefined value will be returned.

\fIsoftware_version()\fP

Returns the device firmare version, as stored by the manufacturer. Example:

my $rev = $gsm->software_revision();

For example, for my Siemens C45, $rev holds 06.

\fIstorage()\fP

Allows to get/set the current sms storage, that is where the sms messages are saved, either the sim card or gsm phone memory. Phones/modems that do not support this feature (implemented by \*(C`+CPMS\*(C' \s-1AT\s0 command won't be affected by this method.

my @msg; my $storage = $gsm->storage(); print "Current storage is $storage\n";

# Read all messages on sim card $gsm->storage('SM'); @msg = $gsm->messages();

# Read messages from gsm phone memory $gsm->storage('ME'); push @msg, $gsm->messages();

\fItest_command()\fP

This method allows to query the device to know if a specific \s-1AT\s0 \s-1GSM\s0 command is supported. This is used only with \s-1GSM\s0 commands (those with \*(C`AT+\*(C' prefix). For example, I want to know if my device supports the \*(C`AT+GXXX\*(C' command. All we have to do is:

my $gsm = Device::Gsm->new( port => '/dev/myport' );

...

if( $gsm->test_command('GXXX') ) { # Ok, command is supported } else { # Nope, no GXXX command }

Note that if you omit the starting \*(C`+\*(C' character, it is automatically added. You can also test commands like \*(C`^SNBR\*(C' or the like, without \*(C`+\*(C' char being added.

\fIregister()\fP

\*(L"Registering\*(R" on the \s-1GSM\s0 network is what happens when you turn on your mobile phone or \s-1GSM\s0 equipment and the device tries to reach the \s-1GSM\s0 operator network. If your device requires a \s-1PIN\s0 number, it is used here (but remember to supply the \*(C`pin\*(C' parameter in new() object constructor for this to work.

Registration can take some seconds, don't worry for the wait. After that, you are ready to send your \s-1SMS\s0 messages or do some voice calls, ... . Normally you don't need to call register() explicitly because it is done automatically for you when/if needed.

If return value is true, registration was successful, otherwise there is something wrong; probably you supplied the wrong \s-1PIN\s0 code or network unreachable.

\fIsend_sms()\fP

Obviously, this sends out \s-1SMS\s0 text messages. I should warn you that you cannot send (for now) \s-1MMS\s0, ringtone, smart, ota messages of any kind with this method.

Send out an \s-1SMS\s0 message quickly:

my $sent = $gsm->send_sms( content => 'Hello, world!', # SMS text recipient => '+99000123456', # recipient phone number );

if( $sent ) { print "OK!"; } else { print "Troubles..."; }

The allowed parameters to send_sms() are: Class parameter can assume two values: \*(C`normal\*(C' and \*(C`flash\*(C'. Flash (or class zero) messages are particular because they are immediately displayed (without user confirm) and never stored on phone memory, while \*(C`normal\*(C' is the default. This is the text you want to send, consisting of max 160 chars if you use \s-1PDU\s0 mode and 140 (?) if in text mode (more on this later). Can assume two values (case insensitive): \*(C`pdu\*(C' and \*(C`text\*(C'. \*(C`PDU\*(C' means Protocol Data Unit and it is a sort of binary encoding of commands, to save time/space, while \*(C`text\*(C' is the normal \s-1GSM\s0 commands text mode. Recent mobile phones and \s-1GSM\s0 equipments surely have support for \*(C`PDU\*(C' mode. Older \s-1OEM\s0 modules (like Falcom Swing, for example) don't have \s-1PDU\s0 mode, but only text mode. It is just a matter of trying. Phone number of message recipient If present with a true value, it enables sending of \s-1SMS\s0 messages (only for \s-1PDU\s0 mode, text mode \s-1SMS\s0 won't be influenced by this parameter) with the status report, also known as delivery report, that is a short message that reports the status of your sent message. Usually this is only available if your mobile company supports this feature, and probably you will be charged a small amount for this service. More information on this would be welcome.

\fIservice_center()\fP

If called without parameters, returns the actual \s-1SMS\s0 Service Center phone number. This is the number your phone automatically calls when receiving and sending \s-1SMS\s0 text messages, and your network operator should tell you what this number is.

Example:

my $gsm = Device::Gsm->new( port => 'COM1' ); $gsm->connect() or die "Can't connect"; $srv_cnt = $gsm->service_center(); print "My service center number is: $srv_cnt\n";

If you want to set or change this number (if used improperly this can disable sending of \s-1SMS\s0 messages, so be warned!), you can try something like:

my $ok = $gsm->service_center('+99001234567'); print "Service center changed!\n" if $ok;

REQUIRES

  • Device::Modem, which in turn requires

  • Device::SerialPort (or Win32::SerialPort on Windows machines)

EXPORT

None

TROUBLESHOOTING

If you experience problems, please double check:

Device permissions

Maybe you don't have necessary permissions to access your serial, irda or bluetooth port device. Try executing your script as root, or try, if you don't mind, \*(C`chmod a+rw /dev/ttyS1\*(C' (or whatever device you use instead of \*(C`/dev/ttyS1\*(C').

Connection speed

Try switching \*(C`baudrate\*(C' parameter from 19200 (the default value) to 9600 or viceversa. This one is the responsible of 80% of the problems, because there is no baudrate auto-detection.

Device autoscan

If all else fails, please use the autoscan utility in the \*(C`bin/\*(C' folder of the \*(C`Device::Gsm\*(C' distribution. Try running this autoscan utility and examine the log file produced in the current directory. If you lose any hope, send me this log file so I can eventually have any clue about the problem / failure. Also this is a profiling tool, to know which commands are supported by your device, so please send me profiles of your devices, so I can add better support for all devices in the future!

TO-DO

Spooler

Build a simple spooler program that sends all \s-1SMS\s0 stored in a special queue (that could be a simple filesystem folder).

Validity Period

Support \*(C`validity\*(C' period option on \s-1SMS\s0 sending. Tells how much time the \s-1SMS\s0 Service Center must hold the \s-1SMS\s0 for delivery when not received.

Profiles

Build a profile of the \s-1GSM\s0 device used, so that we don't have to \*(C`always\*(C' test each command to know whether it is supported or not, because this takes too time to be done every time.

AUTHOR

Cosimo Streppone, [email protected]

RELATED TO Device::Gsm…

Device::Modem, Device::SerialPort, Win32::SerialPort, perl\|(1)