You are on page 1of 31

Download application - 21.

6 KB
Introduction Lesson 1
There are many different kinds of applications SMS applications in the market today,
and many others are ein! de"eloped. #pplications in which SMS messa!in! can e
utili$ed are "irtually unlimited. %ome common e&amples of these are !i"en elow'
(erson-to-person te&t messa!in! is the most commonly
used SMS application, and it is what the SMStechnolo!y was ori!inally
desi!ned for.
)any content pro"iders make use of SMS te&t messa!es to send information
such as news, weather report, and financial data to their suscriers.
SMS messa!es can carry inary data, and so SMS can e used as the
transport medium of wireless downloads. *+ects such as rin!tones,
wallpapers, pictures, and operator lo!os can e encoded in SMS messa!es.
SMS is a "ery suitale technolo!y for deli"erin! alerts and notifications of
important e"ents.
SMS messa!in! can e used as a marketin! tool.
In !eneral, there are two ways to send SMS messa!es from a computer , (- to a
moile phone'
1. -onnect a moile phone or .%),.(/% modem to a computer , (-. Then use
the computer , (- and #T commands to instruct the moile phone or
.%),.(/% modem to send SMS messa!es.
2. -onnect the computer , (- to the SMS center 0SMS-1 or SMS !ateway of a
wireless carrier or SMS ser"ice pro"ider. Then send SMS messa!es usin! a
protocol , interface supported y the SMS- or SMS !ateway.
In this article, I will e&plain the first way to send, read, and delete SMS usin! #T
commands. But efore startin!, I would like to e&plain a little it aout #T
commands.
AT Commands
#T commands are instructions used to control a modem. #T is the are"iation of
#Ttention. 2"ery command line starts with 3#T3 or 3at3. That4s why modem
commands are called #T commands. There are two types of #T commands'
1. Basic commands are #T commands that do not start with a 353. 6or e&ample,
D 0Dial1, # 0#nswer1, 7 07ook control1, and * 0/eturn to online data state1
are the asic commands.
2. 2&tended commands are #T commands that start with a 353. #ll .%) #T
commands are e&tended commands. 6or e&ample, 5-).%
0%end SMS messa!e1, 5-).8 08ist SMS messa!es1, and 5-)./
0/ead SMS messa!es1 are e&tended commands.
If you want to !et more information aout #T commands, then you can !et it on my
other article on -ode(ro+ect
here' http',,www.codepro+ect.com,KB,system,Introductionto#Tcommands.asp&.
Operating Modes
The SMS specification has defined two modes in which a .%),.(/% modem or
moile phone can operate. They are called SMS te&t mode and SMS (D9 mode.
0(D9 stands for (rotocol Data 9nit.1 The mode that a .%),.(/% modem or moile
phone is operatin! in determines the synta& of some SMS #T commands and the
format of the responses returned after e&ecution.
I am usin! SMS te&t mode in this article.
How to Test GSM Modem Connectivity Using Hyper Terminal
6irst, find the est .%) modem that suits the needs. I tested this application
with a :a"ecom 6#%T/#-K )12;6.
9nderstand the #T -ommand set re<uired to communicate with the modem.
-onnect the modem to the computer accordin! to the setup !uide specified in
the manual pro"ided with the .%) modem.
(ut a "alid %I) card into the moile phone or .%),.(/% modem.
-onnect your moile phone or .%),.(/% modem to a computer, and set up
the correspondin! wireless modem dri"er.
/un the )% 7yperTerminal y selectin! %tart -= (ro!rams -= #ccessories -=
-ommunications -= 7yperTerminal.
In the -onnection Description dialo! o&, enter a name and choose an icon
you like for the connection. Then click the *K utton.
In the -onnect To dialo! o&, choose the -*) port that your moile phone or
.%),.(/% modem is connectin! to in the Connect using como o&. 6or
e&ample, choose -*)1 if your moile phone or .%),.(/% modem is
connectin! to the -*)1 port. Then click the *K utton.
The (roperties dialo! o& comes out. 2nter the correct port settin!s for your
moile phone or .%),.(/% modem. Then click the *K utton.
To find the correct port settin!s that should e used with your moile phone
or .%),.(/% modem, consult the manual of your moile phone or
.%),.(/% modem.
Type 3#T3 in the main window. # response 3*K3 should e returned from the
moile phone or .%),.(/% modem.
If >*K? returns, it means your moile phone or .%),.(/% modem is
connected successfully.
#fter successful connection of the .%) ,.(/% modem with (-, you are ready to run
this application. Download the attached pro+ect and run the application.
Sending SMS through GSM Modem using AT Commands
Port Settings
In this ta, you will ha"e to do port settin!s which will e the same as you did in the
hyper terminal and then click the *K utton. If the modem is connected successfully,
a messa!e o& will appear with the messa!e >)odem is connected?.
-ollapse
public SerialPort OpenPort(string p_strPortName,
int p_uBaudRate, int p_uDataBits,
int p_uReadTimeout, int p_uWriteTimeout)
{
receieNo! " ne! #utoReset$ent(%alse)&
SerialPort port " ne! SerialPort()&
tr'
{
port(PortName " p_strPortName& //COM1
port(BaudRate " p_uBaudRate& //9600
port(DataBits " p_uDataBits& //8
port(StopBits " StopBits(One& //1
port(Parit' " Parit'(None& //None
port(ReadTimeout " p_uReadTimeout& //300
port(WriteTimeout " p_uWriteTimeout& //300
port($ncoding " $ncoding()et$ncoding(*iso+,,-.+/*)&
port(DataReceied 0" ne! SerialDataReceied$ent1andler
(port_DataReceied)&
port(Open()&
port(Dtr$nable " true&
port(Rts$nable " true&
2
catc3 ($4ception e4)
{
t3ro! e4&
2
return port&
2
Send SMS
In the second ta, you can send SMS'
-ollapse
public bool send5sg(SerialPort port, string P3oneNo, string 5essage)
{
bool isSend " %alse&
tr'
{
string recieedData " $4ec6ommand(port,*#T*, 788, *No p3one connected*)&
recieedData " $4ec6ommand(port,*#T065)9"/*, 788,
*9ailed to set message %ormat(*)&
String command " *#T065)S":** 0 P3oneNo 0 *:**&
recieedData " $4ec6ommand(port,command, 788,
*9ailed to accept p3oneNo*)&
command " 5essage 0 c3ar(6onert9rom;t%7<(<=) 0 *:r*&
recieedData " $4ec6ommand(port,command, 7888,
*9ailed to send message*)& >>7 seconds
i% (recieedData($ndsWit3(*:r:nO?:r:n*))
{
isSend " true&
2
else i% (recieedData(6ontains(*$RROR*))
{
isSend " %alse&
2
return isSend&
2
catc3 ($4ception e4)
{
t3ro! ne! $4ception(e4(5essage)&
2
2
Read SMS
In the third ta, you can read SMS'
-ollapse
public S3ort5essage6ollection ReadSMS(SerialPort port)
{
// Set up the phone and read the messages
S3ort5essage6ollection messages " null&
tr'
{
@region $4ecute 6ommand
// Check connection
$4ec6ommand(port,*#T*, 788, *No p3one connected*)&
// Use message format !e"t mode
$4ec6ommand(port,*#T065)9"/*, 788, *9ailed to set message %ormat(*)&
// Use character set #CC#$3%
$4ec6ommand(port,*#T06S6S":*P66PA7B:**, 788,
*9ailed to set c3aracter set(*)&
// Se&ect S'M storage
$4ec6ommand(port,*#T06P5S":*S5:**, 788,
*9ailed to select message storage(*)&
// (ead the messages
string input " $4ec6ommand(port,*#T065)C":*#CC:**, -888,
*9ailed to read t3e messages(*)&
@endregion
@region Parse messages
messages " Parse5essages(input)&
@endregion
2
catc3 ($4ception e4)
{
t3ro! ne! $4ception(e4(5essage)&
2
i% (messages D" null)
return messages&
else
return null&
2
elete SMS
In the fourth and last ta, you can count the numer of SMS and delete SMS as
well.
-ollapse
public bool Delete5sg(SerialPort port , string p_str6ommand)
{
bool isDeleted " %alse&
tr'
{
@region $4ecute 6ommand
string recieedData " $4ec6ommand(port,*#T*, 788, *No p3one connected*)&
recieedData " $4ec6ommand(port,*#T065)9"/*, 788,
*9ailed to set message %ormat(*)&
String command " p_str6ommand&
recieedData " $4ec6ommand(port,command, 788, *9ailed to delete
message*)&
@endregion
i% (recieedData($ndsWit3(*:r:nO?:r:n*))
{
isDeleted " true&
2
i% (recieedData(6ontains(*$RROR*))
{
isDeleted " %alse&
2
return isDeleted&
2
catc3 ($4ception e4)
{
t3ro! ne! $4ception(e4(5essage)&
2
2
Lesson 2
!ntroduction
SMS client and ser"er is an application software which is used for sendin! and
recei"in! messa!es0SMS1. It listens for incomin! messa!es to arri"e, processes the
messa!e if it4s in a "alid format. @ote the processin! of arri"ed messa!es depends on
the application which will e discussed later. I am !oin! to e&plain the followin!
thin!s'
1. -ommunication (ort %ettin!s
2. /ecei"e Incomin! )essa!e
A. %end )essa!es
B. /ead #ll )essa!es 0%ent y the users1
C. Delete )essa!es 0*ne or #ll1
I ha"e used the )S56omm 8irary for %endin! and /ecei"in! SMS. Dou re<uire a .%)
modem or phone for sendin! anSMS.
Using the code
"# Communication Port Settings
6ommSetting class is used for storin! comm port settin!s'
-ollapse
public class 6ommSetting
{
public static int 6omm_Port"8&
public static Ent=A 6omm_BaudRate"8&
public static Ent=A 6omm_TimeOut"8&
public static )sm6omm5ain comm&
public 6ommSetting()
{
//
// !O)O* +dd constructor &ogic here
//
2
2
6omm is an o+ect of type )sm6omm5ain which is re<uired for sendin! and recei"in!
messa!es. :e ha"e to set the6omm port, Baud rate and time out for our comm o+ect
of type )sm6omm5ain. Then try to open with the ao"e settin!s. :e can test the
-omm port settin!s y clickin! on the Test utton after selectin! the -omm port,
aud rate and Time out. %ometimes if the comm port is unale to open, you will !et
a messa!e 3@o phone connected3. This is mainly due to Baud rate settin!s. -han!e
the aud rate and check a!ain y clickin! the Test utton until you !et a messa!e
3%uccessfully connected to the phone.3
Before creatin! a )S56omm o+ect with settin!s, we need to "alidate the port
numer, aud rate and Timeout.
The $nterNe!Settings() does "alidation, returns true if "alid, and will
in"oke SetData(port,baud,timeout)for comm settin!.
The followin! lock of code will try to connect. If any prolem occurs 3(hone not
connected3 messa!e appears and you can either retry y clickin! on the /etry utton
or else -ancel.
-ollapse
)sm6omm5ain comm " ne! )sm6omm5ain(port, baudRate, timeout)&
tr'
{
comm(Open()&
!3ile (Dcomm(Es6onnected())
{
6ursor(6urrent " 6ursors(De%ault&
i% (5essageBo4(S3o!(t3is, *No p3one connected(*,
*6onnection setup*, 5essageBo4Buttons(Retr'6ancel,
5essageBo4Econ($4clamation) "" DialogResult(6ancel)
{
comm(6lose()&
return&
2
6ursor(6urrent " 6ursors(Wait6ursor&
2
// C&ose Comm port connection ,Since it-s .ust for testing
// connection/
comm(6lose()&
2
catc3($4ception e4)
{
5essageBo4(S3o!(t3is, *6onnection errorF * 0 e4(5essage,
*6onnection setup*, 5essageBo4Buttons(O?, 5essageBo4Econ(Warning)&
return&
2
// disp&a0 message if connection is a success1
5essageBo4(S3o!(t3is, *Success%ull' connected to t3e p3one(*,
*6onnection setup*, 5essageBo4Buttons(O?, 5essageBo4Econ(En%ormation)&
$# Receive !ncoming Message
:e are !oin! to re!ister the followin! e"ents for )S56omm o+ect comm.
1. P3one6onnected
This e"ent is in"oked when you try to open the -omm port. The e"ent handler
for (hone connected iscomm_P3one6onnected which will
in"oke OnP3one6onnection63ange(bool connected) with the help of
Dele!ate 6onnected1andler.
2. 5essageReceied
This e"ent is in"oked when a messa!e arri"es at the .%) phone. :e will
re!ister with5essageReceied$ent1andler. :hen the incomin! messa!e
arri"es, the comm_5essageReceiedmethod will e in"oked which in turn
calls the 5essageReceied() method in order to process the unread
messa!e. )S56omm o+ect comm has a method Read5essages which will e
used for readin! messa!es. It accepts the followin! parameters phone status
0#ll, ReceiedRead, Receied;nread, StoredSent, andStored;nsent1
and stora!e type' %I) memory or (hone memory.
-ollapse
priate oid 5essageReceied()
{
6ursor(6urrent " 6ursors(Wait6ursor&
string storage " )et5essageStorage()&
DecodedS3ort5essageGH messages " 6ommSetting(comm(Read5essages
(P3one5essageStatus(Receied;nread, storage)&
%oreac3(DecodedS3ort5essage message in messages)
{
Output(string(9ormat(*5essage status " {82,
Cocation " {/2>{<2*,
StatusToString(message(Status),
message(Storage, message(Ende4))&
S3o!5essage(message(Data)&
Output(**)&
2
Output(string(9ormat(*{8,.2 messages read(*,
messages(Cengt3(ToString()))&
Output(**)&
2
The ao"e code will read all unread messa!es from %I) memory. The
method S3o!5essage is used for displayin! the read messa!e. The messa!e may e
a status report, stored messa!e sent,un sent, or a recei"ed messa!e.
%# Send Message
Dou can send an SMS y keyin! in the destination phone numer and te&t messa!e.
If you want to send a messa!e in your nati"e lan!ua!e 09nicode1, you need to check
in %end as 9nicode09-%21.)S56omm o+ect comm has a Send5essage method which
will e used for sendin! SMS to any phone. -reate a (D9 for sendin! messa!es. :e
can create a (D9 in strai!ht forward "ersion as'
-ollapse
SmsSubmitPdu pdu " ne! SmsSubmitPdu
(t4t_message(Te4t,t4t_destination_numbers(Te4t,**)&
#n e&tended "ersion of (D9 is used when you are sendin! a messa!e in 9nicode.
-ollapse
tr'
{
// Send an SMS message
SmsSubmitPdu pdu&
bool alert " c3I#lert(63ecIed&
bool unicode " c3I;nicode(63ecIed&
i% (Dalert JJ Dunicode)
{
// !he straightfor2ard 3ersion
pdu " ne! SmsSubmitPdu
(t4t_message(Te4t, t4t_destination_numbers(Te4t,**)&
2
else
{
// !he e"tended 3ersion 2ith dcs
b'te dcs&
i% (Dalert JJ unicode)
dcs " Data6odingSc3eme(No6lass_/=Bit&
else
i% (alert JJ Dunicode)
dcs " Data6odingSc3eme(6lass8_BBit&
else
i% (alert JJ unicode)
dcs " Data6odingSc3eme(6lass8_/=Bit&
else
dcs " Data6odingSc3eme(No6lass_BBit&
pdu " ne! SmsSubmitPdu
(t4t_message(Te4t, t4t_destination_numbers(Te4t, **, dcs)&
2
// Send the same message mu&tip&e times if this is set
int times " c3I5ultipleTimes(63ecIed K
int(Parse(t4tSendTimes(Te4t) F /&
// Send the message the specified num4er of times
%or (int i"8&iLtimes&i00)
{
6ommSetting(comm(Send5essage(pdu)&
Output(*5essage {82 o% {/2 sent(*, i0/, times)&
Output(**)&
2
2
catc3($4ception e4)
{
5essageBo4(S3o!(e4(5essage)&
2
6ursor(6urrent " 6ursors(De%ault&
&# Read All Messages
Dou can read all messa!es from the phone memory of %I) memory. Eust click on
3/ead #ll )essa!es3 utton. The messa!e details such as sender, date-time, te&t
messa!e will e displayed on the Data .rid. -reate a new row for each read
messa!e, add to Data tale and assi!n the Data tale to data!rid4s source
-ollapse
priate oid Bind)rid(SmsPdu pdu)
{
DataRo! dr"dt(Ne!Ro!()&
SmsDelierPdu data " (SmsDelierPdu)pdu&
drG8H"data(Originating#ddress(ToString()&
drG/H"data(S6Timestamp(ToString()&
drG<H"data(;serDataTe4t&
dt(Ro!s(#dd(dr)&
data)rid/(DataSource"dt&
2
The ao"e code will read all unread messa!es from %I) memory. The
method S3o!5essage is used for displayin! the read messa!e. The messa!e may
e a status report, stored messa!e sent,un sent, or a recei"ed messa!e. The only
chan!e in processin! /ecei"ed messa!e and /ead messa!e is the first parameter.
'or received message
-ollapse
)ecodedShortMessage56 messages 7
CommSetting1comm1(eadMessages,#honeMessageStatus1(ecei3edUnread8 storage/9
'or read all messages
-ollapse
)ecodedShortMessage56 messages 7
CommSetting1comm1(eadMessages,#honeMessageStatus1+&&8 storage/9
(# elete Messages )One or All#
#ll messa!es which are sent y the users will e stored in %I) memory and we are
!oin! to display them in the Data !rid. :e can delete a sin!le messa!e y specifyin!
the messa!e inde& numer. :e can delete all messa!es from %I) memory y
clickin! on 3Delete #ll3 utton. )essa!es are deleted ased on the inde&. 2"ery
messa!e will e stored in memory with a uni<ue inde&.
The followin! code will delete a messa!e ased on inde&'
-ollapse
// )e&ete the message 2ith the specified inde" from storage
CommSetting1comm1)e&eteMessage,inde"8 storage/9
To delete all messa!es from memory0 %I),(hone1
-ollapse
// )e&ete a&& messages from phone memor0
CommSetting1comm1)e&eteMessages,)e&eteScope1+&&8 storage/9
The DeleteScope is an $num which contains'
1. #ll
2. Read
A. Read#ndSent
B. ReadSent#nd;nsent
Applications
7ere are some interestin! applications where you can use and modify this software.
"# Pre paid *lectricity
Scenario )Customer#
The customer has a!reed for pre paid electricity rechar!es with the help of rechar!e
coupons. The coupon is made a"ailale at shops. The customer will first uy the
coupons from shopsF e"ery coupon consists of -oupon (I@ which will e masked, the
customer needs to scratch to "iew the (I@ numer. The customer will send
an SMS to the SMS%er"er with a specified messa!e format for rechar!in!.
)essa!e 6ormat for /echar!in!'
R$61#R)$ L6oupon NoM L6ustomer EDM
Scenario )Server ata+ase#
*n the %er"er, the Dataase consists of -ustomer information alon! with his
telephone numer, there will a field named #mount which will e used and updated
when the customer rechar!ed with some amount. This application ecomes
somewhat comple&, an automatic meter readin! software alon! with hardware needs
to e inte!rated with this. #utomatic meter readin! systems will read all meter
readin!s and calculate the amount to e deducted for the customer.
$# Astrology
Dou can implement as astrolo!y software. The user will send an SMS with his $odiac
si!n. The SMS ser"er will maintain an #strolo!y Dataase with $odiac si!n and a te&t
description which contains a messa!e for the day. The Dataase is re<uired to e
updated daily for all $odiac si!ns.
)essa!e 6ormat which will e used y the user to !et messa!e of the day'
Nodiac Sign
%# Remote Controlling System
:e can implement a remote controllin! system, for e&ample you need to'
1. %hutdown
2. /estart
A. 8o! off system
Dou can send an SMS. The SMS ser"er will listen and then process the messa!e.
Based on the messa!e format sent y the user we can take action.
2&ample if messa!e format is'
S1;TDOWN
%end to SMS phone numer.
Conclusion
This pro+ect wouldn4t e completed unless I thank the )S56omm 8i de"eloper
3%tefan )ayr3. I customi$ed my application usin! this 8irary. Dou can download the
sample pro+ect, lirary from the we link which I pro"ided under the /eference
section.
Re,erence
http',,www.scampers.or!,ste"e, sms ,inde&.htm
-icense
This article has no e&plicit license attached to it ut may contain usa!e terms in the
article te&t or the download files themsel"es. If in dout please contact the author
"ia the discussion oard elow.
# list of licenses authors mi!ht use can e found here
A+out the Author
!ntroduction to AT commands and its uses
!ntroduction
#T commands are instructions used to control a modem. #T is the are"iation of
#Ttention. 2"ery command line starts with 3#T3 or 3at3. That4s why modem
commands are called #T commands.
@ote that the startin! 3#T3 is the prefi& that informs the modem aout the start of a
command line. It is not part of the #T command name. 6or e&ample, D is the actual
#T command name in #TD, and 5-).% is the actual #T command name in
#T5-).%.
Tas.s Per,ormed +y AT Commands
7ere are some of the tasks that can e done usin! #T commands with a .%),.(/%
modem or moile phone'
.et asic information aout the moile phone or .%),.(/% modem. 6or
e&ample, name of the manufacturer 0#T5-.)I1, model numer 0#T5-.))1,
I)2I numer 0International )oile 2<uipment Identity1 0#T5-.%@1, and the
software "ersion 0#T5-.)/1.
.et asic information aout the suscrier. 6or e&ample, )%I%D@ 0#T5-@9)1
and I)%I numer 0International )oile %uscrier Identity1 0#T5-I)I1.
.et the current status of the moile phone or .%),.(/% modem. 6or
e&ample, moile phone acti"ity status 0#T5-(#%1, moile network
re!istration status 0#T5-/2.1, radio si!nal stren!th 0#T5-%G1, attery
char!e le"el, and attery char!in! status 0#T5-B-1.
2stalish a data connection or "oice connection to a remote modem 0#TD,
#T#, etc.1.
%end and recei"e fa& 0#TD, #T#, #T56H1.
%end 0#T5-).%, #T5-)%%1, read 0#T5-)./, #T5-).81, write
0#T5-).:1, or delete 0#T5-).D1 SMSmessa!es and otain notifications of
newly recei"ed SMS messa!es 0#T5-@)I1.
/ead 0#T5-(B/1, write 0#T5-(B:1, or search 0#T5-(B61 phoneook entries.
(erform security-related tasks, such as openin! or closin! facility locks
0#T5-8-K1, checkin! whether a facility is locked 0#T5-8-K1, and chan!in!
passwords 0#T5-(:D1. 06acility lock e&amples' %I) lock Ia password must
e !i"en to the %I) card e"ery time the moile phone is switched onJ and (7-
%I) lock Ia certain %I) card is associated with the moile phoneF to use other
%I) cards with the moile phone, a password must e entered.J1
-ontrol the presentation of result codes , error messa!es of #T commands.
6or e&ample, you can control whether to enale certain error messa!es
0#T5-)221, and whether error messa!es should e displayed in numeric
format or "erose format 0#T5-)22K1 or #T5-)22K21.
.et or chan!e the confi!urations of the moile phone or .%),.(/% modem.
6or e&ample, chan!e the .%) network 0#T5-*(%1, earer ser"ice type
0#T5-B%T1, radio link protocol parameters 0#T5-/8(1, SMS center address
0#T5-%-#1, and stora!e of SMS messa!es 0#T5-()%1.
%a"e and restore confi!urations of the moile phone or .%),.(/% modem.
6or e&ample, sa"e 0#T5-%#%1 and restore 0#T5-/2%1 settin!s related
to SMS messa!in! such as the SMS center address.
@ote that moile phone manufacturers usually do not implement all #T commands,
command parameters, and parameter "alues in their moile phones. #lso, the
eha"ior of the implemented #T commands may e different from that defined in the
standard. In !eneral, .%),.(/% modems desi!ned for wireless applications ha"e
etter support of #T commands than ordinary moile phones.
Types o, AT Commands
There are two types of #T commands'
1. /asic commands are #T commands that do not start with 353. 6or e&ample,
D 0Dial1, # 0#nswer1, 7 07ook control1, and * 0/eturn to online data state1
are asic commands.
2. *0tended commands are #T commands that start with 353. #ll .%) #T
commands are e&tended commands. 6or e&ample, 5-).%
0%end SMS messa!e1, 5-).8 08ist SMS messa!es1, and 5-)./
0/ead SMS messa!es1 are e&tended commands.
General Synta0 o, AT Commands
The !eneral synta& of e&tended #T commands is strai!htforward. The synta& rules
are pro"ided elow'
Synta0 rule ". #ll command lines must start with 3#T3 and end with a carria!e
return character. In a terminal pro!ram like the 7yperTerminal of )icrosoft :indows,
you can press the 2nter key on the keyoard to output a carria!e return character.
2&ample' To list all unread inound SMS messa!es stored in the messa!e stora!e
area, type 3#T3, then the e&tended #T command 35-).83, and finally a carria!e
return character, like this'
-ollapse
#T065)C:C(;
Synta0 rule $. # command line can contain more than one #T command. *nly the
first #T command should e prefi&ed with 3#T3. #T commands in the same
command-line strin! should e separated with semicolons.
2&ample' To list all unread inound SMS messa!es stored in the messa!e stora!e
area and otain the manufacturer name of the moile de"ice, type 3#T3, then the
e&tended #T command 35-).83, followed y a semicolon and the ne&t e&tended #T
command 35-.)I3'
-ollapse
#T065)C&06)5E:C(;
#n error will occur if oth #T commands are prefi&ed with 3#T3, like this'
-ollapse
#T065)C&#T06)5E:C(;
Synta0 rule %. # strin! is enclosed etween doule <uotes.
2&ample' To read all SMS messa!es from a messa!e stora!e in SMS te&t mode,
you need to assi!n the strin! 3#883 to the e&tended #T command 5-).8, like this'
-ollapse
#T065)C"*#CC*:C(;
Synta0 rule &. Information responses and result codes 0includin! oth final result
codes and unsolicited result codes1 always start and end with a carria!e return
character and a linefeed character.
2&ample' #fter sendin! the command line 3#T5-.)I<CR>3 to the moile de"ice, the
moile de"ice should return a response similar to this'
-ollapse
:C(;:<=;NoIia:C(;:<=;
:C(;:<=;O?:C(;:<=;
The first line is the information response of the #T command 5-.)I, and the second
line is the final result code. <CR>and <LF> represent a carria!e return character
and a linefeed character, respecti"ely. The final result code 3*K3 marks the end of
the response. It indicates no more data will e sent from the moile de"ice to the
computer , (-.
:hen a terminal pro!ram such as the 7yperTerminal of )icrosoft :indows sees a
carria!e return character, it mo"es the cursor to the e!innin! of the current line.
:hen it sees a linefeed character, it mo"es the cursor to the same position on the
ne&t line. 7ence, the command line 3#T5-.)IL-/=3 that you entered and the
correspondin! response will e displayed like this in a terminal pro!ram such as
7yperTerminal of )icrosoft :indows'
-ollapse
#T06)5E
NoIia
O?
!n,ormation Response and 'inal Result Code
-ollapse
#T06)5E L++ 6ommand line entered
NoIia L++ En%ormation response
O? L++ 9inal result code
Result Code o, AT Commands
/esult codes are messa!es sent from the .%),.(/% modem or moile phone to
pro"ide you information aout the e&ecution of an #T command and the occurrence
of an e"ent. Two types of result codes are useful to you when dealin! with #T
commands for SMS messa!in!'
6inal result codes
9nsolicited result codes
'inal Result Code o, AT Commands
# final result code marks the end of an #T command response. It is an indication that
the .%),.(/% modem or moile phone has finished the e&ecution of a command
line. Two fre<uently used final result codes are *K and 2//*/. *nly one final result
code will e returned for each command line. Thus, you will not see oth *K and
2//*/ in the response of a command line.
The O1 'inal Result Code
The *K final result code indicates that a command line has een e&ecuted
successfully y the .%),.(/% modem or moile phone. It always starts and ends
with a carria!e return character and a linefeed character.
The *RROR 'inal Result Code
The 2//*/ final result code indicates that an error occurs when the .%),.(/%
modem or moile phone tries to e&ecute a command line. #fter the occurrence of an
error, the .%),.(/% modem or moile phone will not process the remainin! #T
commands in the command-line strin!.
Below are some common causes of error'
1. The synta& of the command line is incorrect.
2. The "alue specified to a certain parameter is in"alid.
A. The name of the #T command is spelt incorrectly.
B. The .%),.(/% modem or moile phone does not support one or more of the
#T commands, command parameters, or parameter "alues in the command-
line strin!.
8ike the *K final result code, the 2//*/ final result code always starts and ends with
a carria!e return character and a linefeed character.
'inal Result Code Speci,ic to SMS AT Commands
The final result codes *K and 2//*/ are a"ailale to all #T commands. 9nlike *K
and 2//*/, the 5-)% 2//*/ final result code is only a"ailale to SMS #T
commands. It notifies you aout the occurrence of a messa!e ser"ice failure.
Unsolicited Result Codes o, AT Commands
9nsolicited result codes are messa!es sent from the .%),.(/% modem or moile
phone to pro"ide you information aout the occurrence of an e"ent. 6or e&ample,
you can use the 5-@)I #T command 0command name in te&t' @ew )essa!e
Indications to T21 to re<uest the .%),.(/% modem or moile phone to send the
unsolicited result code 35-)TI3 to your computer , (- e"ery time a
new SMS messa!e is recei"ed from the SMS center.
How to Test GSM Modem Connectivity Using HyperTerminal
6irst, find the est .%) modem that suits the needs.
9nderstand the #T -ommand set re<uired to communicate with the modem.
-onnect the modem to the computer accordin! to the setup !uide specified in
the manual pro"ided with the .%) modem.
(ut a "alid %I) card into the moile phone or .%),.(/% modem.
-onnect your moile phone or .%),.(/% modem to a computer and set up
the correspondin! wireless modem dri"er.
/un )% 7yperTerminal y selectin! %tart -= (ro!rams -= #ccessories -=
-ommunications -= 7yperTerminal.
In the -onnection Description dialo! o&, enter a name and choose an icon
you like for the connection. Then click the *K utton.
In the -onnect To dialo! o&, choose the -*) port that your moile phone or
.%),.(/% modem is connectin! to in the Connect using como o&. 6or
e&ample, choose -*)1 if your moile phone or .%),.(/% modem is
connectin! to the -*)1 port. Then click the *K utton.
The (roperties dialo! o& comes out. 2nter the correct port settin!s for your
moile phone or .%),.(/% modem. Then click the *K utton.
To find the correct port settin!s that should e used with your moile phone
or .%),.(/% modem, consult the manual of your moile phone or
.%),.(/% modem.
Type 3#T3 in the main window. # response 3*K3 should e returned from the
moile phone or .%),.(/% modem.
If 3*K3 returns, it means your moile phone or .%),.(/% modem is
connected successfully '1.
-icense
Server pinger and SMS reporter via GSM Modem AT COMMA2
By Arash 3avadi M 1C Eun 2;;N
.@2T2.; -O1.; -O2.; .@2TA.; -OA.; .@2TA.C -O .@2T De" Intermediate
# software that pin!s many ser"ers inside a company and reports network health

See Also
)ore like this
)ore y this author
2A
Article /rowse Code Revisions )4#
B.6N 012 "otes1
Sponsored -in.s
Download source - BA.1B KB
!ntroduction
This is old code that I de"eloped for my friend workin! in a network maintenance
company many years a!o. 7e asked me to write a software to check the connecti"ity
of all computers on networks that he should admin and if there was a prolem send
him a SMS. :ith this stupid software, he successfully e&tended his +o into a lar!e
usiness.
How !t 5or.s
#ll you need is a .%) )odem usin! rs-2A2 or 9%B connection. Install it to a
computer on a network that you want to admin and deu! this pro+ect and !i"e the
software local machine names to monitor - the software fre<uently pin!s each
computer and if pin! failed for B times, adds an 2rr to the report list and when the
2rr report list reaches 1;; errs, sends my friend an SMS. Dou can make a etter
rule for reportin! and sendin! SMS.
'or Sending SMS6 7ou Should
1. -onnect your !sm modem throu!h -*) (ort or 9%B
2. (ro"ide (ort @umer
A. (ro"ide your local call ser"ice for your own country
B. :rite messa!e and destination numer
C. %end
Pinger
I +ust took the code of loadin! circle from an article named 8oadin! -ircle y )artin
.a!ne and turned it to a pin!in! and status module that I used it a lot, thanks )artin
P
Serer63ecIing() function is called e"ery time the loadingcircle control turns
one cycle. This function sends a pin! packa!e to network 0for more information
aout pin!, click here1.
-ollapse
string bu% " *aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*&
public irtual oid Serer63ecIing()
{
i% ( _serer63ecIing$nable "" %alse OO string(EsNullOr$mpt'( _sererName))
return&
string !3o " SererName&// args5069
S'stem(T3reading(#utoReset$ent !aiter " ne!
S'stem(T3reading(#utoReset$ent(%alse)&
S'stem(Net(Net!orIEn%ormation(Ping pingSender "
ne! S'stem(Net(Net!orIEn%ormation(Ping()&
pingSender(Ping6ompleted 0" ne! S'stem(Net(Net!orIEn%ormation(
Ping6ompleted$ent1andler(Ping6ompleted6allbacI)&
string data " bu%&
b'teGH bu%%er " $ncoding(#S6EE()etB'tes(data)&
int timeout " /888&
S'stem(Net(Net!orIEn%ormation(PingOptions options "
ne! S'stem(Net(Net!orIEn%ormation(PingOptions(=A, true)&
pingSender(Send#s'nc(!3o, timeout, bu%%er, options, !aiter)&
2
#nd as pin! reply is recei"ed or there is a pin! error, you can specify the status
on loadingcircle y chan!in! the color of it'
-ollapse
public S'stem(Net(Net!orIEn%ormation(PingRepl' repl'&

public eent $ent1andlerLconnectionstateeentargM 6onnectionState63anged&
internal 6onnectionState$ent#rg state " ne! 6onnectionState$ent#rg()&
protected int succ " 8&
protected int %ail " 8&
oid Ping6ompleted6allbacI(obPect sender,
S'stem(Net(Net!orIEn%ormation(Ping6ompleted$ent#rgs e)
{
i% (e(Repl' D" null)
{
repl' " e(Repl'&
state($4actReason " e&
_serer6onnectionState " e(Repl'(Status(ToString()&
state(Ne!Repl' " e(Repl'(Status&
i% (repl'(Status "" S'stem(Net(Net!orIEn%ormation(EPStatus(Success)
{
i% (succ M A)
{
t3is(6olor " 6olor(Pale)reen&
t3is(RotationSpeed " A88&
state(Ne!State " 6onnectionStatus(6onnectedPer&
2
else
{
t3is(RotationSpeed " ,8&
t3is(6olor " 6olor(Blue&
state(Ne!State " 6onnectionStatus(6onnectedTem&
2
succ00&
%ail " 8&
Serer6onnected " true&
2
else i% (repl'(Status ""
S'stem(Net(Net!orIEn%ormation(EPStatus(TimedOut)
{
i% (%ail M A)
{
t3is(RotationSpeed " A88&
t3is(6olor " 6olor(Cig3tPinI&
state(Ne!State " 6onnectionStatus(DisconnectedPer&
2
else
{
t3is(RotationSpeed " ,8&
t3is(6olor " 6olor(Orange&
state(Ne!State " 6onnectionStatus(DisconnectedTem&
2
Serer6onnected " %alse&
%ail00&
succ " 8&
2
else
{
t3is(RotationSpeed " ,8&
t3is(6olor " 6olor(DarIRed&
succ " 8&
Serer6onnected " %alse&
state(Ne!State " 6onnectionStatus(Ot3er&
%ail00&
2
%or (int i " 8& i L e(Repl'(Bu%%er(Cengt3& i00)
{
i% (e(Repl'(Bu%%erGiH D" (b'te)bu%GiH)
{
t3is(6olor " 6olor(Purple&
state(Ne!State " 6onnectionStatus(Transmit5ismac3&
2
2
2
else
{
t3is(RotationSpeed " A88&
t3is(6olor " 6olor(BlacI&
succ " 8&
Serer6onnected " %alse&
state(Ne!State " 6onnectionStatus(Ot3er&
%ail00&
2
i% (t3is(6onnectionState63anged D" null)
t3is(6onnectionState63anged(t3is, state)&
2
GSM Handler
(erhaps you need one of these for sendin! SMS'
.%) )odems are workin! with #T -ommand. 7ere is a component that I wrote for
.%) )odem %endin! and recei"in!SMS'
-ollapse
public class )S55anager F 6omponent
{
public CistLsmsmessageM Recied5essages " ne! CistLsmsmessageM()&
public CistLsmsmessageM Sending5essages " ne! CistLsmsmessageM()&
Timer timer " ne! Timer()&
public )S55anager()
{
timer(Enteral " /888&
2
bool )O " %alse&
bool O? " %alse&
bool $RROR " %alse&
public S'stem(EO(Ports(SerialPort comPort " ne!
S'stem(EO(Ports(SerialPort()&
//pu4&ic 3oid Send
public bool SMS$nable " true&
public oid SMS6on%ig()
{
i% (comPort(EsOpen "" %alse)
{
comPort(PortName "
globalFFCoading6ircleTester(Properties(Settings(De%ault(6O5PortName&
comPort(BaudRate " //-<88&
comPort(Parit' " Parit'(None&
comPort(StopBits " StopBits(One&
comPort(DataBits " ,&
comPort(ReadBu%%erSiQe " /8888&
comPort(ReadTimeout " /888&
comPort(WriteBu%%erSiQe " /8888&
comPort(WriteTimeout " /8888&
comPort(Rts$nable " true&
// com#ort1)ata(ecei3ed >7 ne2 Seria&)ata(ecei3ed?3ent@and&er
// ,com#ortA(ead'ncommingSMS/9
2
i% (comPort(EsOpen "" %alse)
{
comPort(DataReceied +" ne! SerialDataReceied$ent1andler
(comPort_ReadEncommingSMS)&
comPort(Rts$nable " %alse &
comPort(6lose()&
tr' { comPort(Open()& 2
catc3 ($4ception e4)
{
i% (SMS$nable "" true)
{
SMS$nable " %alse&
5essageBo4(S3o!(*Port(* 0 comPort(PortName 0 *)
6ould not be Opened :n:r 63ecI 'our )S5 Deice 6onnection*)&
2
SMS$nable " %alse&
return&
2

comPort(Rts$nable " true&
comPort(DataReceied 0" ne! SerialDataReceied$ent1andler
(comPort_ReadEncommingSMS)&
2
comPort(DiscardEnBu%%er()&
comPort(DiscardOutBu%%er()&
string s " **&
>>>
comPort(Write(*#T065)9"/* 0 (c3ar)/7)&
>>>
)O " %alse& $RROR " %alse& O? " %alse&
%or (int i " 8& i L /88& i00)
{
i% (O? "" true)
breaI&
i% ($RROR "" true)
{
//MessageBo"1Sho2,?((O(/9
SMS$nable " true&
2
S'stem(T3reading(T3read(Sleep(/-)& i% (i "" /88)
{ $RROR " true& SMS$nable " %alse& 2
2
SMS$nable " true&
return &
2
oid SMS_is_Disable()
{
2
public SMS5essage Read$4istingSMS(int 5essageEnde4)
{
DateTime t/ " DateTime(No!&
Readed " **&

SMS_is_Disable()&
>>>
comPort(Write(*#T065)R"* 0 5essageEnde4(ToString() 0 (c3ar)/7)&
>>>
)O " %alse& $RROR " %alse& O? " %alse&
%or (int i " 8& i L /88& i00)
{
i% (O? "" true)
breaI&
i% ($RROR "" true)
{
//MessageBo"1Sho2,?((O(/9
return null&
2
S'stem(T3reading(T3read(Sleep(/-)& i% (i "" /88) $RROR " true&
2
SMS5essage mess " ne! SMS5essage()&
int I " 8&
bool mess$rr " %alse&
int l " 8&
%or (int P " 8& P L 7& P00)
{
i% (I "" +/ OO l "" +/) { mess$rr " true& continue& 2
I " Readed(Ende4O%(*:**, l)&
i% (I "" +/ OO l "" +/) { mess$rr " true& continue& 2
l " Readed(Ende4O%(*:**, I 0 /)&
i% (I "" +/ OO l "" +/) { mess$rr " true& continue& 2
string inc " Readed(Substring(I 0 /, l + I + /)&
i% (P "" / JJ mess$rr "" %alse)
mess(P3oneNo " inc&
i% (P "" < JJ mess$rr "" %alse)
mess(Time " DateTime(Parse(inc)&
l00&
2
i% (mess$rr "" %alse)
{
mess(5essage " Readed(Substring(l 0 <, Readed(Cengt3 + l + < + ,)&
mess(Status " SMS5essage(SMS5essageStatus(Recied&
DateTime t< " DateTime(No!&
return mess&
2
//MessageBo"1Sho2,,,!imeSpan/tC1Su4tract,t1//1Mi&&iseconds1!oString,//9
return null&
2
public enum ReadEncommingSMST'pe
{
R$6_;NR$#D " 8,
R$6_R$#D " /,
STO_;NS$NT " <,
STO_S$NT " 7,
#CC " A
2
public oid Delete$4istingSMS(int inde4)
{
SMS_is_Disable()&
Readed " **&
comPort(Write(*#T065)D"* 0 inde4(ToString() 0 (c3ar)/7)&
)O " %alse& $RROR " %alse& O? " %alse&
%or (int i " 8& i L /88& i00)
{
i% (O? "" true)
breaI&
i% ($RROR "" true)
{
//MessageBo"1Sho2,?((O(/9
// return nu&&9
2
S'stem(T3reading(T3read(Sleep(/-)& i% (i "" /88) $RROR " true&
2
2
public string SendSMS(SMS5essage sms)
{
return SendSMS(sms(P3oneNo, sms(5essage)&
2
public string callserice&
public string SendSMS(string P3oneNo, string 5essage )
{
SMS_is_Disable()&
string s " **&
comPort(Write(*#T06S6#":**0callserice0*:** 0 (c3ar)/7)&

)O " %alse& $RROR " %alse& O? " %alse&
%or (int i " 8& i L /88& i00)
{
i% (O? "" true)
breaI&
i% ($RROR "" true)
{
5essageBo4(S3o!(*$RROR*)&
return *$RROR*&
2
S'stem(T3reading(T3read(Sleep(/-)& i% (i "" /88) $RROR " true&
2
>>>
comPort(Write(*#T065)S":** 0 P3oneNo 0 *:** 0 (c3ar)/7)&
>>>
)O " %alse& $RROR " %alse& O? " %alse&
%or (int i " 8& i L /88& i00)
{
i% (O? "" true)
breaI&
i% ($RROR "" true)
{
5essageBo4(S3o!(*$RROR*)&
return *$RROR*&
2
S'stem(T3reading(T3read(Sleep(/-)& i% (i "" /88) $RROR " true&
2
s 0" *:r* 0 comPort(Read$4isting()&
>>>
comPort(Write(5essage 0 (c3ar)<=)&// Char1Con3ert=romUtf3C,C6//9
>>>
)O " %alse& $RROR " %alse& O? " %alse&
%or (int i " 8& i L /88& i00)
{
i% (O? "" true)
{
breaI&
2
i% ($RROR "" true)
{
5essageBo4(S3o!(*$RROR*)&
return *$RROR*&
2
S'stem(T3reading(T3read(Sleep(/-)& i% (i "" /88) $RROR " true&
2
s 0" *:r* 0 comPort(Read$4isting()&

comPort(6lose()&
return s&
2
public CistLsmsmessageM ReadEncommingSMS(ReadEncommingSMST'pe t'pe)
{
DateTime t/ " DateTime(No!&
Readed " **&
SMS_is_Disable()&
i% (SMS$nable "" %alse) return null&
s!itc3 (t'pe)
{
case ReadEncommingSMST'pe(STO_S$NTF
comPort(Write(*#T065)C":*STO S$NT:** 0 (c3ar)/7)&
breaI&
case ReadEncommingSMST'pe(R$6_;NR$#DF
comPort(Write(*#T065)C":*R$6 ;NR$#D:** 0 (c3ar)/7)&
breaI&
case ReadEncommingSMST'pe(#CCF
comPort(Write(*#T065)C":*#CC:** 0 (c3ar)/7)&
breaI&
case ReadEncommingSMST'pe(R$6_R$#DF
comPort(Write(*#T065)C":*R$6 R$#D:** 0 (c3ar)/7)&
breaI&
case ReadEncommingSMST'pe(STO_;NS$NTF
comPort(Write(*#T065)C":*STO ;NS$NT:** 0 (c3ar)/7)&
breaI&
2
)O " %alse& $RROR " %alse& O? " %alse&
%or (int i " 8& i L /88& i00)
{
i% (O? "" true)
breaI&
i% ($RROR "" true)
{
//MessageBo"1Sho2,?((O(/9
return null&
2
S'stem(T3reading(T3read(Sleep(/-)& i% (i "" /88)
{ $RROR " true& t3is(SMS$nable " %alse& return null& 2
2
CistLsmsmessageM messCist " ne! CistLsmsmessageM()&

stringGH re " Readed(Split(ne! stringGH { *065)CF* 2,
StringSplitOptions(Remoe$mpt'$ntries)&
%or (int i " /& i L re(Cengt3& i00)
{
int I " 8&
bool mess$rr " %alse&
int l " 8&
string Str " reGiH&
SMS5essage mess " ne! SMS5essage()&
string ind " Str(Substring(8, Str(Ende4O%(*,*))(Trim()&
mess(inde4 " int(Parse(ind)&
%or (int P " 8& P L 7& P00)
{
i% (I "" +/ OO l "" +/) { mess$rr " true& continue& 2
I " Str(Ende4O%(*:**, l)&
i% (I "" +/ OO l "" +/) { mess$rr " true& continue& 2
l " Str(Ende4O%(*:**, I 0 /)&
i% (I "" +/ OO l "" +/) { mess$rr " true& continue& 2
string inc " Str(Substring(I 0 /, l + I + /)&
i% (P "" / JJ mess$rr "" %alse)
mess(P3oneNo " inc&
i% (P "" < JJ mess$rr "" %alse)
mess(Time " DateTime(Parse(inc)&
l00&
2
i% (mess$rr "" %alse)
{
mess(5essage " Str(Substring(l 0 <, Str(Cengt3 + l 0 < + ,0<)&
mess(5essage " mess(5essage(Replace(*:r:nO?*, **)&
mess(Status " SMS5essage(SMS5essageStatus(Recied&
messCist(#dd(mess)&
2
2
//MessageBo"1Sho2,,,!imeSpan/tC1Su4tract,t1//1Mi&&iseconds1!oString,//9
return messCist&
2
string Readed " **&
oid comPort_ReadEncommingSMS(obPect sender, SerialDataReceied$ent#rgs e)
{
SMS_is_Disable()&
S'stem(EO(Ports(SerialPort SP " (S'stem(EO(Ports(SerialPort)sender&
string s " SP(Read$4isting()&
Readed0"s&
i% (Readed($ndsWit3(*O?:r:n*) OO Readed($ndsWit3(*:r:nM *) OO
Readed($ndsWit3(((c3ar)<=)(ToString()))
O? " true&
i% (Readed($ndsWit3(*$RROR:r:n*))
$RROR " true&

//s 7 S#1(ead?"isting,/9
2
2
/ememer this is a "ery old code of mine. It re<uires a lot more chan!es. I hope this
helps you.
Qisit 7e&:ay for more of my software.
-icense
This article, alon! with any associated source code and files, is licensed under The
-ode (ro+ect *pen 8icense 0-(*81
A+out the Author
Arash 3avadi
%oftware De"eloper
0Eunior1
Iran 0Islamic
/epulic *f1
)emer
he studied )-%D 0-O ased 2;;A1 and )-DB# 02;;C1 -:@#,
-:@( at %ematech
I- (ro!rammin! with R;C1, #Q/ , I- desi!hn with 6(.# and
oard desi!h at -ontronic -o
7e also worked on :ireless 8ow le"el T-(,I( (ro!rammale
)odule and "ideo motion Detection al!orithm
he is student of Industrial en!ineerin! in 9ni"ersity of (ayam e
noor Tehran learnin! aout ()B*K and mana!ement systems.
7e has -ertificate in #d"anced 2n!lish 0-#21 and also he
studied .erman lan!ua!e in Skf Ssterreichisches Kulturforum

You might also like