AT Commands: Mobile Messaging

I was just wondering on how to send SMS from your computer via a mobile device (or GPRS modem). I dug it up and created a small application using c++ (Netbeans IDE) which you can extend and use as per your free will.

The How??

There is a great guide here which you can use to telnet your mobile device and test sending a SMS manually. To do it via a program: read on.

Quick Start

To incorporate this library into your project all you have to do is to include the “ATCommands.h” file. This exports the following functions:
void initPort(int n);
void pokeDevice();
int getMsgIndex();
void sendSMS(char *TargetNo,char *Msg);
void closePort();
Lets dicuss their roles one at a time:
  • initPort(int n): It initializes and sets up the port for communication. The device string should be of the form /dev/ttS<n> where n is the port number (like mostly if you have only one device attached then it will be /dev/ttyS1).
  • pokeDevice(): To be used only under debug mode(explained later). It is analogous to a ping.
  • getMsgIndex(): It is a helper function for sendSMS and returns the index for the new message to be written.
  • sendSMS(char *TargetNo,char *Msg): It is the function you want to call most often and is responsible for actual sending of SMS.
  • closePort(): performs cleanup and closes open port.
Putting it all together, we have a sample test program as:
initPort(n); // Open Port and set params;
#ifdef DEBUG
pokeDevice(); // To test if connection can be made
sendSMS(argv[2],argv[3]); // actual procedure that sends message
// argv[2] is no. and argv[3] is MSG
closePort(); // Cleanup

Try running it and …. guess what… you’ve got SMS (You’ve got mail sounds more catchy or is it just me :P).

Under The Hood

The code I have written supports a DEBUG flag. All you’ve got to do is to include “Debug.h” which defines a macro Debug and enables logging of debug messages to stdout. If you are extending the library then you might want to use the DbgPrint( char *format, … ) function to maintain uniformity of the debug flag.

click download link below to download the complete netbeans project and have a go at it yourself.


The above code was compiled using g++4.3.2/cygwin and tested with mobile handsets of Nokia, Sony Ericsson and Sigmatel. It should also work with most GPRS modems. 

Further Improvements

  • Support for handling multiple mobile devices at once.
  • Error handling can be better.
  • Support for Queueing/Scheduling of messages.


  1. well bhaiya,its coincidence. i am making the project on the same..will be a great help to me..!!!


    April 11, 2011

Leave a Reply

Your email address will not be published. Required fields are marked *