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.
To incorporate this library into your project all you have to do is to include the “ATCommands.h” file. This exports the following functions:
- 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.
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.
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.
- Support for handling multiple mobile devices at once.
- Error handling can be better.
- Support for Queueing/Scheduling of messages.