Documentos de Académico
Documentos de Profesional
Documentos de Cultura
asp
As suggested by the name "Short Message Service", the data that can be held by an SMS
message is very limited. One SMS message can contain at most 140 bytes (1120 bits) of data,
so one SMS message can contain up to:
• 160 characters if 7-bit character encoding is used. (7-bit character encoding is suitable
for encoding Latin characters like English alphabets.)
• 70 characters if 16-bit Unicode UCS2 character encoding is used. (SMS text messages
containing non-Latin characters like Chinese characters should use 16-bit character
encoding.)
SMS text messaging supports languages internationally. It works fine with all languages
supported by Unicode, including Arabic, Chinese, Japanese and Korean.
Besides text, SMS messages can also carry binary data. It is possible to send ringtones,
pictures, operator logos, wallpapers, animations, business cards (e.g. VCards) and WAP
configurations to a mobile phone with SMS messages.
One major advantage of SMS is that it is supported by 100% GSM mobile phones. Almost all
subscription plans provided by wireless carriers include inexpensive SMS messaging service.
Unlike SMS, mobile technologies such as WAP and mobile Java are not supported on many old
mobile phone models.
The drawback of concatenated SMS is that it is less widely supported than SMS on wireless
devices.
1.3. EMS (Enhanced Messaging Service)
Besides the data size limitation, SMS has another major drawback -- an SMS message cannot
include rich-media content such as pictures, animations and melodies. EMS (Enhanced
Messaging Service) was developed in response to this. It is an application-level extension of
SMS. An EMS message can include pictures, animations and melodies. Also, the formatting of
the text inside an EMS message is changeable. For example, the message sender can specify
whether the text in an EMS message should be displayed in bold or italic, with a large font or a
small font.
The drawback of EMS is that it is less widely supported than SMS on wireless devices. Also,
many EMS-enabled wireless devices only support a subset of the features defined in the EMS
specification. A certain EMS feature may be supported on one wireless device but not on the
other.
2.4. SMS Messages are Supported by 100% GSM Mobile Phones and
They can be Exchanged between Different Wireless Carriers
SMS messaging is a very mature technology. All GSM mobile phones support it. Not only that
you can exchange SMS messages with mobile users of the same wireless carrier, but you can
also exchange SMS messages with mobile users of many other wireless carriers worldwide.
• Firstly, SMS messaging is supported by 100% GSM mobile phones. Building wireless
applications on top of the SMS technology can maximize the potential user base.
• Secondly, SMS messages are capable of carrying binary data besides text. They can be
used to transfer ringtones, pictures, operator logos, wallpapers, animations, VCards,
VCals (calendar entries), etc.
• Thirdly, SMS supports reverse billing, which enables payment to be made conveniently.
For example, suppose you want to develop a commercial ringtone download application
that charges a fee from the user for each ringtone downloaded. One way to accept
payment is to use a reverse billing phone number obtained from a wireless carrier. To
buy a ringtone, the user will write an ordinary SMS text message that contains the ID of
the ringtone he/she wants to buy and send it to your SMS application's reverse billing
phone number. Your SMS application will then send back one or more reverse billing
SMS messages that carry the ringtone. The user will be charged a fee for the reverse
billing SMS messages he/she received. The fee will be included in the user's monthly
mobile phone bill or be deducted from his/her prepaid card credits. Depending on the
agreement between you and the wireless carrier, all or part of the money received will be
given to you.
A chat application is another kind of person-to-person text messaging application that allows a
group of people to exchange SMS text messages interactively. In a chat application, all SMS
text messages sent and received are displayed on the mobile phone's screen in order of date
and time. SMS text messages written by different mobile users may be displayed in different
colors for better readability, like this:
Tom: OK.
3.3. Downloading
SMS messages can carry binary data and so SMS can be used as the transport medium of
wireless downloads. Objects such as ringtones, wallpapers, pictures and operator logos can be
encoded in one or more SMS messages depending on the object's size. Like information
services, wireless download services are usually not free and reverse billing SMS is a common
way used by content providers to bill their customers. The object to be downloaded is encoded
in one or more reverse billing SMS messages. The mobile user who requests the object will be
charged a certain fee for each reverse billing SMS message received. If the mobile user is using
a monthly mobile phone service plan, the download fee will be included in his/her next monthly
bill; if the mobile user is using a prepaid SIM card, the download fee will be deducted from the
prepaid credits.
1. A mobile phone is a device that is carried by its owner most of the time. Whenever an
SMS text message is received, the mobile phone will notify you by giving out a sound or
by vibrating. You can check what the SMS text message contains immediately.
2. SMS technology allows the "push" of information. This is different from the "pull" model
where a device has to poll the server regularly in order to check whether there is any
new information. The "pull" model is less suitable for alert and notification applications,
since it wastes bandwidth and increases server load.
Some common examples of SMS alert and notification applications are described below.
• To find out the meaning of the term "SMS text messaging", you can type "find: SMS text
messaging" in an SMS text message and send it to the search engine's phone number.
After receiving your SMS text message, the search engine parses it and finds that it
begins with the command "find" and follows by the words "SMS text messaging". The
search engine then knows you want to find out the meaning of the term "SMS text
messaging". So, it sends a text message, which contains the meaning of the term "SMS
text messaging", back to your mobile phone.
• If the search result is very long and it cannot contain within a single SMS text message,
the search engine adds "Page 1 of 2", "Page 1 of 3", etc, at the end of the reply SMS
text message. The search engine also creates a session using your mobile phone
number as the session ID and stores the term that you searched for (i.e. "SMS text
messaging") in the session object.
• To request the second page, you can send a text message with the content "page: 2" to
the search engine's phone number. After receiving your SMS text message, the search
engine parses it and finds that it begins with the command "page" and follows by "2".
The search engine then knows you want the second page of the search result. It
retrieves the term that you searched for last time from the session object and finds that it
is "SMS text messaging". The search engine then sends a text message that contains
the second page of the search result for the term "SMS text messaging" back to your
mobile phone.
Many other two-way interactive text messaging applications can be built using a similar way. For
example, a company may want to build an SMS messaging application to enable its employees
to query the corporate database while they are working outdoors.
3.6. SMS Marketing
SMS messaging can be used as a marketing tool. An example is an SMS newsletter system.
After signing up, the user will receive SMS text messages about the latest discounts and
products of the company. If the user has any questions or comments, he/she can send a text
message back with the questions or comments in it. The company may include its phone
number in the SMS newsletter so that the user can talk to the customer service staff directly if
he/she wants to do so.
Very often an SMSC is dedicated to handle the SMS traffic of one wireless network. A network
operator usually manages its own SMSC(s) and locates them inside its wireless network
system. However, it is possible for a network operator to use a third-party SMSC that is located
outside the wireless network system.
You must know the address of the wireless network operator's SMSC in order to use SMS
messaging with your mobile phone. Typically an SMSC address is an ordinary phone number in
the international format. A mobile phone should have a menu option that can be used to
configure the SMSC address. Normally, the SMSC address is pre-set in the SIM card by the
wireless network operator, which means you do not need to make any changes to it.
Here is an example that illustrates how validity period can be used. Suppose you find a very
interesting program that is showing on TV now. You think your friend may want to watch it. So,
you send a text message to tell your friend about the TV program. Let's say the TV program
lasts for an hour. Your SMS text message will not be useful to your friend if his mobile phone is
not available before the program finishes. In this situation, you may want to send a text
message with a validity period of one hour to your friend. The wireless carrier will not deliver the
SMS text message to your friend if his mobile phone is not available before the validity period
ends.
A mobile phone should have a menu option that can be used to set the validity period. After
setting it, the mobile phone will include the validity period in the outbound SMS messages
automatically.
A mobile phone should have a menu option that can be used to set whether the status report
feature is on or off. After setting it, the mobile phone will set the corresponding flag in the
outbound SMS messages for you automatically. The status report feature is turned off by default
on most mobile phones and GSM / GPRS modems.
If the mobile phone does not receive the message submission report after a period of time, it
concludes that the message submission report has been lost. The mobile phone may then re-
send the SMS message to the SMS center. A flag will be set in the new SMS message to inform
the SMS center that this SMS message has been sent before. If the previous message
submission was successful, the SMS center will ignore the new SMS message but send back a
message submission report to the mobile phone. This mechanism prevents the sending of the
same SMS message to the recipient multiple times.
Sometimes the message submission report mechanism is not used and the acknowledgement
of message submission is done in a lower layer.
If the sender requested a status report earlier, the SMS center sends a status report to the
sender when it receives the message delivery report from the recipient.
If the SMS center does not receive the message delivery report after a period of time, it
concludes that the message delivery report has been lost. The SMS center then re-sends the
SMS message to the recipient.
Sometimes the message delivery report mechanism is not used and the acknowledgement of
message delivery is done in a lower layer.
Typically, the cost for sending an intra-operator SMS message from a mobile phone is lower
than that for sending other kinds of SMS messages such as inter-operator SMS messages.
Some wireless network operators allow their subscribers to send unlimited intra-operator SMS
messages free of charge.
When the SMS center receives the message delivery report from the recipient mobile phone or
removes the SMS message (for example, when the validity period expires), it sends a status
report to the sender if the sender requested one earlier.
The following figure illustrates the transmission process of an intra-operator SMS message:
7. Inter-operator SMS Messages
Suppose you and your friend are using the mobile phone service of wireless network operator A
and wireless network operator B respectively. The transmission of an SMS message from you
to your friend involves two wireless networks. This SMS message is called an inter-operator
SMS message.
Typically, the cost for sending an inter-operator SMS message from a mobile phone is higher
than that for sending an intra-operator SMS message.
Usually the cost for sending an international SMS message from a mobile phone is higher than
that for sending a local inter-operator SMS message. Hence, the cost for sending an intra-
operator SMS message <= the cost for sending a local inter-operator SMS message <= the cost
for sending an international SMS message.
The interoperability of SMS messaging between two wireless networks locally and even
internationally is undoubtedly a main factor that contributes to the success of SMS worldwide.
Besides wireless carriers, content providers and SMS application developers may also find an
SMS gateway useful. Let's consider the following situation. Suppose you are the developer of
an SMS text messaging application. To send and receive SMS text messages on your server,
one way is to connect to the SMSCs of the wireless carriers. Different wireless carriers may use
SMSCs from different vendors, which means your SMS text messaging application may need to
support multiple SMSC-specific protocols. (This is illustrated in the following figure). As a result,
the SMS text messaging application's complexity and development time increases.
Figure 2. An SMS text messaging application connects to SMSCs without an SMS gateway.
To deal with the above problem, an SMS gateway can be set up to handle the connections to
the SMSCs. Now the SMS text messaging application only needs to know how to connect to the
SMS gateway. To support more SMSCs, you just need to modify the settings of the SMS
gateway. No change to the source code of the SMS text messaging application is required. The
use of an SMS gateway can greatly shorten the SMS text messaging application's development
time.
To connect to an SMS gateway, you can use an SMSC protocol such as SMPP and CIMD.
Some SMS gateways support an HTTP / HTTPS interface. HTTP / HTTPS is easier to use than
SMSC protocols. The drawback is that there may be fewer SMS features to use. For example,
an SMS gateway may not support the sending of picture messages through the HTTP / HTTPS
interface.
Figure 3. An SMS text messaging application connects to SMSCs through an SMS gateway.
Besides using a direct connection to the SMSC of a wireless carrier, another way to send and
receive SMS text messages on a computer is to use a mobile phone or GSM/GPRS modem. To
do this, your SMS text messaging application has to know how to communicate with the mobile
phone or GSM/GPRS modem using AT commands.
Some SMS gateways are capable of handling the connections to mobile phones and
GSM/GPRS modems. To send and receive SMS text messages with a mobile phone or
GSM/GPRS modem, the SMS text messaging application only needs to know how to talk to the
SMS gateway and does not need to know anything about AT commands. More details about
GSM/GPRS modems and AT commands will be provided in later sections of this SMS tutorial.
Figure 4. An SMS text messaging application connects to a pool of mobile phones or GSM/GPRS modems
through an SMS gateway.
1. Connect a mobile phone or GSM/GPRS modem to a computer / PC. Then use the
computer / PC and AT commands to instruct the mobile phone or GSM/GPRS modem to
send SMS messages.
2. Connect the computer / PC to the SMS center (SMSC) or SMS gateway of a wireless
carrier or SMS service provider. Then send SMS messages using a protocol / interface
supported by the SMSC or SMS gateway.
If you do not want to develop SMS software or applications but just want to use your computer /
PC to send text messages, you may want to read our Quick Guide for Non-Developers.
10.1. The 1st Way: Sending SMS Messages from a Computer Using a
Mobile Phone or GSM/GPRS Modem
The SMS specification has defined a way for a computer to send SMS messages through a
mobile phone or GSM/GPRS modem. A GSM/GPRS modem is a wireless modem that works
with GSM/GPRS wireless networks. A wireless modem is similar to a dial-up modem. The main
difference is that a wireless modem transmits data through a wireless network whereas a dial-
up modem transmits data through a copper telephone line. More information about GSM/GPRS
modems will be provided in the section "Introduction to GSM / GPRS Wireless Modems". Most
mobile phones can be used as a wireless modem. However, some mobile phones have certain
limitations comparing to GSM/GPRS modems. This will be discussed in the section "Which is
Better: Mobile Phone or GSM / GPRS Modem" later.
To send SMS messages, first place a valid SIM card from a wireless carrier into a mobile phone
or GSM/GPRS modem, which is then connected to a computer. There are several ways to
connect a mobile phone or GSM/GPRS modem to a computer. For example, they can be
connected through a serial cable, a USB cable, a Bluetooth link or an infrared link. The actual
way to use depends on the capability of the mobile phone or GSM/GPRS modem. For example,
if a mobile phone does not support Bluetooth, it cannot connect to the computer through a
Bluetooth link.
After connecting a mobile phone or GSM/GPRS modem to a computer, you can control the
mobile phone or GSM/GPRS modem by sending instructions to it. The instructions used for
controlling the mobile phone or GSM/GPRS modem are called AT commands. (AT commands
are also used to control dial-up modems for wired telephone system.) Dial-up modems, mobile
phones and GSM/GPRS modems support a common set of standard AT commands. In addition
to this common set of standard AT commands, mobile phones and GSM/GPRS modems
support an extended set of AT commands. One use of the extended AT commands is to control
the sending and receiving of SMS messages.
The following table lists the AT commands that are related to the writing and sending of SMS
messages:
AT command Meaning
One way to send AT commands to a mobile phone or GSM/GPRS modem is to use a terminal
program. A terminal program's function is like this: It sends the characters you typed to the
mobile phone or GSM/GPRS modem. It then displays the response it receives from the mobile
phone or GSM/GPRS modem on the screen. The terminal program on Microsoft Windows is
called HyperTerminal. More details about the use of Microsoft HyperTerminal can be found in
the "How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile Phone or
GSM/GPRS Modem" section of this SMS tutorial.
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to send an SMS text message. The lines in bold
type are the command lines that should be entered in HyperTerminal. The other lines are
responses returned from the GSM / GPRS modem or mobile phone.
AT
OK
AT+CMGF=1
OK
AT+CMGW="+85291234567"
> A simple demo of SMS text messaging.
+CMGW: 1
OK
AT+CMSS=1
+CMSS: 20
OK
• Line 1: "AT" is sent to the GSM / GPRS modem to test the connection. The GSM /
GPRS modem sends back the result code "OK" (line 2), which means the connection
between the HyperTerminal program and the GSM / GPRS modem works fine.
• Line 3: The AT command +CMGF is used to instruct the GSM / GPRS modem to
operate in SMS text mode. The result code "OK" is returned (line 4), which indicates the
command line "AT+CMGF=1" has been executed successfully. If the result code
"ERROR" is returned, it is likely that the GSM / GPRS modem does not support the SMS
text mode. To confirm, type "AT+CMGF=?" in the HyperTerminal program. If the
response is "+CMGF: (0,1)" (0=PDU mode and 1=text mode), then SMS text mode is
supported. If the response is "+CMGF: (0)", then SMS text mode is not supported.
• Line 5 and 6: The AT command +CMGW is used to write an SMS text message to the
message storage of the GSM / GPRS modem. "+85291234567" is the recipient mobile
phone number. After typing the recipient mobile phone number, you should press the
Enter button of the keyboard. The GSM / GPRS modem will then return a prompt "> "
and you can start typing the SMS text message "A simple demo of SMS text
messaging.". When finished, press Ctrl+z of the keyboard.
• Line 7: "+CMGW: 1" tells us that the index assigned to the SMS text message is 1. It
indicates the location of the SMS text message in the message storage.
• Line 9: The result code "OK" indicates the execution of the AT command +CMGW is
successful.
• Line 10: The AT command +CMSS is used to send the SMS text message from the
message storage of the GSM / GPRS modem. "1" is the index of the SMS text message
obtained from line 7.
• Line 11: "+CMSS: 20" tells us that the reference number assigned to the SMS text
message is 20.
• Line 13: The result code "OK" indicates the execution of the AT command +CMSS is
successful.
To send SMS messages from an application, you have to write the source code for connecting
to and sending AT commands to the mobile phone or GSM/GPRS modem, just like what a
terminal program does. You can write the source code in C, C++, Java, Visual Basic, Delphi or
other programming languages you like. However, writing your own code has a few
disadvantages:
In most cases, instead of writing your own code for interacting with the mobile phone or
GSM/GPRS modem via AT commands, a better solution is to use a high-level SMS messaging
API (Application programming interface) / SDK (Software development kit) / library. The API /
SDK / library encapsulates the low-level details. So, an SMS application developer does not
need to know AT commands and the composition of SMS messages in the bit-level. Some SMS
messaging APIs / SDKs / libraries support SMSC protocols in addition to AT commands. To
move from a wireless-modem-based SMS solution to a SMSC-based SMS solution, usually you
just need to modify a configuration file / property file or make a few changes to your SMS
messaging application's source code.
The links to some open source and free SMS messaging libraries can be found in the article
"Free Libraries/Tools for Sending/Receiving SMS with a Computer".
Another way to hide the low-level AT command layer is to place an SMS gateway between the
SMS messaging application and the mobile phone or GSM/GPRS modem. (This has been
described in the section "What is an SMS Gateway?" earlier.) Simple protocols such as HTTP /
HTTPS can then be used for sending SMS messages in the application. If an SMSC protocol
(e.g. SMPP, CIMD, etc) is used for communicating with the SMS gateway instead of HTTP /
HTTPS, an SMS messaging API / SDK / library can be very helpful to you since it encapsulates
the SMSC protocol's details.
Usually a list of supported / unsupported mobile phones or wireless modems is provided on the
web site of an SMS messaging API / SDK / library or an SMS gateway software package.
Remember to check the list if you are going to use an SMS messaging API / SDK / library or an
SMS gateway software package.
10.1.1. Major Drawback of Sending SMS Messages through a
Mobile Phone or GSM/GPRS Modem -- Low SMS Sending
Rate
Using a mobile phone or GSM/GPRS modem to send SMS messages has a major drawback,
that is the SMS sending rate is too low. Only 6-10 SMS messages can be sent per minute
(when the "SMS over GSM" mode is used). The performance is not affected by the connection
between the computer and the mobile phone or GSM/GPRS modem (i.e. the SMS sending rate
is about the same no matter the mobile phone or GSM/GPRS modem is connected to the
computer through a serial cable, USB cable, Bluetooth link or infrared link) and does not depend
on whether a mobile phone or GSM/GPRS modem is used (i.e. the SMS sending rate is about
the same no matter a mobile phone or a GSM/GPRS modem is used). The determining factor
for the SMS sending rate is the wireless network.
10.2. The 2nd Way: Sending SMS Messages from a Computer through
a Connection to the SMSC or SMS Gateway of a Wireless Carrier
or SMS Service Provider
The way for sending SMS messages from a computer through a mobile phone or GSM/GPRS
modem has a major limitation, that is the SMS sending rate is too low. If you need a high SMS
sending rate, obtaining a direct connection to the SMS center (SMSC) or SMS gateway of a
wireless carrier is necessary. The connection may be made through the Internet, X.25 or dial-
up. If you cannot get a direct connection to the SMSC or SMS gateway of a wireless carrier,
another choice is to get a connection to the SMS gateway of an SMS service provider, which
will forward SMS messages towards a suitable SMSC.
Besides, the information about the service (for example, cost of the service, protocols
supported, network coverage) is usually not stated clearly on a wireless carrier's web site. This
is because the wireless carrier staff wants to know more about your SMS messaging
application, such as its nature and traffic requirement, before offering a price and providing
further information to you. To decide which wireless carrier's service plan is the best, you have
to discuss with the sales staff of each wireless carriers. This is troublesome if you just want to
send a small number of SMS messages. (Of course if you need to send a large amount of SMS
messages, say one million SMS messages per month, negotiating with the wireless carrier staff
for a more favorable agreement is a necessary step.)
A more convenient way to send SMS messages is to use the SMS connectivity service of an
SMS service provider, which is described in the next section.
10.2.2. SMS Service Providers (SMS Gateway Providers, SMS
Resellers, SMS Brokers)
There is a demand for SMS connectivity from applications that does not require the sending or
receiving of large amount of SMS messages. One example is a remote monitoring system. If the
remote monitoring system finds that a certain server is not responding, it will send an SMS alert
to the system administrator's mobile phone. This remote monitoring system will have a very
small amount of SMS traffic per month since the servers being monitored should be working fine
most of the time.
Since a wireless carrier usually does not provide direct SMSC or SMS gateway access to users
without a large amount of SMS traffic, some companies come out to fill the gap. These
companies are called SMS service providers. There is no minimal purchase requirement or
monthly minimum usage requirement for many SMS service providers.
SMS service providers are also known as SMS gateway providers, SMS resellers and SMS
brokers because of the following reasons:
• SMS gateway providers -- An SMS service provider provides an SMS gateway for its
users to send SMS messages to. This SMS gateway will then route the SMS messages
to another SMS gateway or SMSC.
• SMS resellers and SMS brokers -- SMS service providers buy a large amount of SMS
messages from a lot of wireless carriers at a low price per SMS message. They then sell
the SMS messages at a price higher than the cost.
Unlike wireless carriers, many SMS service providers provide detail information about their SMS
connectivity service on their web site. For example, you may find the cost of the service,
network coverage, protocols supported, developers' guide, etc, on the web site. Thus, the
service of different SMS service providers can be compared easily. If you are not happy with,
say the price or network coverage of an SMS service provider, you can simply leave its web site
and find another SMS service provider.
Another advantage of using the SMS connectivity services of SMS service providers is that their
network coverage is very good. They work hard to cover as many wireless networks as possible
so as to make their services attractive. Some SMS service providers can send SMS messages
not only to GSM wireless networks, but also to CDMA and TDMA wireless networks.
It is easy to send SMS messages with an SMS service provider. Here are the typical steps:
1. Register for an account on the SMS service provider's web site. (An SMS service
provider may allow newly registered users to send a few free SMS messages for testing
its service quality.)
2. Log into the account.
3. Buy a number of credits or SMS text messages online. Many SMS service providers
support credit card payment and some also support PayPal.
4. Send SMS messages using a protocol / interface (e.g. HTTP, email, FTP) supported by
the SMS service provider.
SMS service providers can be divided into two categories depending on how they require you to
pay for their SMS messaging service:
• Credit-based -- You purchase a number of credits from the SMS service provider's web
site. Sending one SMS message will cost you one or more credits, depending on the
country you send the SMS message to. For example, sending an SMS text message to
India might cost you one credit while sending an SMS text message to the US might cost
you two credits.
• SMS-based -- You purchase a number of SMS messages from the SMS service
provider's web site. The cost per SMS message is the same for all destinations. For
example, if you purchase ten SMS messages, you can send at most ten SMS messages
no matter the destination is India or the US.
The cost per SMS message sent depends on which SMS service provider you choose and how
many SMS messages you purchase. It starts at around US $0.06 to US $0.07 per SMS
message. The more SMS messages you purchased, the lower the cost of sending one SMS
message.
A comparison of some SMS service providers can be found in "SMS Gateway Providers
Comparison Table". You may also want to have a look at the article "How to Choose an SMS
Gateway Provider" to learn some of the things that you should consider when choosing an SMS
gateway provider for your SMS application.
CMG (CMG and Logica have merged intoLogicaCMG.) EMI (External Machine Interface)
Logica (CMG and Logica have merged SMPP (Short Message Peer to Peer)
intoLogicaCMG.)
SMS2000
SMS gateways of SMS service providers and wireless carriers very often support one or more
of the following protocols / interfaces: HTTP, HTTPS (HTTP + SSL encryption), XML over HTTP
/ HTTPS, SMTP (email to SMS), FTP. Some also support the SMPP protocol, which is usually
used by advanced users. SMSC protocols other than SMPP are not commonly supported.
It is very easy to send SMS messages if you use a simple protocol like HTTP / HTTPS. Here is
an example. To send an SMS message "It is easy to send text messages" to the mobile phone
number 61234567, you submit an HTTP GET to the SMS gateway using an URL that looks
something like this:
http://smsgateway.company123.com/cgi-bin/sendsms?
account=account123&password=password123&destination=61234567&textmessa
ge=It+is+easy+to+send+text+messages
• "smsgateway.company123.com" is the host name of the SMS gateway that the SMS text
message should be sent to.
• "sendsms" is the file name of the CGI program that will be executed on the SMS
gateway.
• "account=account123" is used to assign the value account123 to the account parameter.
Theaccount parameter specifies which account that the cost of the SMS text message
should be deducted from.
• "password=password123" is used to assign the value password123 to
the password parameter. The password parameter specifies the password of the
account.
• "destination=61234567" is used to assign the value 61234567 to
the destination parameter. Thedestination parameter specifies the recipient's mobile
phone number.
• "textmessage=It+is+easy+to+send+text+messages" is used to assign the value It is
easy to send text messages to the textmessage parameter. The textmessage parameter
specifies the SMS text message to be sent. There exists some "+" characters because
the space character is a special character and it should be escaped if it appears in an
URL. The escaped character of the space character is the "+" character.
After receiving your HTTP request, the SMS gateway will forward your SMS text message
towards the recipient. The SMS gateway will then send back an HTTP response that contains a
return value. The return value indicates whether there are any errors. For example, a certain
SMS gateway may use the return value 0 to indicate that there is no error, the return value 1 to
indicate the error "The account does not have enough credits", the return value 2 to indicate the
error "The SMS message is too long", etc.
Note that the parameters that can be passed in an HTTP request and the return values varies
between SMS gateways of different SMS service providers and wireless carriers. To send the
same SMS message "It is easy to send text messages" to the same mobile phone number
61234567 but with a different SMS service provider, the URL to be used may become:
http://api.abccompany.com/cgi-bin/send?
user=account123&passwd=password123&to=61234567&msg=It+is+easy+to+send+
text+messages
Also, note that data transmitted over the Internet using the HTTP protocol is not secure. This
means other people can read your account name and password you included in the above URL.
To send data securely, you should use the HTTPS protocol instead of HTTP (i.e. change "http"
at the beginning of the above URL to "https"), like this:
https://api.abccompany.com/cgi-bin/send?
user=account123&passwd=password123&to=61234567&msg=It+is+easy+to+send+
text+messages
1. Connect a mobile phone or GSM/GPRS modem to a computer / PC. Then use the
computer / PC and AT commands to get the received SMS messages from the mobile
phone or GSM/GPRS modem.
2. Get access to the SMS center (SMSC) or SMS gateway of a wireless carrier. Any SMS
messages received will be forwarded to your computer / PC using a protocol / interface
supported by the SMSC or SMS gateway.
3. Get access to the SMS gateway of an SMS service provider. Any SMS messages
received will be forwarded to your computer / PC using a protocol / interface supported
by the SMS gateway.
If you do not want to develop SMS software or applications but just want to use your computer /
PC to receive text messages, you may want to read our Quick Guide for Non-Developers.
The following table lists the AT commands that are related to the receiving and reading of SMS
messages:
AT command Meaning
Below shows a simple example that demonstrates how to use AT commands and the
HyperTerminal program of Microsoft Windows to read SMS text messages received by a GSM /
GPRS modem or mobile phone. The lines in bold type are the command lines that should be
entered in HyperTerminal. The other lines are responses returned from the GSM / GPRS
modem or mobile phone.
AT
OK
AT+CMGF=1
OK
AT+CMGL="ALL"
+CMGL: 1,"REC READ","+85291234567",,"06/11/11,00:30:29+32"
Hello, welcome to our SMS tutorial.
+CMGL: 2,"REC READ","+85291234567",,"06/11/11,00:32:20+32"
A simple demo of SMS text messaging.
OK
• Line 1: "AT" is sent to the GSM / GPRS modem to test the connection. The GSM /
GPRS modem sends back the result code "OK" (line 2), which means the connection
between the HyperTerminal program and the GSM / GPRS modem works fine.
• Line 3: The AT command +CMGF is used to instruct the GSM / GPRS modem to
operate in SMS text mode. The result code "OK" is returned (line 4), which indicates the
command line "AT+CMGF=1" has been executed successfully. If the result code
"ERROR" is returned, it is likely that the GSM / GPRS modem does not support the SMS
text mode. To confirm, type "AT+CMGF=?" in the HyperTerminal program. If the
response is "+CMGF: (0,1)" (0=PDU mode and 1=text mode), then SMS text mode is
supported. If the response is "+CMGF: (0)", then SMS text mode is not supported.
• Line 5-9: The AT command +CMGL is used to list all SMS text messages in the
message storage of the GSM / GPRS modem. There are two SMS text messages in the
message storage: "Hello, welcome to our SMS tutorial." and "A simple demo of SMS text
messaging.". "+85291234567" is the sender mobile phone number.
"06/11/11,00:30:29+32" and "06/11/11,00:32:20+32" tell us when the SMS text
messages were received by the SMSC. "+32" is the time zone. Note that the unit is a
quarter of an hour. So, +32 means GMT+8 hours, since 32 quarters of an hour = 8
hours. "REC READ" indicates both of the SMS text messages have been read before.
• Line 11: The result code "OK" indicates the execution of the AT command +CMGL is
successful.
To enable an application to receive SMS messages, you have to write the source code for
connecting to and sending AT commands to the mobile phone or GSM/GPRS modem, just like
what a terminal program (such as HyperTerminal of Microsoft Windows) does. You can write the
source code in C, C++, Java, Visual Basic, Delphi or other programming languages you like.
However, like what we have discussed in the earlier section "The 1st Way: Sending SMS
Messages from a Computer Using a Mobile Phone or GSM/GPRS Modem", usually a better
solution is to use a high-level SMS messaging API (Application programming interface) / SDK
(Software development kit) / library instead of writing your own code for interacting with the
mobile phone or GSM/GPRS modem via AT commands. The API / SDK / library encapsulates
the low-level details. So, an SMS application developer does not need to know AT commands
and the composition of SMS messages in the bit-level. Some SMS messaging APIs / SDKs /
libraries support SMSC protocols in addition to AT commands. To move from a wireless-
modem-based SMS solution to a SMSC-based SMS solution, usually you just need to modify a
configuration file / property file or make a few changes to your SMS messaging application's
source code. The links to some open source and free SMS messaging libraries can be found in
the article "Free Libraries/Tools for Sending/Receiving SMS with a Computer".
Another high-level solution is to place an SMS gateway between the SMS messaging
application and the mobile phone or GSM/GPRS modem. The SMS messaging application can
then use simple protocols such as HTTP / HTTPS for receiving SMS messages. If an SMSC
protocol (e.g. SMPP, CIMD, etc) is used for communicating with the SMS gateway instead of
HTTP / HTTPS, an SMS messaging API / SDK / library can be very helpful to you since it
encapsulates the SMSC protocol's details.
To receive SMS messages through a direct connection to the SMSC or SMS gateway of a
wireless carrier, usually you need to contact the wireless carrier staff to discuss the details. A
wireless carrier may only provide such service to those who have huge SMS traffic and the total
fee can be very high. (However, if you divide the total fee by the number of SMS messages that
is allowed to receive through the SMSC or SMS gateway, you may find that the fee per
incoming SMS message is very low.) The service may involve a one-time setup fee, a monthly
subscription fee and/or a per-message fee. To know the exact cost of the service, protocols
supported, network coverage and other information, usually you have to contact the wireless
carrier staff.
1. SIM hosting -- The SMS service provider hosts a SIM card for you. All SMS messages
sent to the mobile phone number of the SIM card will be forwarded to your system using
a protocol / interface supported by the SMS gateway of the SMS service provider.
2. Shared phone number -- The SMS service provider provides you a phone number that
is shared by its customers for receiving SMS messages. You have to specify one or
more keywords to associate with your SMS application. If an SMS message is received
and its content begins with a keyword specified by you, it will be forwarded to your
system using a protocol / interface supported by the SMS gateway of the SMS service
provider.
Some SMS service providers also provide SMS messaging solutions that are customized to
your needs. For example, if you need to receive SMS messages from users in a few countries,
an SMS service provider may help you open dedicated phone numbers in those countries and
forward the received SMS messages to you in a unified way. To use such SMS messaging
services, you have to contact the SMS service provider to discuss the details.
Like receiving SMS messages using your own mobile phone or GSM/GPRS modem, SIM
hosting has a major weakness -- it cannot handle a large amount of SMS traffic. The advantage
of SIM hosting is that you do not need to buy, set up and manage the necessary equipment.
Also, you do not need to write any code to control the receiving of SMS messages from a
GSM/GPRS modem via low-level AT commands, which means you can concentrate on the
business logic of your SMS application. The SMS service provider may provide you a detail log
of the incoming SMS messages.
11.3.1.1. Cost of SIM Hosting Service
SIM hosting service typically involves a one-time setup fee and a monthly hosting fee. Usually
there is no per-message cost. Some SMS service providers do not state the cost of SIM hosting
service on their website, which means you have to contact their staff directly.
If the SMS service provider is located overseas, the SIM card needs to support foreign network
roaming. SMS roaming fees may be charged by the wireless carrier that provides you the SIM
card.
Like using SIM hosting service, using shared phone number service has the advantage that you
do not need to buy, set up and manage any equipment (e.g. GSM / GPRS modems) and write
any low-level code for receiving SMS messages. Hence, an SMS application developer can
concentrate on the business logic of his/her SMS messaging application.
The weakness of shared phone number service is that the bandwidth is shared, i.e. the
performance drops if the number of users sharing the phone number increases, or if the amount
of incoming SMS traffic required by other users increases.
Here is an example for illustration. Suppose you want to develop an SMS messaging application
that provides free ringtone download service. A user will be able to perform two functions: listing
the free ringtones that are available and requesting a ringtone to be sent to a mobile phone.
To receive SMS messages from users, you can subscribe to the shared phone number service
of an SMS service provider and register two keywords, list and download, to be associated with
your SMS messaging application.
To request the list of free ringtones that are available on your server, the user can send the
following SMS text message to the shared phone number:
list
When the SMS gateway of the SMS service provider receives the above SMS text message, it
parses its content and extracts the keyword list. It then searches a database to find out which
SMS messaging application is associated with the keyword list. As your SMS messaging
application is associated with the keyword list, the SMS text message will be forwarded to your
SMS messaging application.
The keyword list indicates that the user wants the list of free ringtones that are available on your
server. Hence, your SMS messaging application should return an SMS text message that
contains something like this:
To download the second ringtone, the user can send an SMS text message that looks like this
to the shared phone number:
download 2
Since the keyword download is also associated with your SMS messaging application, the SMS
gateway will forward the above SMS text message to your SMS messaging application. This
time the keyword download indicates that the user wants to download a ringtone. Your SMS
messaging application should encode the second ringtone in an SMS message and send it to
the user.
11.3.2.2. Cost of Shared Phone Number Service
Shared phone number service typically involves a monthly subscription fee, a per-message fee
and/or a per-keyword fee. A few SMS service providers also charge a one-time setup fee. Some
SMS service providers do not state the cost of shared phone number service on their web site,
which means you have to contact their staff directly.
CMG (CMG and Logica have merged intoLogicaCMG.) EMI (External Machine Interface)
Logica (CMG and Logica have merged SMPP (Short Message Peer to Peer)
intoLogicaCMG.)
SMS2000
SMS gateways of SMS service providers and wireless carriers very often support one or more
of the following protocols / interfaces: HTTP, HTTPS (HTTP + SSL encryption), XML over HTTP
/ HTTPS, SMTP (SMS to email), FTP. Some also support the SMPP protocol, which is usually
used by advanced users. SMSC protocols other than SMPP are not commonly supported.
It is very easy to receive SMS messages from an SMS gateway if you use a simple protocol like
HTTP / HTTPS. Let's take HTTP as an example. First, you log into your account and register a
callback URL that points to a server-side script written by you. The server-side script is hosted
on a web server / application server and it will be responsible for processing the received SMS
messages. Commonly used server-side technologies include ASP, Java Servlet / JSP, Perl and
PHP. If your server-side script is written in PHP, the callback URL should look something like
this:
http://yourserver.com/receiveSMS.php
Whenever an SMS message is received, the SMS gateway will submit an HTTP GET to your
web server / application server using the above callback URL. Details of the inbound SMS
message such as its content, the sender's mobile phone number, the time and date that the
SMS message is received, etc, will be appended to the callback URL. For example, suppose
someone with the mobile phone number 61234567 sends an SMS text message "It is easy to
receive text messages" to your SMS application's phone number. When the SMS gateway
receives the SMS text message, it submits an HTTP GET to your web server / application
server using an URL that looks like this:
http://yourserver.com/receiveSMS.php?
sender=61234567&textmessage=It+is+easy+to+receive+text+messages&date_t
ime=20060101+1830
• "yourserver.com" is the host name of your web server / application server that is
responsible for processing the inbound SMS text message.
• "receiveSMS.php" is the file that contains the PHP script for processing the inbound
SMS text message.
• "sender=61234567" assigns the value 61234567 to the sender parameter.
The sender parameter specifies the originating mobile phone number.
• "textmessage=It+is+easy+to+receive+text+messages" assigns the value It is easy to
receive text messages to the textmessage parameter. The textmessage parameter
specifies the content of the inbound SMS text message. The "+" character is the
escaped character of the space character. The space character is a special character
and it cannot appear in an URL without escaping.
• "date_time=20060101+1830" assigns the value 20060101 1830 to
the date_time parameter. Thedate_time parameter specifies the date and time that the
SMS text message was received. In this example, 20060101 1830 means the SMS text
message was received on 1 January 2006 at 6:30 pm. The date and time format may be
different if you use the SMS gateway of a different SMS service provider or wireless
carrier.
After processing the inbound SMS text message, you may want to send a reply SMS text
message to the originator. Usually this can be done simply by including the reply SMS text
message in the HTTP response you send back to the SMS gateway. The SMS gateway will
then forward the included text message towards the mobile phone number 61234567. The cost
for sending the SMS text message will be deducted from your account.
Note that the parameters that are included in the callback URL varies between SMS gateways
of different SMS service providers or wireless carriers. For example, if a different SMS gateway
is used, the previous SMS message "It is easy to receive text messages" may be forwarded to
your web server / application server using a different URL, like below:
http://yourserver.com/receiveSMS.php?
from=61234567&msg=It+is+easy+to+receive+text+messages×tamp=1830+0
1012006
Also, note that data transmitted over the Internet using the HTTP protocol is not secure. This
means other people can read the data included in the above URL. Some SMS gateways allow
the use of the HTTPS protocol instead of HTTP in a callback URL (i.e. change "http" at the
beginning of the above URL to "https") so that inbound SMS messages can be submitted to
your web server / application server securely. (HTTPS must be enabled on your web server /
application server.)
https://yourserver.com/receiveSMS.php?
from=61234567&msg=It+is+easy+to+receive+text+messages×tamp=1830+0
1012006
A GSM modem can be an external device or a PC Card / PCMCIA Card. Typically, an external
GSM modem is connected to a computer through a serial cable or a USB cable. A GSM modem
in the form of a PC Card / PCMCIA Card is designed for use with a laptop computer. It should
be inserted into one of the PC Card / PCMCIA Card slots of a laptop computer.
Like a GSM mobile phone, a GSM modem requires a SIM card from a wireless carrier in order
to operate.
As mentioned in earlier sections of this SMS tutorial, computers use AT commands to control
modems. Both GSM modems and dial-up modems support a common set of standard AT
commands. You can use a GSM modem just like a dial-up modem.
The number of SMS messages that can be processed by a GSM modem per minute is very low
-- only about six to ten SMS messages per minute.
GPRS can be used as the bearer of SMS. If SMS over GPRS is used, an SMS transmission
speed of about 30 SMS messages per minute may be achieved. This is much faster than using
the ordinary SMS over GSM, whose SMS transmission speed is about 6 to 10 SMS messages
per minute. A GPRS modem is needed to send and receive SMS over GPRS. Note that some
wireless carriers do not support the sending and receiving of SMS over GPRS.
If you need to send or receive MMS messages, a GPRS modem is typically needed.
• Some mobile phone models (example: Ericsson R380) cannot be used with a computer
to receive concatenated SMS messages.
Besides the above issues, mobile phones and GSM/GPRS modems are more or less the same
for sending and receiving SMS messages from a computer. Actually, you can consider an AT-
command-enabled mobile phone as "GSM/GPRS modem + keypad + display + ...".
There is not much difference between mobile phones and GSM/GPRS modems in terms of
SMS transmission rate, since the determining factor for the SMS transmission rate is the
wireless network.
Before you start programming your SMS application, you may want to check if your mobile
phone, GSM/GPRS modem and SIM card are working properly first. The MS HyperTerminal is a
handy tool when it comes to testing your GSM devices. It is a good idea to test your GSM
devices beforehand. When a problem occurs, sometimes it is difficult to tell what causes the
problem. The cause can be your program, the GSM device or the SIM card. If you test your
GSM device and SIM card with MS HyperTerminal and they operate properly, then it is very
likely that the problem is caused by your program.
1. Put a valid SIM card into the mobile phone or GSM/GPRS modem. You can obtain a
SIM card by subscribing to the GSM service of a wireless network operator.
2. Connect your mobile phone or GSM/GPRS modem to a computer and set up the
corresponding wireless modem driver. You should find the wireless modem driver in the
CD or disk that was provided by the manufacturer. If the manufacturer does not provide
such CD or disk with your mobile phone or GSM/GPRS modem, you can go to the
manufacturer's web site and see whether the wireless modem driver can be downloaded
there. If the wireless modem driver cannot be found on the web site, you can still use
Windows' standard modem driver.
3. Run MS HyperTerminal by selecting Start -> Programs -> Accessories -
> Communications ->HyperTerminal.
4. In the Connection Description dialog box, enter a name and choose an icon you like for
the connection. Then click the OK button.
Figure 5. The screenshot of MS HyperTerminal's Connection Description dialog box in Windows 98.
5. In the Connect To dialog box, choose the COM port that your mobile phone or
GSM/GPRS modem is connecting to in the Connect using combo box. For example,
choose COM1 if your mobile phone or GSM/GPRS modem is connecting to the COM1
port. Then click the OK button.
(Sometimes there will have more than one COM port in the Connect using combo box.
To know which COM port is used by your mobile phone or GSM/GPRS modem, follow
the procedure below:
In Windows 98:
Go to Control Panel -> Modem. Then click the Diagnostics tab. In the list box, you can
see which COM port the mobile phone or GSM/GPRS modem is connected to.
6. The Properties dialog box comes out. Enter the correct port settings for your mobile
phone or GSM/GPRS modem. Then click the OK button.
(To find the correct port settings that should be used with your mobile phone or
GSM/GPRS modem, one way is to consult the manual of your mobile phone or
GSM/GPRS modem. Another way is to check the port settings used by the wireless
modem driver that you installed earlier.
To check the port settings used by the wireless modem driver on Windows 98, follow
these steps:
a. Go to Control Panel -> Modem.
b. Select your mobile phone or GSM/GPRS modem in the list box.
c. Click the Properties button.
d. The Properties dialog box appears. The Maximum speeds field on the General tab
corresponds to HyperTerminal's Bits per second field. Click the Connection tab and you
can find the settings for data bits, parity and stop bits. Click the Advanced button and
you can find the setting for flow control.
To check the port settings used by the wireless modem driver on Windows 2000 and
Windows XP, follow these steps:
a. Go to Control Panel -> Phone and Modem Options -> Modems tab.
b. Select your mobile phone or GSM/GPRS modem in the list box.
c. Click the Properties button.
d. The Properties dialog box appears. Click the Advanced tab and then click the Change
Default Preferences button.
e. The Change Default Preferences dialog box appears. The Port speed field on
the General tab corresponds to HyperTerminal's Bits per second field. You can also find
the setting for flow control on the General tab. On the Advanced tab, you can find the
settings for data bits, parity and stop bits.)
7. Type "AT" in the main window. A response "OK" should be returned from the mobile
phone or GSM/GPRS modem.
Type "AT+CPIN?" in the main window. The AT command "AT+CPIN?" is used to query
whether the mobile phone or GSM/GPRS modem is waiting for a PIN (personal
identification number, i.e. password). If the response is "+CPIN: READY", it means the
SIM card does not require a PIN and it is ready for use. If your SIM card requires a PIN,
you need to set the PIN with the AT command "AT+CPIN=<PIN>".
Figure 8. The screenshot of MS HyperTerminal's main window in Windows 98.
If you get the responses above, your mobile phone or GSM/GPRS modem is working properly.
You can start typing your own AT commands to control the mobile phone or GSM/GPRS
modem.
Further details about how to use AT commands to send and receive SMS messages will be
provided in the following sections.
Note that the starting "AT" is the prefix that informs the modem about the start of a command
line. It is not part of the AT command name. For example, D is the actual AT command name in
ATD and +CMGS is the actual AT command name in AT+CMGS. However, some books and
web sites use them interchangeably as the name of an AT command.
Here are some of the tasks that can be done using AT commands with a GSM/GPRS modem or
mobile phone:
• Get basic information about the mobile phone or GSM/GPRS modem. For example,
name of manufacturer (AT+CGMI), model number (AT+CGMM), IMEI number
(International Mobile Equipment Identity) (AT+CGSN) and software version
(AT+CGMR).
• Get basic information about the subscriber. For example, MSISDN (AT+CNUM) and
IMSI number (International Mobile Subscriber Identity) (AT+CIMI).
• Get the current status of the mobile phone or GSM/GPRS modem. For example, mobile
phone activity status (AT+CPAS), mobile network registration status (AT+CREG), radio
signal strength (AT+CSQ), battery charge level and battery charging status (AT+CBC).
• Establish a data connection or voice connection to a remote modem (ATD, ATA, etc).
• Send and receive fax (ATD, ATA, AT+F*).
• Send (AT+CMGS, AT+CMSS), read (AT+CMGR, AT+CMGL), write (AT+CMGW) or
delete (AT+CMGD) SMS messages and obtain notifications of newly received SMS
messages (AT+CNMI).
• Read (AT+CPBR), write (AT+CPBW) or search (AT+CPBF) phonebook entries.
• Perform security-related tasks, such as opening or closing facility locks (AT+CLCK),
checking whether a facility is locked (AT+CLCK) and changing passwords (AT+CPWD).
(Facility lock examples: SIM lock [a password must be given to the SIM card every time
the mobile phone is switched on] and PH-SIM lock [a certain SIM card is associated with
the mobile phone. To use other SIM cards with the mobile phone, a password must be
entered.])
• Control the presentation of result codes / error messages of AT commands. For
example, you can control whether to enable certain error messages (AT+CMEE) and
whether error messages should be displayed in numeric format or verbose format
(AT+CMEE=1 or AT+CMEE=2).
• Get or change the configurations of the mobile phone or GSM/GPRS modem. For
example, change the GSM network (AT+COPS), bearer service type (AT+CBST), radio
link protocol parameters (AT+CRLP), SMS center address (AT+CSCA) and storage of
SMS messages (AT+CPMS).
• Save and restore configurations of the mobile phone or GSM/GPRS modem. For
example, save (AT+CSAS) and restore (AT+CRES) settings related to SMS messaging
such as the SMS center address.
Note that mobile phone manufacturers usually do not implement all AT commands, command
parameters and parameter values in their mobile phones. Also, the behavior of the implemented
AT commands may be different from that defined in the standard. In general, GSM/GPRS
modems designed for wireless applications have better support of AT commands than ordinary
mobile phones.
In addition, some AT commands require the support of mobile network operators. For example,
SMS over GPRS can be enabled on some GPRS mobile phones and GPRS modems with the
+CGSMS command (command name in text: Select Service for MO SMS Messages). But if the
mobile network operator does not support the transmission of SMS over GPRS, you cannot use
this feature.
Basic commands are AT commands that do not start with "+". For example, D (Dial), A
(Answer), H (Hook control) and O (Return to online data state) are basic commands.
Extended commands are AT commands that start with "+". All GSM AT commands are
extended commands. For example, +CMGS (Send SMS message), +CMSS (Send SMS
message from storage), +CMGL (List SMS messages) and +CMGR (Read SMS messages) are
extended commands.
Syntax rule 1. All command lines must start with "AT" and end with a carriage return character.
(We will use <CR> to represent a carriage return character in this SMS tutorial.) In a terminal
program like HyperTerminal of Microsoft Windows, you can press the Enter key on the keyboard
to output a carriage return character.
Example: To list all unread inbound SMS messages stored in the message storage area, type
"AT", then the extended AT command "+CMGL", and finally a carriage return character, like this:
AT+CMGL<CR>
Syntax rule 2. A command line can contain more than one AT command. Only the first AT
command should be prefixed with "AT". AT commands in the same command-line string should
be separated with semicolons.
Example: To list all unread inbound SMS messages stored in the message storage area and
obtain the manufacturer name of the mobile device, type "AT", then the extended AT command
"+CMGL", followed by a semicolon and the next extended AT command "+CGMI":
AT+CMGL;+CGMI<CR>
An error will occur if both AT commands are prefixed with "AT", like this:
AT+CMGL;AT+CGMI<CR>
Syntax rule 3. A string is enclosed between double quotes.
Example: To read all SMS messages from message storage in SMS text mode (at this time you
do not need to know what SMS text mode is. More information will be provided later in this SMS
tutorial), you need to assign the string "ALL" to the extended AT command +CMGL, like this:
AT+CMGL="ALL"<CR>
Syntax rule 4. Information responses and result codes (including both final result codes and
unsolicited result codes) always start and end with a carriage return character and a linefeed
character.
Example: After sending the command line "AT+CGMI<CR>" to the mobile device, the mobile
device should return a response similar to this:
<CR><LF>Nokia<CR><LF>
<CR><LF>OK<CR><LF>
The first line is the information response of the AT command +CGMI and the second line is the
final result code. <CR> and <LF> represent a carriage return character and a linefeed character
respectively. The final result code "OK" marks the end of the response. It indicates no more
data will be sent from the mobile device to the computer / PC.
When a terminal program such as HyperTerminal of Microsoft Windows sees a carriage return
character, it moves the cursor to the beginning of the current line. When it sees a linefeed
character, it moves the cursor to the same position on the next line. Hence, the command line
"AT+CGMI<CR>" that you entered and the corresponding response will be displayed like this in
a terminal program such as HyperTerminal of Microsoft Windows:
AT+CGMI
Nokia
OK
AT+CMGL<CR>
at+cmgl<CR>
AT+CMGL;+CGMI<CR>
<CR><LF>+CMGL: 1,"REC
UNREAD","+85291234567",,"06/11/11,00:30:29+32"<CR><LF>
Welcome to our SMS tutorial.<CR><LF>
<CR><LF>Nokia<CR><LF>
<CR><LF>OK<CR><LF>
AT+CMGL;+CGMI
+CMGL: 1,"REC UNREAD","+85291234567",,"06/11/11,00:30:29+32"
Welcome to our SMS tutorial.
Nokia
OK
Like the OK final result code, the ERROR final result code always starts and ends with a
carriage return character and a linefeed character.
Here is an example for illustration. Suppose you want to instruct your GSM/GPRS modem to list
SMS messages from the message storage area and get the manufacturer name of the
GSM/GPRS modem. You intend to type the command line "AT+CMGL;+CGMI<CR>" but make
a careless mistake by typing "+CMFL" instead of "+CMGL". The GSM/GPRS modem will return
the ERROR final result code, as shown below:
AT+CMFL;+CGMI<CR>
<CR><LF>ERROR<CR><LF>
As an error occurs when the GSM/GPRS modem processes "+CMFL", the GSM/GPRS modem
stops the execution of the command line and so the second AT command "+CGMI" is not
processed.
If you type the second AT command "+CGMI" incorrectly instead of the first AT command
"+CMGL", the GSM/GPRS modem will output the result of the execution of the AT command
"+CMGL" before outputting the ERROR final result code, like this:
AT+CMGL;+CGMU<CR>
<CR><LF>+CMGL: 1,"REC
UNREAD","+85291234567",,"06/11/11,00:30:29+32"<CR><LF>
Welcome to our SMS tutorial.<CR><LF>
<CR><LF>ERROR<CR><LF>
AT+CMGL;+CGMU
+CMGL: 1,"REC UNREAD","+85291234567",,"06/11/11,00:30:29+32"
Welcome to our SMS tutorial.
ERROR
Just as the final result codes OK and ERROR, the +CMS ERROR final result code always starts
and ends with a carriage return character and a linefeed character. error_code is an integer that
is associated to a certain error. A list of some error codes and their meanings can be found in
"Table of +CMS Error Codes and Their Meanings".
As mentioned earlier, after the execution of a command line, only one final result code is
returned. Hence, when an error occurs, you will not find both +CMS ERROR and ERROR in the
command response. For errors related to SMS messaging, the +CMS ERROR final result code
is returned. For other errors such as invalid command syntax and unsupported AT command,
the ERROR final result code is returned as usual.
AT+CMGR=11<CR>
<CR><LF>+CMS ERROR: 321<CR><LF>
AT+CMGR=11
+CMS ERROR: 321
To find out the meaning of the +CMS error code 321, go to "Table of +CMS Error Codes and
Their Meanings". From there, we know that the read message operation failed because an
invalid memory index was assigned to the AT command +CMGR.
Note that after the occurrence of a +CMS error, the GSM/GPRS modem or mobile phone will
not process the remaining AT commands in the command line. Thus, if the command line sent
to Nokia 6021 is "AT+CMGR=11;+CGMI" (+CGMI is the AT command for retrieving the
manufacturer name of the GSM/GPRS modem or mobile phone), you will get the following
result in Windows' HyperTerminal:
AT+CMGR=11;+CGMI
+CMS ERROR: 321
But if the positions of the two AT commands in the command line are exchanged, Nokia 6021
will output the result of the execution of the AT command +CGMI before outputting the +CMS
ERROR result code. Below is the result displayed in Windows' HyperTerminal:
AT+CGMI;+CMGR=11
Nokia
Here are the unsolicited result codes that are related to SMS messaging:
+CDS
A GSM/GPRS modem or mobile phone uses +CDS to forward a newly received SMS status
report to the computer / PC.
+CDSI
A GSM/GPRS modem or mobile phone uses +CDSI to notify the computer / PC that a new SMS
status report has been received and the memory location where it is stored.
+CMT
A GSM/GPRS modem or mobile phone uses +CMT to forward a newly received SMS message
to the computer / PC.
+CMTI
A GSM/GPRS modem or mobile phone uses +CMTI to notify the computer / PC that a new
SMS message has been received and the memory location where it is stored.
17. AT Command Operations: Test, Set, Read
and Execution
There are four types of AT command operations:
The command syntax for performing an operation will be described in detail in the following
sections.
command=?
Here is an example. The AT command +CGMI (command name in text: Request Manufacturer
Identification) is used to get the manufacturer name of the GSM/GPRS modem or mobile
phone. To test whether +CGMI is supported, you can make use of the test command
"+CGMI=?". The complete command line that should be entered is:
AT+CGMI=?
If the GSM/GPRS modem or mobile phone supports the AT command +CGMI, the result code
"OK" will be returned, like this:
AT+CGMI=?
OK
If the GSM/GPRS modem or mobile phone does not support the AT command +CGMI, the
result code "ERROR" will be returned, like this:
AT+CGMI=?
ERROR
In the above example, the AT command +CGMI does not have any parameters. If the AT
command to be tested has parameter(s), the parameter value(s) supported by the GSM/GPRS
modem or mobile phone may be printed additionally. Below is an example that illustrates the
format of the response. +COMMAND1 is a fictitious AT command that has four parameters.
AT+COMMAND1=?
+COMMAND1: (0,1),(0-10),(0,1,5-10),("GSM","UCS2")
OK
The supported values of each of the four parameters are enclosed in parentheses. Commas are
used to delimit the parentheses and the values inside parentheses. A hyphen is used to indicate
a range of values. The values inside parentheses can be of the string type.
In the above example, the response of the test command "+COMMAND1=?" provides us the
following information:
To a few AT commands, the test operation does not return the parameter values supported.
Instead, it returns the values that are allowed to appear in the information response of the AT
command. An example is the +CBC AT command (command name in text: Battery Charge).
The +CBC command is used to retrieve the connection status and charge level of the battery of
the mobile device. Two values are returned in the information response of the +CBC AT
command. The format is:
+CBC: connection_status,charge_level
For example, if the battery is placed in the mobile device with no charger connected and the
charge level is 80%, the result of the execution of the +CBC AT command will be:
AT+CBC
+CBC: 0,80
OK
If you run the test command "+CBC=?", all the supported values that are allowed to appear in
the connection status field and charge level field will be provided. With my Nokia 6021, the
result is:
AT+CBC=?
+CBC: (0,1),(0-100)
OK
"(0,1)" means the connection status field in the information response of the +CBC AT command
can contain either 0 or 1, while "(0-100)" means the charge level field can contain any integer
between 0 and 100.
17.2. Set Command -- Changes the Settings Used for Certain Tasks
A set operation changes the settings used by the GSM/GPRS modem or mobile phone for
certain tasks. The syntax is:
command=value1,value2,...valueN
where command is an AT command and value1 to valueN are the values you want to set. When
an AT command is used in the above syntax to perform a set operation, it is called a set
command.
Here is an example. The AT command +CSCA (command name in text: Service Centre
Address) is used to set the SMSC (SMS center) address for sending SMS messages. It takes
two parameters that specify the SMSC address and type of address. To set the SMSC address
to +85291234567, enter the following command line in a terminal program such as MS
Windows' HyperTerminal:
AT+CSCA="+85291234567",145
If the set command runs successfully, the result code "OK" will be returned:
AT+CSCA="+85291234567",145
OK
Some AT commands have optional parameters. You can choose not to assign values to them.
For example, the second parameter of the +CSCA AT command is optional. If no value is
assigned to the second parameter, the GSM/GPRS modem or mobile phone will use the default
parameter value, which is 145 if the SMSC address starts with "+" (the plus character). Hence,
this command line:
AT+CSCA="+85291234567"
is equivalent to:
AT+CSCA="+85291234567",145
Typically the values you specified with set commands are placed in volatile memory. If the
GSM/GPRS modem or mobile phone is switched off or rebooted, the values you specified with
set commands will be gone. When the GSM/GPRS modem or mobile phone is powered on
again, all settings are back to the defaults.
For some commonly used settings, there are AT commands for saving/restoring the settings
to/from non-volatile memory. For example, the AT commands +CSAS (command name in text:
Save Settings) and +CRES (command name in text: Restore Settings) can be used to save and
restore settings related to SMS messaging such as the SMS center address.
command?
where command is an AT command. When an AT command is used in the above syntax to
perform a read operation, it is called a read command. The read operation is supported by all
AT commands that are capable of the set operation.
AT+CSCA="+85291234567",145
OK
After that, if you enter the read command "+CSCA?", the GSM/GPRS modem or mobile phone
will return the SMSC address and type of address that you set in the previous step:
AT+CSCA?
+CSCA: "+85291234567",145
OK
command=value1,value2,...valueN
where command is an AT command and value1 to valueN are the values to assign to the AT
command. If the AT command does not have any parameters, the part
"=value1,value2,...valueN" should be omitted. When an AT command is used in the above
syntax to perform an execution operation, it is called an execution command.
Here is an example illustrating the use of an execution command. The AT command +CMSS
(command name in text: Send Message from Storage) can be used to perform an execution
operation to send an SMS message stored in message storage. It has three parameters. They
specify the index of the memory location that stores the SMS message, the destination phone
number and the type of the phone number respectively. To send the SMS message at index 1
to the phone number +85291234567, the following command line can be used:
AT+CMSS=1,"+85291234567",145
Some AT commands have optional parameters. You can choose not to assign values to them.
For example, the third parameter of the +CMSS AT command is optional. If no value is
assigned to the third parameter, the GSM/GPRS modem or mobile phone will use the default
parameter value, which is 145 if the destination phone number starts with "+" (the plus
character). Hence, this command line:
AT+CMSS=1,"+85291234567"
is equivalent to:
AT+CMSS=1,"+85291234567",145
Unlike set commands, execution commands do not store the parameter values assigned to
them. So, no read command is available for retrieving the last parameter values assigned to an
execution command. For example, if you send the command line "AT+CMSS?" to your
GSM/GPRS modem or mobile phone, the ERROR result code will be returned:
AT+CMSS?
ERROR
AT
OK
To find out whether a GSM/GPRS modem or mobile phone supports the sending of SMS
messages through AT commands, you have to:
1. Use the AT command +CSMS (command name in text: Select Message Service) to
check whether mobile-originated SMS messages are supported.
2. Perform test operations to check whether +CMGS (command name in text: Send
Message) and/or +CMSS (command name in text: Send Message from Storage) are
supported.
(You may want to check the AT commands +CMGW [command name in text: Write
Message to Memory] and +CMGD [command name in text: Delete Message] in addition
as they are sometimes used together with +CMSS.)
Receiving SMS Messages and Reading SMS Messages from Message Storage
To find out whether a GSM/GPRS modem or mobile phone supports the receiving and reading
of SMS messages through AT commands, you have to:
1. Use the AT command +CSMS (command name in text: Select Message Service) to
check whether mobile-terminated SMS messages are supported.
2. Perform test operations to check whether +CNMI (command name in text: New Message
Indications to TE), +CMGL (command name in text: List Messages) and/or +CMGR
(command name in text: Read Message) are supported.
If the GSM/GPRS modem or mobile phone supports the +CNMI AT command, it can send a
notification or directly forward the message to the PC whenever a new SMS message arrives.
If the GSM/GPRS modem or mobile phone does not support +CNMI but supports +CMGL
and/or +CMGR, the PC has to poll the GSM/GPRS modem or mobile phone repeatedly in order
to know if any new SMS messages have arrived.
Mobile-originated SMS messages refer to SMS messages that are sent from a mobile device to
an SMSC, i.e. outbound SMS messages.
Mobile-terminated SMS messages refer to SMS messages that are sent from an SMSC to a
mobile device, i.e. inbound SMS messages.
Cell broadcast messages are text messages pushed to subscribers located in a certain mobile
network area by the network operator. These text messages may contain news, weather
information, etc.
Here is an example that demonstrates how to use the +CSMS AT command to check if mobile-
originated and mobile-terminated SMS messages are supported. First, send the read command
"+CSMS?" to the GSM/GPRS modem or mobile phone. The response returned from our Nokia
6021 to HyperTerminal is shown below:
AT+CSMS?
+CSMS: 0,1,1,1
OK
As you can see, the information response contains four values. The second, third and fourth
values indicate whether Nokia 6021 supports mobile-terminated SMS messages, mobile-
originated SMS messages and cell broadcast messages respectively. If the value is 1, it means
the message type is supported. If the value is 0, it means the message type is not supported.
• The third value in the information response is 1, which indicates Nokia 6021 supports
mobile-originated SMS messages. So, Nokia 6021 is capable of sending SMS
messages to an SMSC.
• The second value in the information response is 1, which indicates Nokia 6021 supports
mobile-terminated SMS messages. So, Nokia 6021 is capable of receiving SMS
messages from an SMSC.
If the final result code "ERROR" is returned (as shown below), it is likely that the +CSMS AT
command is not supported by the mobile device.
AT+CSMS?
ERROR
To confirm, send the test command "+CSMS=?" to the GSM/GPRS modem or mobile phone. If
the final result code "ERROR" is returned (as shown below), it means the mobile device does
not support the +CSMS AT command.
AT+CSMS=?
ERROR
Note that +CSMS is a mandatory command in the AT command set for SMS messaging. If it is
not supported, normally the whole AT command set for SMS messaging is not supported.
Before we begin the check, let's go through an overview of the AT commands that are required
for sending, receiving and reading SMS messages. You will learn which AT commands should
be checked and get a general idea about when these AT commands should be used.
To send SMS messages via AT commands, the GSM/GPRS modem or mobile phone has to
support either +CMGS (command name in text: Send Message) or +CMSS (command name in
text: Send Message from Storage). You may also find +CMGW (command name in text: Write
Message to Memory) and +CMGD (command name in text: Delete Message) useful, since they
are sometimes used together with +CMSS. +CMSS is used to send an SMS message located in
the message storage area. If an SMS message does not exist in the message storage area, you
must first use the AT command +CMGW to write the SMS message to the message storage
area before you can use the AT command +CMSS to send the SMS message to the SMSC.
After message submission, you may use the AT command +CMGD to delete the SMS message
to free some space from the message storage area.
To receive and read SMS messages via AT commands, the GSM/GPRS modem or mobile
phone has to support the AT command +CNMI (command name in text: New Message
Indications to TE. TE stands for Terminal Equipment, which is the equipment that controls the
GSM/GPRS modem or mobile phone. For example, a PC / computer), +CMGL (command name
in text: List Messages), or +CMGR (command name in text: Read Messages).
The AT command +CNMI is used to specify how newly arrived SMS messages should be
handled. You can tell the GSM/GPRS modem or mobile phone either to forward newly arrived
SMS messages directly to the PC, or to save them in message storage and then notify the PC
about their locations in message storage.
The AT command +CMGL is used to read all SMS messages that have a certain status (e.g.
"received unread", "received read", etc) from the message storage area, while the AT command
+CMGR is used to read the SMS message saved at a certain location of the message storage
area.
AT+CMGS=?
OK
The final result code "OK" indicates the AT command +CMGS is supported. If the GSM/GPRS
modem or mobile phone returns the final result code "ERROR", it means the command is not
supported.
A quicker way is to copy and paste the following command line to the terminal program and
execute it:
AT+CMGS=?;+CMSS=?;+CNMI=?;+CMGL=?;+CMGR=?
As an example, here shows the response returned from my Nokia 6021 to HyperTerminal after
the execution of above command line:
AT+CMGS=?;+CMSS=?;+CNMI=?;+CMGL=?;+CMGR=?
+CNMI: (0-2),(0-3),(0,2,3),(0-2),(0,1)
+CMGL: (0-4)
OK
The return of the final result code "OK" indicates all AT commands under test are supported. If
the final result code "ERROR" is returned, it means one or more AT commands are not
supported.
The syntax of the unsolicited result codes below also depends on the mode in which the
GSM/GPRS modem or mobile phone is operating:
These two AT commands are useful to you only if SMS text mode is used:
• +CSMP (Set Text Mode Parameters)
• +CSDH (Show Text Mode Parameters)
When the GSM/GPRS modem or mobile phone is operating in different modes, the syntax of
certain SMS AT commands and the responses returned after command execution is different.
Here's an example for illustration. Let's say you would like to send the SMS message "It is easy
to send text messages." to the mobile phone number +85291234567. In SMS text mode, this is
the command line that you should enter:
However, if the GSM/GPRS modem or mobile phone is operating in SMS PDU mode, executing
the above command line will cause an error to occur. This is because the syntax of the +CMGS
AT command is different in SMS PDU mode. To do the same task, the following command line
should be used instead:
AT+CMGS=42<CR>07915892000000F001000B915892214365F7000021493A283D0795C3
F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E<Ctrl+z>
When the GSM/GPRS modem or mobile phone is operating in different modes, the defined
values for certain parameters are different. Usually string values are defined for text mode while
numeric values are defined for PDU mode. For example, the +CMGL AT command is used to
list SMS messages stored in message storage. It takes one parameter that specifies the status
of the SMS messages to be retrieved. The following table lists the defined values for the
parameter in text mode and PDU mode:
Message status Defined values in text mode Defined values in PDU mode
Suppose you would like to list all SMS messages from message storage. If the GSM/GPRS
modem or mobile phone is operating in SMS text mode, you should assign the string value
"ALL" to the +CMGL AT command, like this:
AT+CMGL="ALL"
In SMS PDU mode, the numeric value 4 should be assigned to the +CMGL AT command
instead:
AT+CMGL=4
When the GSM/GPRS modem or mobile phone is operating in different modes, the input/output
format of SMS messages used by SMS AT commands is different. In SMS text mode, headers
and body of SMS messages are inputted/outputted as separate parameters/fields. In SMS PDU
mode, TPDUs (Transport Protocol Data Units) in hexadecimal format are inputted and
outputted. Headers and body of SMS messages are encoded in the TPDUs.
Here is an example for illustration. To send the SMS message "It is easy to send text
messages." to the mobile phone number +85291234567, the following command line should be
used in SMS text mode. As you can see below, the destination phone number header and
message body are provided to the +CMGS AT command as separate parameters.
AT+CMGS=42<CR>07915892000000F001000B915892214365F7000021493A283D0795C3
F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E<Ctrl+z>
Ease of Use
As you can see in the previous example, it is easier to use AT commands in SMS text mode.
You do not have to learn about the structure of different types of TPDUs in the bit level and the
encoding and decoding of the hexadecimal sequence.
Although it is easier to use AT commands in SMS text mode, it supports fewer features of SMS
messaging than SMS PDU mode. This is because you do not have complete control over the
header values and message body in SMS text mode. Some tasks, although can be done in text
mode, require the programmer to have knowledge about PDU mode and TPDU. For example,
to request a status report from SMSC in SMS text mode, you have to set bit 5 of the first octet of
the SMS-SUBMIT TPDU to 1 by the AT command +CSMP (command name in text: Set Text
Mode Parameters). Similar tasks include setting the message validity period and sending a flash
SMS message that immediately pops up on the phone screen when it arrives at the destination.
Level of Support
SMS PDU mode is more commonly supported by GSM/GPRS modems and mobile phones than
SMS text mode.
To find out the operating mode(s) supported by a GSM/GPRS modem or mobile phone, perform
a test operation with the +CMGF AT command. Below shows the response returned from my
Nokia 6021 mobile phone after the execution of the command line "AT+CMGF=?":
AT+CMGF=?
+CMGF: (0,1)
OK
The information response "+CMGF: (0,1)" indicates Nokia 6021 supports both PDU mode and
text mode.
To change the operating mode of a GSM/GPRS modem or mobile phone, perform a set
operation with the +CMGF AT command. The following example demonstrates how to set the
operating mode to SMS text mode:
AT+CMGF=1
OK
If the operating mode specified is not supported by the GSM/GPRS modem or mobile phone,
the final result code "ERROR" will be returned.
To find out the operating mode currently used by a GSM/GPRS modem or mobile phone,
perform a read operation with the +CMGF AT command. Here is an example:
AT+CMGF?
+CMGF: 0
OK
The response above indicates the GSM/GPRS modem or mobile phone is using SMS PDU
mode.
The mobile network operator usually pre-sets the correct service center number in the default
profile of settings stored in the SIM card. Most mobile phones provide some ways for the user to
view or change the service center number saved in the profiles of settings. For example, on my
Nokia 6021 mobile phone, the message center number saved in the default profile of settings
can be viewed and changed by going to Menu -> Messages -> Message settings -> Text
messages -> Sending profile -> Default profile -> Message centre number.
Some GSM/GPRS modems and mobile phones (for example, Nokia 6021, Sony Ericsson T68i,
Philips 598, etc) use the service center number in the default profile of settings as the default
value of the +CSCA AT command. As a result, if the service center number in the default profile
of settings is correct, you do not need to use the +CSCA AT command to set the service center
number.
Note
To some mobile devices such as Nokia 6021, the +CSCA AT command does not save the
service center number in non-volatile memory. Hence, if you switch off the GSM/GPRS modem
or mobile phone, the setting will be gone. To save the service center number set with the AT
command +CSCA, you have to make use of the AT command +CSAS (command name in text:
Save Settings). To restore the saved service center number, the AT command +CRES
(command name in text: Restore Settings) is required.
The command behavior is different on some mobile devices such as Sony Ericsson T68i and
Philips 598. Every time the AT command +CSCA is used to change the SMSC address, the
new SMSC address is saved to non-volatile memory.
+CSCA=address[,address_type]
The second parameter of the +CSCA AT command, address_type, specifies the type of the
SMSC address assigned to the address parameter. Two values, 129 and 145, are commonly
used.
• 129. Meaning: The SMSC address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) but it is not sure whether the SMSC address is an
international number, a national number or a number of other types. Example
addresses: "85291234567" and "91234567".
• 145. Meaning: The SMSC address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) and it is an international number. Example address:
"+85291234567".
• 129 if the SMSC address does not start with a "+" character. For example,
"85291234567".
• 145 if the SMSC address starts with a "+" character. For example, "+85291234567".
+CSCA: address,address_type
AT+CSCA?
+CSCA: "+85291111111",145
OK
If you find that the service center address is not correct, use the +CSCA AT command to
change it, like this:
AT+CSCA="+85290000000",145
OK
The final result code OK indicates the service center address was set successfully. If the
execution of the command line fails, the final result code will be ERROR.
1. Select the message storage area that will be used when sending, receiving, reading, writing
or deleting SMS messages.
2. Find the number of messages that are currently stored in the message storage area.
3. Find the maximum number of messages that can be stored in the message storage area.
+CPMS=message_storage1[,message_storage2[,message_storage3]]
Before we discuss each of the parameters, let's see an example that gives you some idea of
how an actual command line should look like:
AT+CPMS="ME","SM","MT"
The first parameter of the +CPMS AT command, message_storage1, specifies the message
storage area that will be used when reading or deleting SMS messages. (For details about
reading SMS messages, see AT commands +CMGR and +CMGL. For details about deleting
SMS messages, see the AT command +CMGD.)
The second parameter of the +CPMS AT command, message_storage2, specifies the message
storage area that will be used when sending SMS messages from message storage or writing
SMS messages. (For details about sending SMS messages from message storage, see the AT
command +CMSS. For details about writing SMS messages, see the AT command +CMGW.)
The third parameter of the +CPMS AT command, message_storage3, specifies the preferred
message storage area for storing newly received SMS messages. If you use the +CNMI AT
command (command name in text: New Message Indications to TE) to tell the GSM/GPRS
modem or mobile phone to forward newly received SMS messages directly to the PC instead of
storing them in the message storage area, you do not need to care about
the message_storage3 parameter.
Here are the values defined in the SMS specification that may be assigned to the
parametersmessage_storage1, message_storage2 and message_storage3:
Note that a GSM/GPRS modem or mobile phone may not support all the above values and it
may support other manufacturer specific values. To learn how to find the values supported by
your GSM/GPRS modem or mobile phone, please refer to the section "Finding the Message
Storage Areas Supported by a GSM/GPRS Modem or Mobile Phone".
+CPMS: used_space1,max_space1,used_space2,max_space2,used_space3,max_s
pace3
• used_space1 is the number of messages currently stored in the message storage area
specified by the message_storage1 parameter.
• max_space1 is the maximum number of messages that can be stored in the message
storage area specified by the message_storage1 parameter.
• used_space2 is the number of messages currently stored in the message storage area
specified by the message_storage2 parameter.
• max_space2 is the maximum number of messages that can be stored in the message
storage area specified by the message_storage2 parameter.
• used_space3 is the number of messages currently stored in the message storage area
specified by the message_storage3 parameter.
• max_space3 is the maximum number of messages that can be stored in the message
storage area specified by the message_storage3 parameter.
If the GSM/GPRS modem or mobile phone executes the above command line successfully, it
will return an information response to the computer / PC. The information response of the
+CPMS AT command has the following format:
+CPMS: (storage1a,storage1b,...),(storage2a,storage2b,...),
(storage3a,storage3b,...)
The first, second and third parentheses contain the values supported by
the message_storage1parameter, the message_storage2 parameter and
the message_storage3 parameter respectively.
Finding the Message Storage Areas Supported by the GSM/GPRS Modem or Mobile
Phone
First, enter the command line "AT+CPMS=?" in a terminal program (for example, Windows'
HyperTerminal program) to find the message storage areas supported by the GSM/GPRS
modem or mobile phone. Below shows the response returned from my Nokia 6021 to Windows'
HyperTerminal program after the execution of the command line "AT+CPMS=?":
AT+CPMS=?
+CPMS: ("ME","SM"),("ME","SM"),("MT")
OK
The information response above indicates Nokia 6021 supports the use of "ME" or "SM" for
SMS reading, deleting, sending and writing, while it only supports the use of "MT" for storing
inbound SMS messages.
Selecting Message Storage Areas
After knowing what message storage areas are selectable, we can now perform a set operation
to select the message storage areas. For example, let's say you want to instruct the
GSM/GPRS modem or mobile phone to use:
• the phone message storage area for SMS reading and deleting,
• the SIM message storage area for SMS writing and sending, and
• both the phone message storage area and SIM message storage area for storing
inbound SMS messages.
You should assign the string values "ME", "SM" and "MT" to the +CPMS AT command.
Following shows the response returned from my Nokia 6021 mobile phone to HyperTerminal:
AT+CPMS="ME","SM","MT"
+CPMS: 2,150,2,10,4,160
OK
As you can see, there are six values in the information response of the +CPMS AT command.
Following is a description of them.
The value 2 indicates there are currently two messages stored in the ME message storage
area. 150 is the maximum number of messages that can be stored in the ME message storage
area.
The value 2 indicates there are currently two messages stored in the SM message storage
area. 10 is the maximum number of messages that can be stored in the SM message storage
area.
The value of the fifth field of the +CPMS information response, 4, indicates there are currently
four messages stored in the MT message storage area. The same result can also be obtained
by calculating manually like this:
Number of messages currently stored in the ME message storage area +
Number of messages currently stored in the SM message storage area
= 2 + 2
= 4
The value of the sixth field of the +CPMS information response, 160, is the maximum number of
messages that can be stored in the MT message storage area. The same result can also be
obtained by calculating manually like this:
AT+CPMS?
If the GSM/GPRS modem or mobile phone executes the above command line successfully, it
will return an information response to the computer / PC. The +CPMS information response has
the following format:
+CPMS: message_storage1,used_space1,max_space1,message_storage2,used_s
pace2,max_space2,message_storage3,used_space3,max_space3
The first field of the information response of the +CPMS AT command, message_storage1,
contains a string that indicates the message storage area to be used when reading or deleting
SMS messages. (For details about reading SMS messages, see AT
commands +CMGR and +CMGL. For details about deleting SMS messages, see the AT
command +CMGD.)
The used_space1 Field
The second field of the information response of the +CPMS AT command, used_space1,
contains an integer that indicates the number of messages currently stored in the message
storage areamessage_storage1.
The third field of the information response of the +CPMS AT command, max_space1, contains
an integer that indicates the maximum number of messages that can be stored in the message
storage areamessage_storage1.
The fourth field of the information response of the +CPMS AT command, message_storage2,
contains a string that indicates the message storage area to be used when sending SMS
messages from message storage or writing SMS messages. (For details about sending SMS
messages from message storage, see the AT command +CMSS. For details about writing SMS
messages, see the AT command+CMGW.)
The fifth field of the information response of the +CPMS AT command, used_space2, contains
an integer that indicates the number of messages currently stored in the message storage
areamessage_storage2.
The sixth field of the information response of the +CPMS AT command, max_space2, contains
an integer that indicates the maximum number of messages that can be stored in the message
storage area message_storage2.
The seventh field of the information response of the +CPMS AT command, message_storage3,
contains a string that indicates the preferred message storage area to be used for storing newly
received SMS messages.
The used_space3 Field
The eighth field of the information response of the +CPMS AT command, used_space3,
contains an integer that indicates the number of messages currently stored in the message
storage areamessage_storage3.
The ninth field of the information response of the +CPMS AT command, max_space3, contains
an integer that indicates the maximum number of messages that can be stored in the message
storage area message_storage3.
22.5.1. Example
The example below shows the response returned by my Nokia 6021 mobile phone to Windows'
HyperTerminal program after the read command "+CPMS?" has been executed:
AT+CPMS?
+CPMS: "ME",2,150,"SM",2,10,"MT",4,160
OK
As you can see, there are nine values in the information response of the +CPMS AT command.
Following is a description of them.
The string value "ME" indicates that the phone message storage area will be used for SMS
reading and deleting. The value 2 indicates that there are currently two messages stored in the
phone message storage area. 150 is the maximum number of messages that can be stored in
the phone message storage area.
The string value "SM" indicates the SIM message storage area will be used for SMS writing and
sending. The value 2 tells us that there are currently two messages stored in the SIM message
storage area. 10 is the maximum number of messages that can be stored in the SIM message
storage area.
The Seventh, Eighth and Ninth Fields: "MT",4,160
The string value "MT" indicates that both the phone message storage area and SIM message
storage area will be used for storing inbound SMS messages. The value 4 tells us that there are
currently four messages stored in the phone message storage area and SIM message storage
area. 160 is the maximum number of messages that can be stored in the phone message
storage area and SIM message storage area.
+CMGW[=address[,address_type[,message_status]]]<CR>sms_message_body<Ct
rl+z>
Before we discuss each of the parameters, let's see an example that gives you some idea of
how an actual command line should look like:
The first parameter of the +CMGW AT command, address, specifies the destination address to
send the SMS message to. Usually it is a mobile number formatted using the typical ISDN /
telephony numbering plan (ITU E.164/E.163). For example, "+85291234567" and "91234567".
Note that the value passed to the address parameter should be a string, i.e. it should be
enclosed in double quotes.
The address parameter is optional and so it can be omitted. Later when you want to send the
SMS message out, you can specify the destination address by the +CMSS AT
command (command name in text: Send Message from Storage).
The second parameter of the +CMGW AT command, address_type, specifies the type of the
address assigned to the address parameter. Two values are commonly used. They are 129 and
145:
• 129. Meaning: The value of address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) but it is not sure whether the value of address is an
international number, a national number or a number of other types. Example
addresses: "85291234567", "91234567".
• 145. Meaning: The value of address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) and it is an international number. Example address:
"+85291234567".
• 129 if the value of address does not start with a "+" character. For example,
"85291234567".
• 145 if the value of address starts with a "+" character. For example, "+85291234567".
The third parameter of the +CMGW AT command, message_status, specifies the status of the
SMS message to be written. The SMS specification has defined four status values:
Note that the value assigned to the message_status parameter should be a string. Thus, it
should be enclosed in double quotes.
<CR>, which represents the carriage return character, follows the message_status parameter.
When the GSM/GPRS modem or mobile phone receives the carriage return character, it will
send back a prompt formed by these four characters: the carriage return character, the linefeed
character, the ">" character and the space character. If you don't understand what this means,
don't worry. This should be clear to you when you see the example in the section "Example
Demonstrating How to Use the +CMGW AT Command to Write SMS Text Messages to
Message Storage in SMS Text Mode".
The fourth parameter of the +CMGW AT command, sms_message_body, specifies the SMS
message body to be written to the memory/message storage area. Entering
the <Esc> character will cancel the +CMGW AT command. If you don't understand what this
means, see the example in the section "Example Demonstrating How to Use the +CMGW AT
Command to Write SMS Text Messages to Message Storage in SMS Text Mode".
When you finish entering the SMS message body, you have to enter the <Ctrl+z> character to
mark the end of the SMS message body. The GSM/GPRS modem or mobile phone will then
attempt to write the SMS message to the memory/message storage area.
23.2. SMSC Number Stored with the SMS Message (SMS Text Mode)
In SMS text mode, the +CMGW AT command does not have a parameter that allows you to
specify an SMSC number. (Note that the +CMGW AT command does have such parameter
when the GSM/GPRS modem or mobile phone is operating in SMS PDU mode.) However,
when an SMS message is written to message storage, an SMSC number is actually stored with
it. The SMSC number stored is the one specified by the +CSCA AT command (command name
in text: Service Centre Address). Later if you send the SMS message, it will be transmitted
through this SMSC. Once an SMS message has been written to message storage, it is not
possible to change the SMSC number stored with the SMS message by using AT commands.
Note that it is possible that the command behavior on your mobile device is slightly different
from what was described above.
More information about this issue is available in the "SMSC Number to be Used by the +CMSS
AT Command to Send SMS Messages" section of this SMS tutorial.
index is an integer that tells us the memory location to which the SMS message was written in
the message storage area.
Instructing the GSM/GPRS Modem or Mobile Phone to Operate in SMS Text Mode
First, enter the command line "AT+CMGF=1" in a terminal program (for example,
HyperTerminal in Microsoft Windows) to instruct the GSM/GPRS modem or mobile phone to
operate in SMS text mode. This step is necessary because the default mode is SMS PDU
mode. Below shows the response returned from Nokia 6021 to HyperTerminal after the
execution of the command line "AT+CMGF=1":
AT+CMGF=1
OK
The final result code OK indicates the +CMGF AT command was executed successfully. If the
final result code ERROR is returned, it is likely that the GSM/GPRS modem or mobile phone
does not support SMS text mode. To check whether the GSM/GPRS modem or mobile phone
supports SMS text mode, enter the command line "AT+CMGF=?" in the terminal program. Here
is the response returned from Nokia 6021 to HyperTerminal:
AT+CMGF=?
+CMGF: (0,1)
OK
The values in the parentheses indicate the modes that the GSM/GPRS modem or mobile phone
can operate in. The value 0 represents SMS PDU mode and the value 1 represents SMS text
mode. From the above response, we know that Nokia 6021 can operate in either SMS PDU
mode or SMS text mode. See the section titled "Selecting the Operating Mode (AT+CMGF)" of
this SMS tutorial if you want to learn further details about the +CMGF AT command.
Selecting the Message Storage Area to Write SMS Text Messages to
Second, use the AT command +CPMS (command name in text: Preferred Message Storage) to
select the message storage area to write SMS text messages to. For example, to instruct the
GSM/GPRS modem or mobile phone to use the message storage area in the SIM card for the
AT command +CMGW, assign the string value "SM" to the second parameter of the +CPMS AT
command, like this:
AT+CPMS="ME","SM"
The first parameter of the +CPMS AT command is used to select the message storage area for
reading and deleting SMS messages. It has no use to us here. So, it does not matter what value
is assigned to the first parameter.
Now press the Enter key on the keyboard and you should see something similar to this:
AT+CPMS="ME","SM"
+CPMS: 2,150,2,10,4,160
OK
Detailed information about the +CPMS AT command is available in the earlier section
"Preferred Message Storage (AT+CPMS)" of this SMS tutorial.
Setting the SMSC Number to be Stored with the SMS Text Message
Third, use the AT command +CSCA (command name in text: Service Centre Address) to set
the SMSC number to be stored with the SMS text message. Later if you send the SMS text
message, it will be transmitted via the SMSC at this number. Usually the default setting is
correct and you do not need to make any changes. Below demonstrates how to use the +CSCA
AT command to set "+85290000000" as the SMSC number:
AT+CSCA="+85290000000"
OK
Detailed information about the +CSCA AT command can be found in the "Setting or Reading
the Service Center Address / SMSC Address (AT+CSCA)" section of this SMS tutorial.
Fourth, you can now use the +CMGW AT command to write a text message to the message
storage area. Suppose you want the destination mobile phone number to be +85291234567
and the message status to be "stored unsent", you should enter something like this in the
terminal program:
AT+CMGW="+85291234567",145,"STO UNSENT"
Then, press the Enter key of the keyboard to send a carriage return character to the
GSM/GPRS modem or mobile phone. The GSM/GPRS modem or mobile phone will send back
a prompt formed by four characters. They are the carriage return character, the linefeed
character, the ">" character and the space character. If all characters are to be displayed, the
characters you have sent to and received from the GSM/GPRS modem or mobile phone so far
are:
AT+CMGW="+85291234567",145,"STO UNSENT"<CR>
<CR><LF>><Space>
However, the carriage return character and linefeed character have special meanings to a
terminal program. When a terminal program sees a carriage return character, it moves the
cursor to the beginning of the current line. When it sees a linefeed character, it moves the
cursor to the same position on the next line. So, here is what you will actually see in a terminal
program such as HyperTerminal:
AT+CMGW="+85291234567",145,"STO UNSENT"
>
If you want to cancel the write command at this point, press the Esc key on the keyboard. The
GSM/GPRS modem or mobile phone will then return the OK final result code. Here shows the
response returned from Nokia 6021:
AT+CMGW="+85291234567",145,"STO UNSENT"
>
OK
Some mobile devices return a slightly different response. One example is Philips 598:
AT+CMGW="+85291234567",145,"STO UNSENT"
>
OK
If you do not want to cancel the write command, enter the body of the SMS text message that
you want to write to the message storage area. Press Enter on the keyboard if you want to start
a new line. When finished, press Ctrl+z on the keyboard. The GSM/GPRS modem or mobile
phone then attempts to write the text message to the message storage area and returns a
response to the computer / PC. Suppose the SMS text message is "It is easy to write text
messages.". Below shows what you should see in a terminal program:
AT+CMGW="+85291234567",145,"STO UNSENT"
> It is easy to write text messages.
+CMGW: 3
OK
The value in the information response is the index that indicates the location where the SMS
text message is stored in the message storage area. In the above example, the information
response tells us that the SMS text message "It is easy to write text messages." has been
written to the memory location at index 3.
The final result code OK tells us the execution of the +CMGW AT command is successful. If it
fails, the GSM/GPRS modem or mobile phone will return either the final result code ERROR or
+CMS ERROR. For example, if the message storage area is out of storage space, the
GSM/GPRS modem or mobile phone will return +CMS error 322, like this:
AT+CMGW="+85291234567",145,"STO UNSENT"
> It is easy to write text messages.
+CMS ERROR: 322
23.5. Syntax of the +CMGW AT Command in SMS PDU Mode
In SMS PDU mode, the syntax of the +CMGW AT command is: (Optional parameters are
enclosed in square brackets.)
+CMGW=TPDU_length[,message_status]<CR>SMSC_number_and_TPDU<Ctrl+z>
Before we discuss each of the parameters, let's see an example that gives you some idea of
how an actual command line should look like:
AT+CMGW=42,2<CR>07915892000000F001000B915892214365F7000021493A283D0795
C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E<Ctrl+z>
The first parameter of the +CMGW AT command, TPDU_length, specifies the length (in octets.
1 octet = 8 bits) of the TPDU (Transfer Protocol Data Unit) assigned to
the SMSC_number_and_TPDU parameter. In the earlier example command line, the value
assigned to the SMSC_number_and_TPDU parameter is:
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
It can be divided into two parts. The following part is the TPDU:
01000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341ED
F27C1E3E97E72E
The TPDU is coded in hexadecimal format. Each character represents 4 bits, i.e. 1/2 octet. The
TPDU has 84 characters and so there are totally 42 octets. That's why the value assigned to
the TPDU_lengthparameter is 42.
Note: To some mobile devices (for example, Sony Ericsson T68i and Philips 598), an error will
occur if the TPDU type is SMS-SUBMIT and the message_status parameter value is 0 or 1, or if
the TPDU type is SMS-DELIVER and the message_status parameter value is 2 or 3.
<CR>, which represents the carriage return character, follows the message_status parameter.
When the GSM/GPRS modem or mobile phone receives the carriage return character, it will
send back a prompt formed by these four characters: the carriage return character, the linefeed
character, the ">" character and the space character. If you don't understand what this means,
don't worry. This should be clear to you when you see the example in the section "Example
Demonstrating How to Use the +CMGW AT Command to Write SMS Text Messages to
Message Storage in SMS PDU Mode".
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E3
2885EC6D341EDF27C1E3E97E72E
Besides the TPDU type SMS-SUBMIT, the +CMGW AT command accepts other TPDU types
such as SMS-DELIVER.
When you finish entering the value for the SMSC_number_and_TPDU parameter, you have to
enter the<Ctrl+z> character to mark the end of the value. The GSM/GPRS modem or mobile
phone will then attempt to write the SMS message to the message storage area.
23.6. SMSC Number Stored with the SMS Message (SMS PDU Mode)
In SMS PDU mode, you can specify an SMSC number to the +CMGW AT command through
theSMSC_number_and_TPDU parameter. If no SMSC number is specified, the GSM/GPRS
modem or mobile phone retrieves the SMSC number specified by the +CSCA AT command
(command name in text: Service Centre Address) and stores it with the SMS message. Later if
you send the SMS message, it will be transmitted through this SMSC. Once an SMS message
has been written to message storage, it is not possible to change the SMSC number stored with
the SMS message by using AT commands.
Note that it is possible that the command behavior on your mobile device is slightly different
from what was described above.
More information about this issue is available in the "SMSC Number to be Used by the +CMSS
AT Command to Send SMS Messages" section of this SMS tutorial.
+CMGW: index
Here is an example that gives you some idea of how an actual information response should look
like:
+CMGW: 5
The information response of the +CMGW AT command has only one field called index. The field
contains an integer that tells us the memory location to which the SMS message was written in
the message storage area.
Instructing the GSM/GPRS Modem or Mobile Phone to Operate in SMS PDU Mode
First, instruct the GSM/GPRS modem or mobile phone to operate in SMS PDU mode by
entering the command line "AT+CMGF=0" in a terminal program (for example, HyperTerminal in
Microsoft Windows). Below shows the response returned from Nokia 6021 to HyperTerminal
after the execution of the command line "AT+CMGF=0":
AT+CMGF=0
OK
The final result code OK indicates the +CMGF AT command was executed successfully. If the
final result code ERROR is returned, it is likely that the GSM/GPRS modem or mobile phone
does not support SMS PDU mode. To check whether the GSM/GPRS modem or mobile phone
supports SMS PDU mode, enter the command line "AT+CMGF=?" in the terminal program.
Here is the response returned from Nokia 6021 to HyperTerminal:
AT+CMGF=?
+CMGF: (0,1)
OK
The values in the parentheses indicate the modes that the GSM/GPRS modem or mobile phone
can operate in. The values 0 and 1 represent SMS PDU mode and SMS text mode respectively.
From the above response, we know that Nokia 6021 can operate in either SMS PDU mode or
SMS text mode. See the section titled "Selecting the Operating Mode (AT+CMGF)" of this SMS
tutorial if you want to learn further details about the +CMGF AT command.
Second, use the AT command +CPMS (command name in text: Preferred Message Storage) to
select the message storage area to write SMS text messages to. For example, to instruct the
GSM/GPRS modem or mobile phone to use the message storage area in the SIM card for the
AT command +CMGW, assign the string value "SM" to the second parameter of the +CPMS AT
command, like this:
AT+CPMS="ME","SM"
The first parameter of the +CPMS AT command is used to select the message storage area for
reading and deleting SMS messages. It has no use to us here. So, it does not matter what value
is assigned to the first parameter.
Now press the Enter key on the keyboard and you should see something similar to this:
AT+CPMS="ME","SM"
+CPMS: 2,150,2,10,4,160
OK
Detailed information about the +CPMS AT command is available in the earlier section
"Preferred Message Storage (AT+CPMS)" of this SMS tutorial.
(Optional in SMS PDU Mode) Setting the SMSC Number to be Stored with the SMS Text
Message
Third, use the AT command +CSCA (command name in text: Service Centre Address) to set
the SMSC number to be stored with the SMS text message. Later if you send the SMS text
message, it will be transmitted via the SMSC at this number. Usually the default setting is
correct and you do not need to make any changes. In SMS PDU mode, you can skip this step
since you can pass the SMSC number directly to the +CMGW AT command as a parameter.
This is different from SMS text mode, in which the only way to set the SMSC number to be
stored with the SMS text message is by using the +CSCA AT command.
Below demonstrates how to use the +CSCA AT command to set "+85290000000" as the SMSC
number:
AT+CSCA="+85290000000"
OK
Detailed information about the +CSCA AT command can be found in the "Setting or Reading
the Service Center Address / SMSC Address (AT+CSCA)" section of this SMS tutorial.
Fourth, you can now use the +CMGW AT command to write a text message to the message
storage area. Suppose you want the SMS center number to be +85290000000, the destination
mobile phone number to be +85291234567, and the text message to be "It is easy to send text
messages.", the hexadecimal sequence to be passed to the +CMGW AT command should be:
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E3
2885EC6D341EDF27C1E3E97E72E
and the length of the SMS-SUBMIT TPDU embedded in the hexadecimal sequence is 42 octets.
If you forget how these values are obtained, you may want to go back to the earlier section
"Syntax of the +CMGW AT Command in SMS PDU Mode".
Now pass the length of the SMS-SUBMIT TPDU to the +CMGW AT command by entering the
following command line in the terminal program:
AT+CMGW=42
Then, press the Enter key of the keyboard to send a carriage return character to the
GSM/GPRS modem or mobile phone. The GSM/GPRS modem or mobile phone will send back
a prompt formed by four characters. They are the carriage return character, the linefeed
character, the ">" character and the space character. If all characters are to be displayed, the
characters you have sent to and received from the GSM/GPRS modem or mobile phone so far
are:
AT+CMGW=42<CR>
<CR><LF>><Space>
However, the carriage return character and linefeed character have special meanings to a
terminal program. When a terminal program sees a carriage return character, it moves the
cursor to the beginning of the current line. When it sees a linefeed character, it moves the
cursor to the same position on the next line. So, here is what you will actually see in a terminal
program such as HyperTerminal:
AT+CMGW=42
>
If you want to cancel the write command at this point, press the Esc key on the keyboard. The
GSM/GPRS modem or mobile phone will then return the OK final result code. Here shows the
response returned from Nokia 6021 (or Sony Ericsson T68i):
AT+CMGW=42
>
OK
Some mobile devices return a slightly different response. One example is Philips 598:
AT+CMGW=42
>
OK
If you do not want to cancel the write command, enter the hexadecimal sequence containing the
SMS text message that you want to write to the message storage area. When finished, press
Ctrl+z on the keyboard. The GSM/GPRS modem or mobile phone then attempts to write the text
message to the message storage area and returns a response to the computer / PC. Below
shows what you should see in a terminal program:
AT+CMGW=42
>
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
+CMGW: 3
OK
The value in the +CMGW information response is the index that indicates the memory location
to which the SMS text message was written. From above, we know that the SMS text message
was written to the memory location at index 3.
The final result code OK tells us the writing of the text message to message storage was
successful. If the execution of the +CMGW AT command fails, the GSM/GPRS modem or
mobile phone will return either the final result code ERROR or +CMS ERROR. For example, if
the message storage area is out of storage space, the GSM/GPRS modem or mobile phone will
return +CMS error 322, like this:
AT+CMGW=42
>
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
+CMS ERROR: 322
+CMGD=index[,flag]
In the above line, index is an integer specifying the location of the SMS message to be deleted
from the message storage area by the +CMGD AT command, and flag is an integer specifying
whether to delete SMS messages according to their message status. The SMS specification
has defined these flagvalues: 0, 1, 2, 3 and 4.
• 0. Meaning: Delete only the SMS message stored at the location index from the
message storage area. This is the default value.
• 1. Meaning: Ignore the value of index and delete all SMS messages whose status is
"received read" from the message storage area.
• 2. Meaning: Ignore the value of index and delete all SMS messages whose status is
"received read" or "stored sent" from the message storage area.
• 3. Meaning: Ignore the value of index and delete all SMS messages whose status is
"received read", "stored unsent" or "stored sent" from the message storage area.
• 4. Meaning: Ignore the value of index and delete all SMS messages from the message
storage area.
To find the flag values supported by your GSM/GPRS modem or mobile phone, you can
perform a test operation using the +CMGD AT command. See the next section for the details.
+CMGD: (list_of_indexes)[,(list_of_flag_values)]
• The values inside the first parentheses are the values that are supported by
the index parameter of the +CMGD AT command.
• The values inside the second parentheses are the values that are supported by
the flag parameter of the +CMGD AT command. Note: A GSM/GPRS modem or mobile
phone might not provide these values since the SMS specification defines them as
optional.
As an example, here is the response returned from my Nokia 6021 mobile phone to Windows'
HyperTerminal program after the execution of the test command "+CMGD=?":
AT+CMGD=?
+CMGD: (1-10),(0-4)
OK
From above, we know that the Nokia 6021 mobile phone allows any integer between 1 and 10
to be assigned to the index parameter of the +CMGD AT command. Also, the Nokia 6021
mobile phone supports all of the five flag values defined in the SMS specification.
Do you remember that we described the format of values inside parentheses in the section
"Test Command -- Checks Whether a Certain AT Command is Supported"? If not, you may
want to go back and have a look. Here are a few examples showing some of the possibilities:
"(0-4)", "(0,1,2,3,4)", "(0,2-4)".
24.3. Example Demonstrating How to Use the +CMGD AT Command
to Delete SMS Text Messages
Now let's see an example that demonstrates how to use the +CMGD AT command to delete an
SMS text message from the message storage area. Suppose you have written an SMS text
message to the message storage area by the +CMGW AT command (details about the +CMGW
AT command can be found in the earlier section "Writing SMS Messages to Memory / Message
Storage (AT+CMGW)" of this SMS tutorial), like this:
AT+CMGW="+85291234567"
> A simple demo of SMS text messaging.
+CMGW: 1
OK
The information response of the +CMGW AT command tells us that the SMS text message is
stored in the memory location at index 1. To delete the SMS text message, specify 1 to
the index parameter of the +CMGD AT command, like this:
(Important note: Make sure you are writing text messages to and deleting text messages from
the same message storage area. If not, you may delete the wrong text message. Details about
message storage areas can be found in the earlier section "Preferred Message Storage
(AT+CPMS)" of this SMS tutorial.)
AT+CMGD=1
OK
The final result code OK indicates the SMS text message "A simple demo of SMS text
messaging." was deleted successfully. If the operation fails, the final result code returned will
either be ERROR or +CMS ERROR.
Here is another example. Suppose you want to delete all SMS messages stored in the message
storage area. To do this, assign 4 to the flags parameter of the +CMGD AT command. The
value assigned to theindex parameter does not matter since it will be ignored by the
GSM/GPRS modem or mobile phone.
AT+CMGD=1,4
OK
25. Sending SMS Messages from a
Computer / PC Using AT Commands
(AT+CMGS, AT+CMSS)
Either of the AT commands +CMGS (command name in text: Send Message) and +CMSS
(command name in text: Send Message from Storage) can be used to send SMS messages
from a computer / PC. The key difference between them is that the +CMGS AT command takes
the SMS message to be sent as a parameter, while the +CMSS AT command takes the index
number that specifies the location of the SMS message in the message storage area as a
parameter. Following is an example for illustrating the difference. Suppose you want to send the
text message "Sending text messages is easy." from a computer / PC to the mobile phone
number 91234567 using the +CMGS AT command in SMS text mode. Here is the command
line to be used:
To send the same text message using the +CMSS AT command, first you have to use the AT
command +CMGW (command name in text: Write Message to Memory) to write the text
message to the message storage area. In SMS text mode, the command line should be:
Let's say the SMS text message is now located at index 3 of the message storage area. You
can use the +CMSS AT command to send the text message to the message center by the
following command line:
AT+CMSS=3
As storage space is limited, if every SMS text message sent is left in the message storage area,
there will come a time when no more SMS text messages can be written. To free some storage
space, you can use the AT command +CMGD (command name in text: Delete Message) to
delete the SMS text message from the message storage area, like this:
AT+CMGD=3
As you can see above, sending an SMS message by the +CMSS AT command is a bit
cumbersome, since it involves more steps and AT commands. However, a copy of the sent
SMS message can be saved in the message storage area. This is not achievable with the
+CMGS AT command.
In some situations, it is more convenient to send SMS messages by the +CMSS AT command
than the +CMGS AT command. For example, if you have to send the same SMS message to
multiple recipients, using the +CMSS AT command is more convenient:
AT+CMSS=3,"91234567"
AT+CMSS=3,"97777777"
AT+CMSS=3,"96666666"
...
Note: To keep things simple in the above examples, we assume that the same message
storage area is used by the AT commands +CMSS, +CMGW, +CMGD and for receiving SMS
messages. But this may not be true in real situations. To learn how to set the message storage
areas to be used by different SMS operations, please refer to the earlier section "Preferred
Message Storage (AT+CPMS)" of this SMS tutorial.
Parameters +CMGS takes the SMS message to +CMSS takes the index number that
be sent as a parameter. specifies the location of the SMS
message in the message storage
area as a parameter.
Sending new SMS messages Using +CMGS is more convenient. +CMSS has to be used together with
+CMGS can be used to send new +CMGW and +CMGD for sending
SMS messages without the help of new SMS messages. As a result, the
other AT commands. process involves more steps and is
a bit cumbersome.
However, no copy of the SMS
message sent is saved in the However, a copy of the SMS
message storage area. message sent can be saved in the
message storage area.
+CMGS AT command +CMSS AT command
Sending the same SMS message to Using +CMGS is less convenient. Using +CMSS is more convenient.
multiple recipients
+CMGS=address[,address_type]<CR>sms_message_body<Ctrl+z>
Before we discuss each of the parameters, let's see an example that gives you some idea of
how an actual command line should look like:
The first parameter of the +CMGS AT command, address, specifies the destination address to
send the SMS message to. Usually it is a mobile number formatted using the typical ISDN /
telephony numbering plan (ITU E.164/E.163). For example, "+85291234567", "91234567", etc.
Note that the value passed to the address parameter should be a string, i.e. it should be
enclosed in double quotes.
The second parameter of the +CMGS AT command, address_type, specifies the type of the
address assigned to the address parameter. Two values are commonly used. They are 129 and
145:
• 129. It means the value of address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) but it is not sure whether the value of address is an
international number, a national number or a number of other types. Example
addresses: "85291234567", "91234567".
• 145. It means the value of address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) and it is an international number. Example address:
"+85291234567".
As address_type is an optional parameter, it can be omitted. If you do so, the GSM/GPRS
modem or mobile phone will use the default value of the address_type parameter, which is:
• 129 if the value of address does not start with a "+" character. For example,
"85291234567".
• 145 if the value of address starts with a "+" character. For example, "+85291234567".
<CR>, which represents the carriage return character, follows the address_type parameter.
When the GSM/GPRS modem or mobile phone receives the carriage return character, it will
send back a prompt formed by these four characters: the carriage return character, the linefeed
character, the ">" character and the space character. If you don't understand what this means,
don't worry. This should be clear to you when you see the example in the section "Example
Demonstrating How to Use the +CMGS AT Command to Send SMS Text Messages in SMS
Text Mode".
The third parameter of the +CMGS AT command, sms_message_body, specifies the body of
the SMS message to be sent. Entering the <Esc> character will cancel the +CMGS AT
command. If you don't understand what this means, see the example in the section "Example
Demonstrating How to Use the +CMGS AT Command to Send SMS Text Messages in SMS
Text Mode".
When you finish entering the SMS message body, you have to enter the <Ctrl+z> character to
mark the end of the SMS message body. The GSM/GPRS modem or mobile phone will then
attempt to send the SMS message to the SMS center.
+CMGS: message_reference[,service_center_time_stamp]
Here is an example that gives you some idea of how an actual information response should look
like:
+CMGS: 5,"07/02/05,08:30:45+32"
The first field of the information response of the +CMGS AT command, message_reference,
contains an integer in the range from 0 to 255. It is a reference number allocated by the
GSM/GPRS modem or mobile phone to the SMS message sent.
For example, "07/02/05,08:30:45+32" represents 5 February 2007, 8:30:45 GMT+8 hours. "+32"
means GMT+8 hours, since 32 quarters of an hour = 8 hours.
Instructing the GSM/GPRS Modem or Mobile Phone to Operate in SMS Text Mode
First, enter the command line "AT+CMGF=1" in a terminal program (for example,
HyperTerminal in Microsoft Windows) to instruct the GSM/GPRS modem or mobile phone to
operate in SMS text mode. This step is necessary because the default mode is SMS PDU
mode. Below shows the response returned from Nokia 6021 to HyperTerminal after the
execution of the command line "AT+CMGF=1":
AT+CMGF=1
OK
The final result code OK indicates the +CMGF AT command was executed successfully. If the
final result code ERROR is returned, it is likely that the GSM/GPRS modem or mobile phone
does not support SMS text mode. To check whether the GSM/GPRS modem or mobile phone
supports SMS text mode, enter the command line "AT+CMGF=?" in the terminal program. Here
is the response returned from Nokia 6021 to HyperTerminal:
AT+CMGF=?
+CMGF: (0,1)
OK
The values in the parentheses indicate the modes that the GSM/GPRS modem or mobile phone
can operate in. The value 0 represents SMS PDU mode and the value 1 represents SMS text
mode. From the above response, we know that Nokia 6021 can operate in either SMS PDU
mode or SMS text mode. See the section titled "Selecting the Operating Mode (AT+CMGF)" of
this SMS tutorial if you want to learn further details about the +CMGF AT command.
Second, use the AT command +CSCA (command name in text: Service Centre Address) to set
the SMSC number to be used to send SMS text messages. Usually the default setting is correct
and you do not need to make any changes. Below demonstrates how to use the +CSCA AT
command to set "+85290000000" as the SMSC number:
AT+CSCA="+85290000000"
OK
Detailed information about the +CSCA AT command can be found in the "Setting or Reading
the Service Center Address / SMSC Address (AT+CSCA)" section of this SMS tutorial.
AT+CMGS="+85291234567"
Then, press the Enter key of the keyboard to send a carriage return character to the
GSM/GPRS modem or mobile phone. The GSM/GPRS modem or mobile phone will send back
a prompt formed by four characters. They are the carriage return character, the linefeed
character, the ">" character and the space character. If all characters are to be displayed, the
characters you have sent to and received from the GSM/GPRS modem or mobile phone so far
are:
AT+CMGS="+85291234567"<CR>
<CR><LF>><Space>
However, the carriage return character and linefeed character have special meanings to a
terminal program. When a terminal program sees a carriage return character, it moves the
cursor to the beginning of the current line. When it sees a linefeed character, it moves the
cursor to the same position on the next line. So, here is what you will actually see in a terminal
program such as HyperTerminal:
AT+CMGS="+85291234567"
>
If you want to cancel the send command at this point, press the Esc key on the keyboard. The
GSM/GPRS modem or mobile phone will then return the OK final result code. Here shows the
response returned from Nokia 6021:
AT+CMGS="+85291234567"
>
OK
Some mobile devices return a slightly different response. One example is Philips 598:
AT+CMGS="+85291234567"
>
OK
If you do not want to cancel the send command, enter the body of the SMS text message that
you want to send from your computer / PC. Press Enter on the keyboard if you want to start a
new line. When finished, press Ctrl+z on the keyboard. The GSM/GPRS modem or mobile
phone then attempts to send the SMS text message to the SMSC and returns a response to the
computer / PC. Suppose the SMS text message is "It is easy to send text messages.". Below
shows what you should see in a terminal program:
AT+CMGS="+85291234567"
> It is easy to send text messages.
+CMGS: 12
OK
The value in the information response, 12, is the message reference number allocated to the
SMS text message. The final result code OK indicates the sending of the SMS text message
was successful. If the execution of the +CMGS AT command fails, the GSM/GPRS modem or
mobile phone will return either the final result code ERROR or +CMS ERROR.
+CMGS=TPDU_length<CR>SMSC_number_and_TPDU<Ctrl+z>
Before we discuss each of the parameters, let's see an example that gives you some idea of
how an actual command line should look like:
AT+CMGS=42<CR>07915892000000F001000B915892214365F7000021493A283D0795C3
F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E<Ctrl+z>
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
It can be divided into two parts. The following part is the TPDU:
01000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341ED
F27C1E3E97E72E
The TPDU is coded in hexadecimal format. Each character represents 4 bits, i.e. 1/2 octet. The
TPDU has 84 characters and so there are totally 42 octets. That's why the value assigned to
the TPDU_lengthparameter is 42.
<CR>, which represents the carriage return character, follows the TPDU_length parameter.
When the GSM/GPRS modem or mobile phone receives the carriage return character, it will
send back a prompt formed by these four characters: the carriage return character, the linefeed
character, the ">" character and the space character. If you don't understand what this means,
don't worry. This should be clear to you when you see the example in the section "Example
Demonstrating How to Use the +CMGS AT Command to Send SMS Text Messages in SMS
PDU Mode".
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
The above value can be divided into two parts, as shown below. The first part contains
information about the SMSC to be used for sending the SMS message. The second part is the
TPDU.
07915892000000F0
01000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341ED
F27C1E3E97E72E
07 91 5892000000F0
The first sub-field specifies the length in octets of the following two sub-fields. There are 14
hexadecimal digits in "915892000000F0" and each hexadecimal digit represents 4 bits. So,
there are totally 7 octets. That's why the value of the first sub-field is 0x07.
The Second Sub-field: Type of SMSC Number
The second sub-field specifies the type of the SMSC number assigned to the third sub-field.
Two values are commonly used. They are 0x81 (129 in decimal) and 0x91 (145 in decimal):
• 0x81. It means the SMSC number is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) but it is not sure whether the SMSC number is an
international number, a national number or a number of other types. For example,
suppose the SMSC number provided to you by the mobile network operator for sending
SMS messages is "+85290000000". If the value of the second sub-field is 0x81, the
SMSC number assigned to the third sub-field can be either "85290000000" (country
code included) or "90000000" (country code omitted).
• 0x91. It means the SMSC number is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) and it is an international number. For example,
suppose the SMSC number provided to you by the mobile network operator for sending
SMS messages is "+85290000000". If the value of the second sub-field is 0x91, the
SMSC number assigned to the third sub-field should be "85290000000".
The third sub-field specifies the SMSC number for sending the SMS message.
0x5892000000F0 represents the phone number +85290000000. Here's how the value
0x5892000000F0 is obtained:
1. Starting from the left, group the digits of the phone number 85290000000 into pairs, like
this: 85 29 00 00 00 0.
2. As the last group has only one digit, we add an "F" to make up a pair. The result is 85 29
00 00 00 0F.
3. Swap the digits in each pair and you will get 58 92 00 00 00 F0.
Note
It is possible to tell the GSM/GPRS modem or mobile phone to use the SMSC number specified
by the AT command +CSCA (command name in text: Service Centre Address) for sending SMS
messages. Just assign the value 0x00 to the first sub-field and omit the second and third sub-
fields, i.e. the SMSC part becomes:
00
The first sub-field is the first octet of the TPDU. It tells the GSM/GPRS modem or mobile phone
several things:
The second sub-field specifies the message reference number. It is an integer in the range from
0 to 255. The value 0x00 tells the GSM/GPRS modem or mobile phone to assign a message
reference number to the SMS message automatically.
The third sub-field specifies the length in digits of the destination phone number. The destination
phone number specified in the fifth sub-field is "+85291234567", which has 11 digits. Thus, the
value of the third sub-field is 0x0B (i.e. 11 in decimal).
The fourth sub-field specifies the type of the destination phone number assigned to the fifth sub-
field. Two values are commonly used. They are 0x81 (129 in decimal) and 0x91 (145 in
decimal):
• 0x81. It means the destination phone number is formatted using the typical ISDN /
telephony numbering plan (ITU E.164/E.163) but it is not sure whether the destination
phone number is an international number, a national number or a number of other types.
For example, suppose you want to send an SMS message to the phone number
"+85291234567". If the value of the fourth sub-field is 0x81, the destination phone
number assigned to the fifth sub-field can be either "85291234567" (country code
included) or "91234567" (country code omitted).
• 0x91. It means the destination phone number is formatted using the typical ISDN /
telephony numbering plan (ITU E.164/E.163) and it is an international number. For
example, suppose you want to send an SMS message to the phone number
"+85291234567". If the value of the fourth sub-field is 0x91, the destination phone
number assigned to the fifth sub-field should be "85291234567".
The fifth sub-field specifies the destination phone number. The value 0x5892214365F7
represents the phone number +85291234567. Here's how the value 0x5892214365F7 is
obtained:
• Starting from the left, group the digits of the phone number 85291234567 into pairs, like
this: 85 29 12 34 56 7.
• As the last group has only one digit, we add an "F" to make up a pair. The result is 85 29
12 34 56 7F.
• Swap the digits in each pair and you will get 58 92 21 43 65 F7.
The sixth sub-field specifies the protocol identifier. Its value should be 0x00 for normal cases.
The seventh sub-field specifies the data coding scheme. With 0x00, we inform the GSM/GPRS
modem or mobile phone that the text in the SMS message body is encoded according to the
"GSM 7-bit default alphabet" text coding scheme.
The eighth sub-field specifies the length of the SMS message body in septets (1 septet = 7 bits).
The value 0x21 means there are 33 septets (or characters, since each character is represented
by 7 bits according to the "GSM 7-bit default alphabet" text coding scheme) in the SMS
message body.
• Encode the SMS text message "It is easy to send text messages." according to the
character set "GSM 7-bit default alphabet". For example, 0x49 is used to represent the
first character "I" in the SMS text message, 0x74 is used to represent the second
character "t", etc. To find the code representing a certain character, see "Appendix: GSM
7-bit Default Alphabet Table (with Character Codes of ISO 8859 Latin 1)" of this SMS
tutorial.
After encoding, the SMS text message "It is easy to send text messages." becomes:
49 74 20 69 73 20 65 61 73 79 20 74 6F 20 73 65 6E 64 20 74 65 78
74 20 6D 65 73 73 61 67 65 73 2E
• With the character set "GSM 7-bit default alphabet", each character is represented by 7
bits. If the SMS text message is encoded as above, 1 bit is wasted in every octet. To
prevent this from happening, the SMS specification requires us to pack the 7-bit
characters in octets. The packing process is described below:
o The binary representation of the first character is 1001001. Since the most
significant bit of the first octet is unused, we fill it by the least significant bit of the
second character, which is 0. (The binary representation of the second character
is 1110100.) As a result, the first octet contains the binary value 01001001, which
is 0x49 in hexadecimal format.
o As the least significant bit of the second character has been moved to the first
octet, the second octet now contains the binary value 111010 and the two bits at
the leftmost position of the second octet is unused. We fill them by the two least
significant bits of the third character, which are both 0. (The binary representation
of the third character is 0100000.) As a result, the second octet
contains 00111010, which is 0x3A in hexadecimal format.
o Similarly, since the two least significant bits of the third character have been
moved to the second octet, the third octet now contains the binary value 01000
and the three bits at the leftmost position of the third octet is unused. So, we fill
them by the three least significant bits of the fourth character, which are 0, 0 and
1. (The binary representation of the fourth character is 1101001.) Now the third
octet contains the binary value 00101000, which is 0x28 in hexadecimal format.
o The packing process continues. This is illustrated in the following table.
Octet 1 0 1 0 0 1 0 0 1 = 0x49
Octet 2 0 0 1 1 1 0 1 0 = 0x3A
Octet 3 0 0 1 0 1 0 0 0 = 0x28
Octet 4 0 0 1 1 1 1 0 1 = 0x3D
Octet 5 0 0 0 0 0 1 1 1 = 0x07
Octet 6 1 0 0 1 0 1 0 1 = 0x95
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Octet 7 1 1 0 0 0 0 1 1 = 0xC3
Octet 8 1 1 1 1 0 0 1 1 = 0xF3
Octet 9 0 0 1 1 1 1 0 0 = 0x3C
Octet 10 1 0 0 0 1 0 0 0 = 0x88
Octet 11 1 1 1 1 1 1 1 0 = 0xFE
Octet 12 0 0 0 0 0 1 1 0 = 0x06
Octet 13 1 1 0 0 1 1 0 1 = 0xCD
Octet 14 1 1 0 0 1 0 1 1 = 0xCB
Octet 15 0 1 1 0 1 1 1 0 = 0x6E
Octet 16 0 0 1 1 0 0 1 0 = 0x32
Octet 17 1 0 0 0 1 0 0 0 = 0x88
Octet 18 0 1 0 1 1 1 1 0 = 0x5E
Octet 19 1 1 0 0 0 1 1 0 = 0xC6
Octet 20 1 1 0 1 0 0 1 1 = 0xD3
Octet 21 0 1 0 0 0 0 0 1 = 0x41
Octet 22 1 1 1 0 1 1 0 1 = 0xED
Octet 23 1 1 1 1 0 0 1 0 = 0xF2
Octet 24 0 1 1 1 1 1 0 0 = 0x7C
Octet 25 0 0 0 1 1 1 1 0 = 0x1E
Octet 26 0 0 1 1 1 1 1 0 = 0x3E
Octet 27 1 0 0 1 0 1 1 1 = 0x97
Octet 28 1 1 1 0 0 1 1 1 = 0xE7
Octet 29 0 0 1 0 1 1 1 0 = 0x2E
+CMGS: message_reference[,SMS-SUBMIT-REPORT_TPDU]
The message_reference Field
The first field of the information response of the +CMGS AT command, message_reference,
contains an integer in the range from 0 to 255. This field tells you the reference number that was
allocated to your SMS message.
The second field of the information response of the +CMGS AT command, SMS-SUBMIT-
REPORT_TPDU, contains a TPDU of the type SMS-SUBMIT-REPORT in hexadecimal format.
It carries a positive submission report returned from the SMSC. It acknowledges the
GSM/GPRS modem or mobile phone that the submission of the SMS message to the SMSC
was successful. The value of theSMS-SUBMIT-REPORT_TPDU field is a string and so it is
always enclosed in quotes.
Instructing the GSM/GPRS Modem or Mobile Phone to Operate in SMS PDU Mode
First, instruct the GSM/GPRS modem or mobile phone to operate in SMS PDU mode by
entering the command line "AT+CMGF=0" in a terminal program (for example, HyperTerminal in
Microsoft Windows). Below shows the response returned from Nokia 6021 to HyperTerminal
after the execution of the command line "AT+CMGF=0":
AT+CMGF=0
OK
The final result code OK indicates the +CMGF AT command was executed successfully. If the
final result code ERROR is returned, it is likely that the GSM/GPRS modem or mobile phone
does not support SMS PDU mode. To check whether the GSM/GPRS modem or mobile phone
supports SMS PDU mode, enter the command line "AT+CMGF=?" in the terminal program.
Here is the response returned from Nokia 6021 to HyperTerminal:
AT+CMGF=?
+CMGF: (0,1)
OK
The values in the parentheses indicate the modes that the GSM/GPRS modem or mobile phone
can operate in. The value 0 represents SMS PDU mode and the value 1 represents SMS text
mode. From the above response, we know that Nokia 6021 can operate in either SMS PDU
mode or SMS text mode. See the section titled "Selecting the Operating Mode (AT+CMGF)" of
this SMS tutorial if you want to learn further details about the +CMGF AT command.
(Optional in SMS PDU Mode) Setting the SMSC Number to be Used to Send SMS Text
Messages
Second, set the SMSC number to be used to send SMS text messages by the AT command
+CSCA (command name in text: Service Centre Address). Usually the default setting is correct
and you do not need to make any changes. In SMS PDU mode, you can skip this step since you
can pass the SMSC number to the +CMGS AT command as a parameter. This is different from
SMS text mode, in which the only way to set the SMSC number for sending SMS text messages
is by using the +CSCA AT command.
Below demonstrates how to use the +CSCA AT command to set "+85290000000" as the SMSC
number:
AT+CSCA="+85290000000"
OK
Detailed information about the +CSCA AT command can be found in the "Setting or Reading
the Service Center Address / SMSC Address (AT+CSCA)" section of this SMS tutorial.
Third, use the +CMGS AT command to send a text message to the SMSC. Suppose you want
to send the text message "It is easy to send text messages." to the mobile phone number
+85291234567 through the SMS center at +85290000000, the hexadecimal sequence to be
passed to the +CMGS AT command should be:
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E3
2885EC6D341EDF27C1E3E97E72E
and the length of the SMS-SUBMIT TPDU embedded in the hexadecimal sequence is 42 octets.
We have discussed how to obtain these values in previous sections and so we will not talk
about them again here.
Now pass the length of the SMS-SUBMIT TPDU to the +CMGS AT command by entering the
following command line in a terminal program:
AT+CMGS=42
Then, press the Enter key of the keyboard to send a carriage return character to the
GSM/GPRS modem or mobile phone. The GSM/GPRS modem or mobile phone will send back
a prompt formed by four characters. They are the carriage return character, the linefeed
character, the ">" character and the space character. If all characters are to be displayed, the
characters you have sent to and received from the GSM/GPRS modem or mobile phone so far
are:
AT+CMGS=42<CR>
<CR><LF>><Space>
However, the carriage return character and linefeed character have special meanings to a
terminal program. When a terminal program sees a carriage return character, it moves the
cursor to the beginning of the current line. When it sees a linefeed character, it moves the
cursor to the same position on the next line. So, here is what you will actually see in a terminal
program such as HyperTerminal:
AT+CMGS=42
>
If you want to cancel the send command at this point, press the Esc key on the keyboard. The
GSM/GPRS modem or mobile phone will then return the OK final result code. Here shows the
response returned from Nokia 6021 (or Sony Ericsson T68i):
AT+CMGS=42
>
OK
Some mobile devices return a slightly different response. One example is Philips 598:
AT+CMGS=42
>
OK
If you do not want to cancel the send command, enter the hexadecimal sequence containing the
SMS text message that you want to send from your computer / PC. When finished, press Ctrl+z
on the keyboard. The GSM/GPRS modem or mobile phone then attempts to send the SMS text
message to the SMSC and returns a response to the computer / PC. Below shows what you
should see in a terminal program:
AT+CMGS=42
>
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
+CMGS: 12
OK
The value in the information response, 12, is the message reference number allocated to the
SMS text message by the GSM/GPRS modem or mobile phone. The final result code OK
indicates the sending of the SMS text message was successful. If the execution of the +CMGS
AT command fails, the GSM/GPRS modem or mobile phone will return either the final result
code ERROR or +CMS ERROR.
25.8. Syntax of the +CMSS AT Command in SMS Text Mode and PDU
Mode
Unlike +CMGS, the syntax of the +CMSS AT command is the same in both SMS text mode and
PDU mode. Below shows the syntax of the +CMSS AT command: (Optional parameters are
enclosed in square brackets.)
+CMSS=index[,address[,address_type]]
Before we discuss each of the parameters, let's see an example that gives you some idea of
how an actual command line should look like:
AT+CMSS=5,"+85291234567",145
The first parameter of the +CMSS AT command, index, specifies the location of the SMS
message in the message storage area.
The second parameter of the +CMSS AT command, address, specifies the destination address
to send the SMS message to. Usually it is a mobile number formatted using the typical ISDN /
telephony numbering plan (ITU E.164/E.163). For example, "+85291234567", "91234567", etc.
Note that the value passed to the address parameter should be a string, i.e. it should be
enclosed in double quotes.
The address parameter is optional and it can be omitted. If you do so, the +CMSS AT command
will use the address stored in the SMS message header as the destination address.
The third parameter of the +CMSS AT command, address_type, specifies the type of the
address assigned to the address parameter. Two values are commonly used. They are 129 and
145:
• 129. It means the value of address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) but it is not sure whether the value of address is an
international number, a national number or a number of other types. Example
addresses: "85291234567", "91234567".
• 145. It means the value of address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) and it is an international number. Example address:
"+85291234567".
• 129 if the value of address does not start with a "+" character. For example,
"85291234567".
• 145 if the value of address starts with a "+" character. For example, "+85291234567".
25.9. Format of the Information Response of the +CMSS AT Command
in SMS Text Mode and PDU Mode
If the GSM/GPRS modem or mobile phone sends the SMS message successfully, it will return
an information response to the computer / PC. The format of the +CMSS information response
in SMS text mode and that in SMS PDU mode differ by a single parameter.
In SMS text mode, the information response of the +CMSS AT command has the following
format: (Optional fields are enclosed in square brackets.)
+CMSS: message_reference[,service_center_time_stamp]
Here is an example that gives you some idea of how an actual information response should look
like:
+CMSS: 5,"07/02/05,08:30:45+32"
In SMS PDU mode, the information response of the +CMSS AT command has the following
format: (Optional fields are enclosed in square brackets.)
+CMSS: message_reference[,SMS-SUBMIT-REPORT_TPDU]
The first field of the information response of the +CMSS AT command, message_reference,
contains an integer in the range from 0 to 255. It is a reference number allocated by the
GSM/GPRS modem or mobile phone to the SMS message sent.
In SMS text mode, the second field of the information response of the +CMSS AT command
isservice_center_time_stamp. It contains a string that indicates the time and date at which the
SMS message arrived at the service center (i.e. SMSC). The time stamp format is
"yy/MM/dd,hh:mm:ss±zz", where yy = year, MM = month, dd = day, hh = hour, mm = minute, ss
= second, zz = time zone. Note: the unit of time zone is a quarter of an hour.
For example, "07/02/05,08:30:45+32" represents 5 February 2007, 8:30:45 GMT+8 hours. "+32"
means GMT+8 hours, since 32 quarters of an hour = 8 hours.
Note that service_center_time_stamp is an optional field. A GSM/GPRS modem or mobile
phone includes this field in the information response only if the messaging service value set by
the AT command +CSMS (command name in text: Select Message Service) is 1 and the mobile
network supports the use of this messaging service value. By default the messaging service
value is 0. Usually this is the value to be used and the service_center_time_stamp field is not
shown.
In SMS PDU mode, the second field of the information response of the +CMSS AT command
is SMS-SUBMIT-REPORT_TPDU. It contains a TPDU of the type SMS-SUBMIT-REPORT in
hexadecimal format. It carries a positive submission report returned from the SMSC. It
acknowledges the GSM/GPRS modem or mobile phone that the submission of the SMS
message to the SMSC was successful. The value of the SMS-SUBMIT-REPORT_TPDU field is
a string and so it is always enclosed in quotes.
To understand better, let's consider the following example. Suppose we use the AT command
+CSCA to change the SMSC number to +85290000000, like this:
AT+CSCA="+85290000000"
Then we use the AT command +CMGW to write the text message "Sending text messages is
easy." to the message storage area. In SMS text mode, the command line should be something
like this:
After that, we use the AT command +CSCA to change the SMSC number to +85291111111:
AT+CSCA="+85291111111"
At this point, if we use the +CMSS AT command to send the text message out, the GSM/GPRS
modem or mobile phone will perform the task using the SMSC number +85290000000, not the
current number +85291111111.
Once an SMS message has been written to the message storage area, there is no way to
change the SMSC number saved with it via AT commands. But you can always create a new
SMS message with the same message body but with a different SMSC number.
Note: It is possible that the command behavior on your mobile device is slightly different from
what was described above. So, you may want to do something similar to the above example to
find out the exact command behavior on your mobile device.
Note that once an SMS message has been written to the message storage area, there is no
way to change the SMSC number saved with it via AT commands. But you can always create a
new SMS message with the same message body but with a different SMSC number.
The value of the SMSC_number_and_TPDU parameter can be divided into two parts: the
SMSC part and TPDU part. Following is an example that gives you some idea of how an actual
value of theSMSC_number_and_TPDU parameter should look like. The SMSC part is displayed
in bold type.
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
To understand better, let's consider the following example. Suppose we use the AT command
+CSCA to change the SMSC number to +85290000000, like this:
AT+CSCA="+85290000000"
Then we use the AT command +CMGW to write the text message "It is easy to send text
messages." to the message storage area. In SMS PDU mode, the command line should be
something like this: (The SMSC part is displayed in bold type.)
AT+CMGW=42<CR>0001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E<Ctrl+z>
After that, we use the AT command +CMGR (command line in text: Read Message) to read the
SMS text message. The information response returned is shown below. (The SMSC part is
displayed in bold type.)
+CMGR: 2,,42
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
As you can see, the hexadecimal value returned is different from what we assigned to the AT
command +CMGW. The old SMSC part "00" was replaced by the new SMSC part
"07915892000000F0", which specifies the SMSC number +85290000000.
More Details
More details about the SMSC_number_and_TPDU parameter of the AT command +CMGW can
be found from the section "Syntax of the +CMGW AT Command in SMS PDU Mode" of this
SMS tutorial.
Note
Mobile devices such as Nokia 6021 and Philips 598 work in the way described above. However,
it is possible that the command behavior on your mobile device is slightly different from what
was described. So, you may want to do something similar to the above example to find out the
exact command behavior on your mobile device.
One mobile phone that has a different command behavior is Sony Ericsson T68i. The difference
is the time at which the old SMSC part "00" is replaced by the newly generated SMSC part. On
Sony Ericsson T68i, the replacement is done when the +CMSS AT command is executed. To
understand better, let's consider the following example. Suppose we use the AT command
+CSCA to change the SMSC number to +85290000000, like this:
AT+CSCA="+85290000000"
Then we use the AT command +CMGW to write the text message "It is easy to send text
messages." to the message storage area. In SMS PDU mode, the command line should be
something like this: (The SMSC part is displayed in bold type.)
AT+CMGW=42<CR>0001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E<Ctrl+z>
After that, we use the AT command +CMGR to read the SMS text message. The information
response returned is shown below. (The SMSC part is displayed in bold type.)
+CMGR: 2,,42
0001440B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341
EDF27C1E3E97E72E
As you can see, the SMSC part is the same as the one we assigned to the +CMGW AT
command.
Now use the +CMSS AT command to send the text message out. Then use the AT command
+CMGR to read the SMS text message again. This time you should find that the SMSC part
was changed to "07915892000000F0", which specifies the SMSC number +85290000000.
+CMGR: 2,,42
07915892000000F001440B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
Here is an example for illustration. Suppose there is an SMS text message "It is easy to send
text messages." located at index 5 of the message storage area. To read the SMSC number
saved with it, enter the command line "AT+CSDH=1" and then "AT+CMGR=5". The result
shown in a terminal program such as HyperTerminal of Microsoft Windows should be something
like this:
AT+CSDH=1
OK
AT+CMGR=5
+CMGR: "STO
UNSENT","+85291234567",,145,17,0,0,167,"+85290000000",145,30
It is easy to send text messages.
OK
The value of the ninth field of the +CMGR information response, i.e. +85290000000, is the
SMSC number saved with the SMS text message.
Here is an example for illustration. Suppose there is an SMS text message "It is easy to send
text messages." located at index 5 of the message storage area. To read the SMSC number
saved with it, enter the command line "AT+CMGR=5". In SMS PDU mode, the result shown in a
terminal program such as HyperTerminal of Microsoft Windows should be something like this:
AT+CMGR=5
+CMGR: 2,,42
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
OK
The hexadecimal sequence of the fourth field of the +CMGR information response is:
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB
6E32885EC6D341EDF27C1E3E97E72E
It can be divided into two parts: the SMSC part and TPDU part. Here is the SMSC part:
07915892000000F0
The SMSC part can be further divided into three sub-fields, like this:
07 91 5892000000F0
The value of the first sub-field 0x07 tells us that the second and third sub-fields consist of 7
octets totally. The value of the second sub-field 0x91 indicates the SMSC number encoded in
the third sub-field is in the typical international numbering format. The value of the third sub-field
0x5892000000F0 tells us the SMSC number saved with the SMS text message. To decode the
hexadecimal value, group the digits into pairs, like this: 58 92 00 00 00 F0. Then swap the digits
in each pair and you will get 85 29 00 00 00 0F. Remove the last "F", because it was placed
there to fill the empty bits of the last octet and it is not part of the SMSC number. After that,
combine the digits and you will get the SMSC number +85290000000.
More information about the sub-fields is available in the section "The SMSC Part" of this SMS
tutorial.
Selecting the Message Storage Area to Write Text Messages to and Send Text Messages
from
First, use the +CPMS AT command (command name in text: Preferred Message Storage) to
select the message storage area to write text messages to (+CMGW AT command) and send
text messages from (+CMSS AT command). For example, to use the message storage area in
the SIM card for writing and sending SMS text messages, assign the string value "SM" to the
second parameter of the +CPMS AT command, like this:
AT+CPMS="ME","SM"
The first parameter of the +CPMS AT command is used to select the message storage area for
reading and deleting SMS messages. It has no use to us here. So, it does not matter what value
is assigned to the first parameter.
Now press the Enter key on the keyboard and you should see something similar to this:
AT+CPMS="ME","SM"
+CPMS: 2,150,2,10,4,160
OK
Detailed information about the +CPMS AT command is available in the "Preferred Message
Storage (AT+CPMS)" section of this SMS tutorial.
Second, use the AT command +CSCA (command name in text: Service Centre Address) to set
the SMSC number to be used to send SMS text messages. Usually the default setting is correct
and you do not need to make any changes. Below demonstrates how to use the +CSCA AT
command to set "+85290000000" as the SMSC number:
AT+CSCA="+85290000000"
OK
Detailed information about the +CSCA AT command can be found in the "Setting or Reading
the Service Center Address / SMSC Address (AT+CSCA)" section of this SMS tutorial.
Third, use the +CMGW AT command (command line in text: Write Message to Memory) to write
the text message to message storage. Suppose the recipient mobile phone number is
+85291234567. If the GSM/GPRS modem or mobile phone is operating in SMS text mode, you
should enter something like this in the terminal program and press the Enter key of the
keyboard:
AT+CMGW="+85291234567"
The GSM/GPRS modem or mobile phone will return a prompt, as shown below:
AT+CMGW="+85291234567"
>
Now enter the body of the SMS text message "It is easy to send text messages." and press
Ctrl+z on the keyboard to finish. You should see something like this in the terminal program:
AT+CMGW="+85291234567"
> It is easy to send text messages.
+CMGW: 3
OK
The value 3 in the +CMGW information response is the index that specifies the location where
the text message is stored in the message storage area. Later, we have to use this index to tell
the +CMSS AT command which text message should be sent.
If the GSM/GPRS modem or mobile phone is operating in SMS PDU mode, here's what you
should type and see in the terminal program:
AT+CMGW=42
>
0001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341
EDF27C1E3E97E72E
+CMGW: 3
OK
For further details the +CMGW AT command, please refer to the earlier section "Writing SMS
Messages to Memory / Message Storage (AT+CMGW)" of this SMS tutorial.
Fourth, specify the index "3" to the +CMSS AT command to send the text message out:
AT+CMSS=3
+CMSS: 20
OK
"20" is the message reference number allocated by the GSM/GPRS modem or mobile phone to
the text message. The final result code OK indicates the text message was sent to the SMSC
successfully. If the execution of the AT command +CMSS fails, the GSM/GPRS modem or
mobile phone will return either the final result code ERROR or +CMS ERROR.
In the above example, the address parameter of the AT command +CMSS is omitted. Thus, the
mobile phone number stored with the SMS text message (i.e. +85291234567) will be used as
the destination address. Suppose you want to send the text message to another mobile phone
number, say +85298765432, you should assign "+85298765432" to the address parameter of
+CMSS, as shown below:
AT+CMSS=3,"+85298765432"
+CMSS: 21
OK
Following is an example for illustrating the difference between +CMGR and +CMGL. Suppose
you want to use your computer / PC to read a text message from the message storage area and
you know the index at which the SMS text message is located. In this case, you should use the
+CMGR AT command. Here is the command line to be typed (assume the SMS text message is
stored at index 3):
AT+CMGR=3
The GSM/GPRS modem or mobile phone should return something like this:
OK
Suppose you are now in another situation. You want to use your computer / PC to retrieve all
inbound SMS messages that have not been read before. In this case, you should use the
+CMGL AT command. In SMS text mode, the command line to be used should be:
AT+CMGL="REC UNREAD"
The GSM/GPRS modem or mobile phone should return something like this:
OK
The +CMGL AT command can also be used to read all SMS messages stored in the message
storage area. To do so in SMS text mode, the command line should be:
AT+CMGL="ALL"
This time the response of the GSM/GPRS modem or mobile phone should be something like
this:
OK
As you can see above, the +CMGR AT command can only be used to read one SMS message
at a time, while the +CMGL AT command can be used to read multiple SMS messages at a
time.
Another difference between the AT commands +CMGR and +CMGL is that +CMGR can be
used to retrieve more message details than +CMGL when the GSM/GPRS modem or mobile
phone is operating in SMS text mode. Here are the message details that can be retrieved by the
+CMGR AT command in SMS text mode:
• Status of the SMS message ("received unread", "received read", "stored unsent", "stored
sent", etc).
• Originator/recipient phone number stored in the SMS message header and the type of
the phone number.
• Text associated to the originator/recipient phone number in the phonebook.
• Time and date at which the SMS message arrived at the SMSC (available to incoming
SMS messages only).
• The first octet (1 octet = 8 bits) of the TPDU (Transport Protocol Data Unit) of the SMS
message.
• The protocol identifier value in the TPDU of the SMS message.
• The data coding scheme value in the TPDU of the SMS message.
• SMSC number stored with the SMS message and the type of the SMSC number.
• Validity period of the SMS message (available to outgoing SMS messages only).
• Body of the SMS message and its length.
Here are the message details that can be retrieved by the +CMGL AT command in SMS text
mode:
• The index specifying the location of the SMS message in the message storage area.
• Status of the SMS message ("received unread", "received read", "stored unsent", "stored
sent", etc).
• Originator/recipient phone number stored in the SMS message header and the type of
the phone number.
• Text associated to the originator/recipient phone number in the phonebook.
• Time and date at which the SMS message arrived at the SMSC (available to incoming
SMS messages only).
• Body of the SMS message and its length.
If you compare the above two lists, you will find that the following message details can only be
retrieved by the +CMGR AT command but not the +CMGL AT command:
Note: If the GSM/GPRS modem or mobile phone is operating in SMS PDU mode, the message
details that can be retrieved by +CMGR and +CMGL are the same.
Number of SMS messages +CMGR returns one SMS +CMGL returns one or more SMS
returned message. messages.
In SMS text mode, you can retrieve the following information about an SMS message with the
AT command +CMGR:
• Status of the SMS message ("received unread", "received read", "stored unsent", "stored
sent", etc).
• Originator/recipient phone number stored in the SMS message header and the type of
the phone number.
• Text associated to the originator/recipient phone number in the phonebook.
• Time and date at which the SMS message arrived at the SMSC (available to incoming
SMS messages only).
• The first octet (1 octet = 8 bits) of the TPDU (Transport Protocol Data Unit) of the SMS
message.
• The protocol identifier value in the TPDU of the SMS message.
• The data coding scheme value in the TPDU of the SMS message.
• SMSC number stored with the SMS message and the type of the SMSC number.
• Validity period of the SMS message (available to outgoing SMS messages only).
• Body of the SMS message and its length.
• Status of the SMS message ("received unread", "received read", "stored unsent", "stored
sent", etc).
• Text associated to the originator/recipient phone number in the phonebook.
• SMSC number stored with the SMS message and the type of the SMSC number.
• TPDU of the SMS message and its length.
After using the +CMGR AT command to read an SMS message with the "received unread"
status, the status will be changed to "received read".
The message storage area from which SMS messages are read is specified by the +CPMS AT
command (command name in text: Preferred Message Storage). Details about the +CPMS AT
command can be found in the earlier section "Preferred Message Storage (AT+CPMS)" of this
SMS tutorial.
26.2.1. Syntax of the +CMGR AT Command in SMS Text Mode
The syntax of the +CMGR AT command in SMS text mode is:
+CMGR=index
index is an integer specifying the location of the SMS message to be read from the message
storage area.
+CMGR: message_status,address,
[address_text],service_center_time_stamp[,address_type,TPDU_first_octe
t,protocol_identifier,data_coding_scheme,service_center_address,servic
e_center_address_type,sms_message_body_length]<CR><LF>sms_message_body
If the SMS message retrieved is an SMS message that you wrote to the message storage area
for sending out (i.e. outgoing SMS message), the format is: (Optional fields are enclosed in
square brackets.)
+CMGR: message_status,address,[address_text]
[,address_type,TPDU_first_octet,protocol_identifier,data_coding_scheme
,
[validity_period],service_center_address,service_center_address_type,s
ms_message_body_length]<CR><LF>sms_message_body
As you can see above, the format of the +CMGR information response for incoming SMS
messages and for outgoing SMS messages is slightly different. The differences are:
Before we discuss each of the fields that appear in the +CMGR information response, let's see
two examples that give you some idea of how an actual +CMGR information response should
look like:
+CMGR: "REC
READ","+85291234567",,"07/04/20,10:08:02+32",145,4,0,0,"+85290000000",
145,49
It is easy to read text messages via AT commands.
The first field of the information response of the +CMGR AT command, message_status, is a
string that indicates the status of the SMS message. It can be one of the following four values:
The second field of the information response of the +CMGR AT command, address, is a string
that contains the address/phone number stored in the SMS message header. If the SMS
message read is an incoming SMS message, the address field contains the originator address.
If the SMS message read is an outgoing SMS message, the address field contains the recipient
address. Usually the address field value is a phone number formatted using the typical ISDN /
telephony numbering plan (ITU E.164/E.163). For example, "+85291234567".
The third field of the information response of the +CMGR AT command, address_text, is a string
that contains the text associated to address in the phonebook. For example, if the text "Alice" is
associated to the phone number "91234567" in the phonebook, address_text will be "Alice". The
AT command +CSCS (command name in text: Select TE Character Set) can be used to specify
the character set for displaying address_text. Note that address_text is an optional field. Some
GSM/GPRS modems and mobile phones (examples: most Nokia products, including my Nokia
6021) leave this field empty.
The fourth field of the +CMGR information response for incoming SMS
messages,service_center_time_stamp, is a string that contains the time and date at which the
SMS message arrived at the service center (i.e. SMSC). The time stamp format is
"yy/MM/dd,hh:mm:ss±zz" (yy = year, MM = month, dd = day, hh = hour, mm = minute, ss =
second, zz = time zone [Note: the unit of time zone is a quarter of an hour]). For example,
"07/02/05,08:30:45+32" represents 5 February 2007, 8:30:45 GMT+8 hours. (+32 means
GMT+8 hours, since 32 quarters of an hour = 8 hours.)
Note that service_center_time_stamp is an optional field. This field is available to incoming SMS
messages but not to outgoing SMS messages since outgoing SMS messages have not gone
through an SMSC.
The fifth (fourth) field of the +CMGR information response for incoming SMS messages
(outgoing SMS messages), address_type, is an integer that indicates the type of the address
contained in the addressfield. Usually it is one of the following two values:
• 129. Meaning: The value of address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) but it is not sure whether the value of address is an
international number, a national number or a number of other types. Example
addresses: "85291234567", "91234567".
• 145. Meaning: The value of address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) and it is an international number. Example address:
"+85291234567".
Note that address_type is an optional field and it is not shown by default. The AT command
+CSDH (command name in text: Show Text Mode Parameters) can be used to control whether
the fieldaddress_type will be shown in the information response of the +CMGR AT command.
The sixth (fifth) field of the +CMGR information response for incoming SMS messages (outgoing
SMS messages), TPDU_first_octet, contains the first octet (expressed as an integer) of the
TPDU of the SMS message.
Note that TPDU_first_octet is an optional field and it is not shown by default. The AT command
+CSDH (command name in text: Show Text Mode Parameters) can be used to control whether
the fieldTPDU_first_octet will be shown in the information response of the +CMGR AT
command.
The seventh (sixth) field of the +CMGR information response for incoming SMS messages
(outgoing SMS messages), protocol_identifier, contains the value (expressed as an integer) of
the TP-Protocol-Identifier parameter in the TPDU of the SMS message.
Note that protocol_identifier is an optional field and it is not shown by default. The AT command
+CSDH (command name in text: Show Text Mode Parameters) can be used to control whether
the fieldprotocol_identifier will be shown in the information response of the +CMGR AT
command.
The eighth (seventh) field of the +CMGR information response for incoming SMS messages
(outgoing SMS messages), data_coding_scheme, contains the value (expressed as an integer)
of the TP-Data-Coding-Scheme parameter in the TPDU of the SMS message.
Note that data_coding_scheme is an optional field and it is not shown by default. The AT
command +CSDH (command name in text: Show Text Mode Parameters) can be used to
control whether the fielddata_coding_scheme will be shown in the information response of the
+CMGR AT command.
The eighth field of the +CMGR information response for outgoing SMS
messages, validity_period, contains the validity period assigned to the SMS message. There
are three possible validity period formats: relative format, absolute format and enhanced format.
To find out the format of validity_period, examine the value of the TP-Validity-Period-Format
parameter in the TPDU of the SMS message. It is located at bit 4 and bit 3 of the first octet of
the TPDU. (Note: Bit 0 is the rightmost bit.) For example, let's say the value of
the TPDU_first_octet Field is 17. Its binary representation is 00010001. As you can see, bit 4 is
1 and bit 3 is 0.
If the relative format is used (bit 4 = 1, bit 3 = 0), validity_period will be an integer in the range
from 0 to 255 that indicates the period after which the SMSC should delete the SMS message,
counted from the time at which the SMSC receives the SMS message. The validity period can
be calculated by the following formulae:
If the absolute format is used (bit 4 = 1, bit 3 =1), validity_period will be a string that contains the
time and date at which the SMSC should delete the SMS message. The time/date format is
"yy/MM/dd,hh:mm:ss±zz" (yy = year, MM = month, dd = day, hh = hour, mm = minute, ss =
second, zz = time zone [Note: the unit of time zone is a quarter of an hour]). For example,
"07/02/05,08:30:45+32" represents 5 February 2007, 8:30:45 GMT+8 hours. (+32 means
GMT+8 hours, since 32 quarters of an hour = 8 hours.)
If the enhanced format is used (bit 4 = 0, bit 3 = 1), validity_period will be a hexadecimal coded
string. Since the enhanced format is not commonly used, we do not discuss the details here.
Note that validity_period is an optional field and it is not shown by default. The AT command
+CSDH (command name in text: Show Text Mode Parameters) can be used to control whether
the fieldvalidity_period will be shown in the information response of the +CMGR AT command.
Also, note thatvalidity_period is available to outgoing SMS messages but not to incoming SMS
messages, since there is no such value stored in the headers of incoming SMS messages.
Note that service_center_address is an optional field and it is not shown by default. The AT
command +CSDH (command name in text: Show Text Mode Parameters) can be used to
control whether the fieldservice_center_address will be shown in the information response of
the +CMGR AT command.
Note that service_center_address_type is an optional field and it is not shown by default. The
AT command +CSDH (command name in text: Show Text Mode Parameters) can be used to
control whether the field service_center_address_type will be shown in the information response
of the +CMGR AT command.
Note that sms_message_body_length is an optional field and it is not shown by default. The AT
command +CSDH (command name in text: Show Text Mode Parameters) can be used to
control whether the field sms_message_body_length will be shown in the information response
of the +CMGR AT command.
The twelfth field of the information response of the +CMGR AT command, sms_message_body,
contains the body of the SMS message.
Instructing the GSM/GPRS Modem or Mobile Phone to Operate in SMS Text Mode
First, enter the command line "AT+CMGF=1" in a terminal program (for example,
HyperTerminal in Microsoft Windows) to instruct the GSM/GPRS modem or mobile phone to
operate in SMS text mode. This step is necessary because the default mode is SMS PDU
mode. Below shows the response returned from Nokia 6021 to HyperTerminal after the
execution of the command line "AT+CMGF=1":
AT+CMGF=1
OK
The final result code OK indicates the +CMGF AT command was executed successfully. If the
final result code ERROR is returned, it is likely that the GSM/GPRS modem or mobile phone
does not support SMS text mode. To check whether the GSM/GPRS modem or mobile phone
supports SMS text mode, enter the command line "AT+CMGF=?" in the terminal program. Here
is the response returned from Nokia 6021 to HyperTerminal:
AT+CMGF=?
+CMGF: (0,1)
OK
The values in the parentheses indicate the modes that the GSM/GPRS modem or mobile phone
can operate in. The value 0 represents SMS PDU mode and the value 1 represents SMS text
mode. From the above response, we know that Nokia 6021 can operate in either SMS PDU
mode or SMS text mode. See the section titled "Selecting the Operating Mode (AT+CMGF)" of
this SMS tutorial if you want to learn further details about the +CMGF AT command.
Selecting the Message Storage Area to Read SMS Text Messages from
Second, use the AT command +CPMS (command name in text: Preferred Message Storage) to
select the message storage area to read SMS text messages from. For example, to instruct the
GSM/GPRS modem or mobile phone to use the message storage area in the SIM card for the
AT command +CMGR, enter the command line 'AT+CPMS="SM"' in the terminal program. Then
press the Enter key on the keyboard and you should see something similar to this:
AT+CPMS="SM"
+CPMS: 2,10,2,10,3,160
OK
Detailed information about the +CPMS AT command is available in the "Preferred Message
Storage (AT+CPMS)" section of this SMS tutorial.
Third, you can now use the +CMGR AT command to read a text message from the message
storage area. Let's say you would like to read the text message at index 1. You should enter the
following command line in the terminal program:
AT+CMGR=1
Then press the Enter key on the keyboard and the GSM/GPRS modem or mobile phone will
execute the command line "AT+CMGR=1". If it reads the SMS text message successfully, the
result returned should look something like this:
AT+CMGR=1
+CMGR: "REC UNREAD","+85291234567",,"07/02/18,00:05:10+32"
It is easy to read text messages via AT commands.
OK
Here is a brief description of the various field values in the information response above:
• The value of the first field, "REC UNREAD", indicates the status of the text message is
"received unread", which means it is a text message received from the SMSC and it has
not been read.
• The value of the second field, "+85291234567", is the sender's phone number.
• The value of the third field should be a string that contains the text associated to the
sender's phone number "+85291234567" in the phonebook. In this example, this field is
empty. One possible reason is that the GSM/GPRS modem or mobile phone (for
example, Nokia 6021 and many other Nokia products) does not support this field.
• The value of the fourth field, "07/02/18,00:05:10+32", tells us that the SMSC received
the text message at 00:05:10 (GMT+8) on 18 Feb 2007. (Don't forget the unit of time
zone is a quarter of an hour. Since 32 quarters of an hour = 8 hours, "+32" means
GMT+8 hours.)
• The value of the fifth field, "It is easy to read text messages via AT commands.", is the
body of the SMS message.
The final result code OK indicates the SMS text message was read from the message storage
area successfully. If the execution of the +CMGR AT command fails, the GSM/GPRS modem or
mobile phone will return either the final result code ERROR or +CMS ERROR.
After using the +CMGR AT command to read the SMS text message, its status was changed
from "received unread" to "received read". So, if the command line "AT+CMGR=1" is executed
again, you will see a slightly different result (note the part highlighted in bold type):
AT+CMGR=1
+CMGR: "REC READ","+85291234567",,"07/02/18,00:05:10+32"
It is easy to read text messages via AT commands.
OK
The SMS text message "It is easy to read text messages via AT commands." is an incoming
text message. If the SMS text message retrieved is an outgoing text message, the format of the
+CMGR information response will be different. To see the differences, first write a new outgoing
text message to the message storage area using the +CMGW AT command (command name in
text: Write Message to Memory), like this:
AT+CMGW="+85291234567"
> A simple example of SMS text messaging.
+CMGW: 2
OK
(Note: Make sure the same message storage area is selected for writing and reading text
messages. See "Selecting the Message Storage Areas to be Used for SMS Reading, Writing,
Deleting, Sending or Receiving" if you do not know how this can be done.)
AT+CMGR=1;+CMGR=2
+CMGR: "REC READ","+85291234567",,"07/02/18,00:05:10+32"
It is easy to read text messages via AT commands.
OK
As you can see, the +CMGR information response of the incoming text message contains the
service center timestamp field, while that of the outgoing text message does not.
As mentioned in the earlier section "Format of the Information Response of the +CMGR AT
Command in SMS Text Mode" of this SMS tutorial, eight optional fields are not shown in the
information response of the +CMGR AT command by default. They
are address_type, TPDU_first_octet, protocol_identifier,data_coding_scheme, validity_period, s
ervice_center_address, service_center_address_type andsms_message_body_length. To show
these optional fields, you have to specify the value 1 to the +CSDH AT command (command
name in text: Show Text Mode Parameters), like this:
AT+CSDH=1
OK
Now send the command line "AT+CMGR=1;+CMGR=2" to the GSM/GPRS modem or mobile
phone again and you should obtain the following result:
AT+CMGR=1;+CMGR=2
+CMGR: "REC
READ","+85291234567",,"07/02/18,00:05:10+32",145,4,0,0,"+85290000000",
145,49
It is easy to read text messages via AT commands.
+CMGR: "STO
UNSENT","+85291234567",,145,17,0,0,167,"+85290000000",145,39
A simple example of SMS text messaging.
OK
Suppose there is no message located at index 3 of the message storage area. If you specify the
index 3 to the +CMGR AT command, the GSM/GPRS modem or mobile phone will return +CMS
error 321 (which means the index is invalid), like this:
AT+CMGR=3
+CMS ERROR: 321
+CMGR=index
In the above line, index is an integer specifying the location of the SMS message to be read
from the message storage area.
+CMGR: message_status,
[address_text],TPDU_length<CR><LF>SMSC_number_and_TPDU
Before we discuss each of the fields that appear in the +CMGR information response, let's see
an example that gives you some idea of how an actual +CMGR information response should
look like:
+CMGR: 0,,62
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F3
3C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
OK
The first field of the information response of the +CMGR AT command, message_status, is an
integer that indicates the status of the SMS message. It can be one of the following four values:
The second field of the information response of the +CMGR AT command, address_text, is a
string that contains the text associated to address in the phonebook, where address is the
phone number encoded in the TPDU of the SMSC_number_and_TPDU field. For example, if
the phone number encoded in the TPDU is "91234567" and the text "Alice" is associated to the
phone number "91234567" in the phonebook, address_text will be "Alice". The AT command
+CSCS (command name in text: Select TE Character Set) can be used to specify the character
set for displaying address_text.
Note that address_text is an optional field. Some GSM/GPRS modems and mobile phones
(examples: most Nokia products, including my Nokia 6021) leave this field empty.
The third field of the information response of the +CMGR AT command, TPDU_length, is an
integer that indicates the length (in octets. 1 octet = 8 bits) of the TPDU contained in
the SMSC_number_and_TPDUfield. In the earlier example command line, the value of
the SMSC_number_and_TPDU field is:
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F3
3C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
It can be divided into two parts. The following part is the TPDU:
040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132
885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
The TPDU is coded in hexadecimal format. Each character represents 4 bits, i.e. 1/2 octet. The
TPDU has 124 characters and so there are totally 62 octets. That's why the value of
the TPDU_length field is 62.
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F3
3C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
The above value can be divided into two parts, as shown below. The first part contains
information about the SMSC. The second part is the TPDU.
07915892000000F0
040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132
885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
The format of the SMSC_number_and_TPDU field value of an outgoing SMS message is the
same as that mentioned in the earlier section "Some Explanation about the Coding of the
SMSC_number_and_TPDU Parameter Value of the +CMGS AT Command". Thus, we will not
discuss about it again here. In the following sections, we assume the SMS message retrieved
by the +CMGR AT command is an incoming SMS message and the TPDU is of the type SMS-
DELIVER.
The first sub-field specifies the length in octets of the following two sub-fields. There are 14
hexadecimal digits in "915892000000F0" and each hexadecimal digit represents 4 bits, i.e. 1/2
octet. So, there are totally 7 octets. That's why the value of the first sub-field is 0x07.
The second sub-field specifies the type of the SMSC number assigned to the third sub-field.
Two values are commonly used. They are 0x81 (129 in decimal) and 0x91 (145 in decimal):
• 0x81. It means the SMSC number is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) but it is not sure whether the SMSC number is an
international number, a national number or a number of other types. For example,
suppose the SMSC number from which the SMS message was received is
"+85290000000". If the value of the second sub-field is 0x81, the SMSC number
assigned to the third sub-field may be "85290000000" (country code included) or
"90000000" (country code omitted).
• 0x91. It means the SMSC number is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) and it is an international number. For example,
suppose the SMSC number from which the SMS message was received is
"+85290000000". If the value of the second sub-field is 0x91, the SMSC number
assigned to the third sub-field should be "85290000000".
The third sub-field specifies the SMSC number from which the SMS message was received.
0x5892000000F0 represents the phone number +85290000000. Here's how the value
0x5892000000F0 is obtained:
1. Starting from the left, group the digits of the phone number 85290000000 into pairs, like
this: 85 29 00 00 00 0.
2. As the last group has only one digit, we add an "F" to make up a pair. The result is 85 29
00 00 00 0F.
3. Swap the digits in each pair and you will get 58 92 00 00 00 F0.
The first sub-field is the first octet of the TPDU. It tells us several things:
The second sub-field specifies the length in digits of the sender phone number. The sender
phone number specified in the fourth sub-field is "+85291234567", which has 11 digits. Thus,
the value of the second sub-field is 0x0B (i.e. 11 in decimal).
The third sub-field specifies the type of the sender phone number assigned to the fourth sub-
field. Two values are commonly used. They are 0x81 (129 in decimal) and 0x91 (145 in
decimal):
• 0x81. It means the sender phone number is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) but it is not sure whether the sender phone number is
an international number, a national number or a number of other types. For example,
suppose there is an incoming SMS message that was originated from the phone number
"+85291234567". If the value of the third sub-field is 0x81, the sender phone number
assigned to the fourth sub-field may be "85291234567" (country code included) or
"91234567" (country code omitted).
• 0x91. It means the sender phone number is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) and it is an international number. For example,
suppose there is an incoming SMS message that was originated from the phone number
"+85291234567". If the value of the third sub-field is 0x91, the sender phone number
assigned to the fourth sub-field should be "85291234567".
The Fourth Sub-field: Sender Phone Number
The fourth sub-field specifies the sender phone number. The value 0x5892214365F7 represents
the phone number +85291234567. Here's how the value 0x5892214365F7 is obtained:
• Starting from the left, group the digits of the phone number 85291234567 into pairs, like
this: 85 29 12 34 56 7.
• As the last group has only one digit, we add an "F" to make up a pair. The result is 85 29
12 34 56 7F.
• Swap the digits in each pair and you will get 58 92 21 43 65 F7.
The fifth sub-field specifies the protocol identifier. Its value should be 0x00 for normal cases.
The sixth sub-field specifies the data coding scheme. The value 0x00 indicates that the text in
the SMS message body is encoded according to the "GSM 7-bit default alphabet" text coding
scheme.
The seventh sub-field specifies the time and data at which the SMS message arrived at the
service center (i.e. SMSC). The value 0x70402132522423 represents 12 April 2007, 23:25:42
GMT+8 hours. Here's how the value 0x70402132522423 is decoded:
• Starting from the left, group the digits of the value 0x70402132522423 into pairs, like
this: 70 40 21 32 52 24 23.
• Swap the digits in each pair and you will get 07 04 12 23 25 42 32. Starting from the left,
the values represent year, month, day, hour, minute, second and time zone respectively.
Note that the unit of time zone is a quarter of an hour.
The decoding of the time zone field requires a bit more explanation. The binary representation
of the hexadecimal value 0x32 is 00110010. It can be divided into three parts, like this:
0 011 0010
The first part represents the plus-minus sign. If the value of the first part is 0, the sign is "+". If it
is 1, the sign is "-". The second part represents the most significant digit of the time zone. "011"
is equal to 3 in decimal. The third part represents the least significant digit of the time zone.
"0010" is equal to 2 in decimal. Overall, "00110010" represents GMT+32 quarters of an hour =
GMT+8 hours.
The eighth sub-field specifies the length of the SMS message body in septets (1 septet = 7 bits).
The value 0x31 means there are 49 septets (or characters, since each character is represented
by 7 bits according to the "GSM 7-bit default alphabet" text coding scheme) in the SMS
message body.
The ninth sub-field specifies the SMS message body. The value below:
0x493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A52
41E377BB1D7693E72E
represents the text message "It is easy to read text messages via AT commands.". Below
shows how to convert the hexadecimal value to text:
• Group the digits of the hexadecimal value into pairs, as shown below. Each pair
represents one octet of data.
49 3A 28 3D 07 95 C3 F3 3C 88 FE 06 C9 CB 61 32 88 5E C6 D3 41 ED
F2 7C 1E 3E 97 E7 20 7B 3A 0C 0A 52 41 E3 77 BB 1D 76 93 E7 2E
• The binary representation of the first octet is 01001001. With the character set "GSM 7-
bit default alphabet", each character is represented by 7 bits. The seven least significant
bits, 1001001, represent the first character. The hexadecimal value of 1001001 is 0x49,
which represents the character "I" according to the character set "GSM 7-bit default
alphabet". To find out which character is represented by a certain hexadecimal code,
see "Appendix: GSM 7-bit Default Alphabet Table (with Character Codes of ISO 8859
Latin 1)" of this SMS tutorial.
• The binary representation of the second octet is 00111010. Now move the most
significant bit of the first octet to the rightmost position of the second octet. The result is
001110100. The seven least significant bits, 1110100, represent the second character.
The hexadecimal value of 1110100 is 0x74, which represents the character "t" according
to the character set "GSM 7-bit default alphabet".
• Similarly, move the two unused bits at the leftmost position of the second octet to the
rightmost position of the third octet. The binary representation of the third octet is
00101000 and so the result is 0010100000. The seven least significant bits, 0100000,
represent the third character. The hexadecimal value of 0100000 is 0x20, which
represents the space character according to the character set "GSM 7-bit default
alphabet".
• The unpacking process continues. This is illustrated in the following table.
Character 1 0 0 1 0 0 1 = 0x49
1
Character 1 1 1 0 1 0 0 = 0x74
2
Character 0 1 0 0 0 0 0 = 0x20
3
Character 1 1 0 1 0 0 1 = 0x69
4
Character 1 1 1 0 0 1 1 = 0x73
5
Character 0 1 0 0 0 0 0 = 0x20
6
Character 1 1 0 0 1 0 1 = 0x65
7
Character 1 1 0 0 0 0 1 = 0x61
8
Character 1 1 1 0 0 1 1 = 0x73
9
Character 1 1 1 1 0 0 1 = 0x79
10
Character 0 1 0 0 0 0 0 = 0x20
11
Character 1 1 1 0 1 0 0 = 0x74
12
Character 1 1 0 1 1 1 1 = 0x6F
13
Character 0 1 0 0 0 0 0 = 0x20
14
Character 1 1 1 0 0 1 0 = 0x72
15
Character 1 1 0 0 1 0 1 = 0x65
16
Character 1 1 0 0 0 0 1 = 0x61
17
Character 1 1 0 0 1 0 0 = 0x64
18
Character 0 1 0 0 0 0 0 = 0x20
19
Character 1 1 1 0 1 0 0 = 0x74
20
Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Character 1 1 0 0 1 0 1 = 0x65
21
Character 1 1 1 1 0 0 0 = 0x78
22
Character 1 1 1 0 1 0 0 = 0x74
23
Character 0 1 0 0 0 0 0 = 0x20
24
Character 1 1 0 1 1 0 1 = 0x6D
25
Character 1 1 0 0 1 0 1 = 0x65
26
Character 1 1 1 0 0 1 1 = 0x73
27
Character 1 1 1 0 0 1 1 = 0x73
28
Character 1 1 0 0 0 0 1 = 0x61
29
Character 1 1 0 0 1 1 1 = 0x67
30
Character 1 1 0 0 1 0 1 = 0x65
31
Character 1 1 1 0 0 1 1 = 0x73
32
Character 0 1 0 0 0 0 0 = 0x20
33
Character 1 1 1 0 1 1 0 = 0x76
34
Character 1 1 0 1 0 0 1 = 0x69
35
Character 1 1 0 0 0 0 1 = 0x61
36
Character 0 1 0 0 0 0 0 = 0x20
37
Character 1 0 0 0 0 0 1 = 0x41
38
Character 1 0 1 0 1 0 0 = 0x54
39
Character 0 1 0 0 0 0 0 = 0x20
40
Character 1 1 0 0 0 1 1 = 0x63
41
Character 1 1 0 1 1 1 1 = 0x6F
42
Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Character 1 1 0 1 1 0 1 = 0x6D
43
Character 1 1 0 1 1 0 1 = 0x6D
44
Character 1 1 0 0 0 0 1 = 0x61
45
Character 1 1 0 1 1 1 0 = 0x6E
46
Character 1 1 0 0 1 0 0 = 0x64
47
Character 1 1 1 0 0 1 1 = 0x73
48
Character 0 1 0 1 1 1 0 = 0x2E
49
Instructing the GSM/GPRS Modem or Mobile Phone to Operate in SMS PDU Mode
First, instruct the GSM/GPRS modem or mobile phone to operate in SMS PDU mode by
entering the command line "AT+CMGF=0" in a terminal program (for example, HyperTerminal in
Microsoft Windows). Below shows the response returned from Nokia 6021 to HyperTerminal
after the execution of the command line "AT+CMGF=0":
AT+CMGF=0
OK
The final result code OK indicates the +CMGF AT command was executed successfully. If the
final result code ERROR is returned, it is likely that the GSM/GPRS modem or mobile phone
does not support SMS PDU mode. To check whether the GSM/GPRS modem or mobile phone
supports SMS PDU mode, enter the command line "AT+CMGF=?" in the terminal program.
Here is the response returned from Nokia 6021 to HyperTerminal:
AT+CMGF=?
+CMGF: (0,1)
OK
The values in the parentheses indicate the modes that the GSM/GPRS modem or mobile phone
can operate in. The value 0 represents SMS PDU mode and the value 1 represents SMS text
mode. From the above response, we know that Nokia 6021 can operate in either SMS PDU
mode or SMS text mode. See the section titled "Selecting the Operating Mode (AT+CMGF)" of
this SMS tutorial if you want to learn further details about the +CMGF AT command.
Selecting the Message Storage Area to Read SMS Text Messages from
Second, use the AT command +CPMS (command name in text: Preferred Message Storage) to
select the message storage area to read SMS text messages from. For example, to instruct the
GSM/GPRS modem or mobile phone to use the message storage area in the SIM card for the
AT command +CMGR, enter the command line 'AT+CPMS="SM"' in the terminal program. Then
press the Enter key on the keyboard and you should see something similar to this:
AT+CPMS="SM"
+CPMS: 2,10,2,10,3,160
OK
Detailed information about the +CPMS AT command is available in the "Preferred Message
Storage (AT+CPMS)" section of this SMS tutorial.
Third, you can now use the +CMGR AT command to read a text message from the message
storage area. Let's say you want to read the SMS text message at index 1. You should enter the
following command line in a terminal program:
AT+CMGR=1
Then press the Enter key on the keyboard and the GSM/GPRS modem or mobile phone will
execute the command line "AT+CMGR=1". If it reads the text message successfully, the result
returned should look something like this:
AT+CMGR=1
+CMGR: 0,,62
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F3
3C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
OK
Here is a brief description of the various field values in the information response above:
• The value of the first field, 0, indicates the status of the SMS message is "received
unread", i.e. it is an SMS text message received from the SMSC and it has not been
read.
• The value of the second field should be a string that contains the text associated to the
sender's phone number "+85291234567" in the phonebook. In this example, this field is
empty. One possible reason is that the GSM/GPRS modem or mobile phone (for
example, Nokia 6021 and many other Nokia products) does not support this field.
• The value of the third field, 62, indicates the TPDU encoded in the hexadecimal
sequence consists of 62 octets.
• The details of the SMS text message are encoded in the hexadecimal sequence.
Examples include the sender's phone number, the body of the SMS text message, the
time and date at which the SMS text message arrived at the SMS center, etc. We have
discussed how to decode the hexadecimal sequence in the section titled "Some
Explanation about the Decoding of the SMSC_number_and_TPDU Field Value of the
+CMGR AT Command" of this SMS tutorial. Thus, we will not talk about it again here.
The final result code OK indicates the SMS text message was read from the message storage
area successfully. If the execution of the +CMGR AT command fails, the GSM/GPRS modem or
mobile phone will return either the final result code ERROR or +CMS ERROR.
After using the +CMGR AT command to read the SMS text message, its status was changed
from "received unread" to "received read". So, if the command line "AT+CMGR=1" is executed
again, you will see a slightly different result (note the part highlighted in bold type):
AT+CMGR=1
+CMGR: 1,,62
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F3
3C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
OK
The SMS text message retrieved above is an incoming text message. Note that if the SMS text
message retrieved is an outgoing text message, the data contained in the hexadecimal
sequence will have a different format and it should be decoded according to the section "Some
Explanation about the Coding of the SMSC_number_and_TPDU Parameter Value of the
+CMGS AT Command" of this SMS tutorial.
Suppose there is no message located at index 3 of the message storage area. If you specify the
index 3 to the +CMGR AT command, the GSM/GPRS modem or mobile phone will return +CMS
error 321 (which means the index is invalid), like this:
AT+CMGR=3
+CMS ERROR: 321
In SMS text mode, you can retrieve the following information about an SMS message with the
AT command +CMGL:
• The index specifying the location of the SMS message in the message storage area.
• Status of the SMS message ("received unread", "received read", "stored unsent", "stored
sent", etc).
• Originator/recipient phone number stored in the SMS message header and the type of
the phone number.
• Text associated to the originator/recipient phone number in the phonebook.
• Time and date at which the SMS message arrived at the SMSC (available to incoming
SMS messages only).
• Body of the SMS message and its length.
• The index specifying the location of the SMS message in the message storage area.
• Status of the SMS message ("received unread", "received read", "stored unsent", "stored
sent", etc).
• Text associated to the originator/recipient phone number in the phonebook.
• SMSC number stored with the SMS message and the type of the SMSC number.
• TPDU of the SMS message and its length.
If the status of a message is "received unread", after being retrieved by the +CMGL AT
command, the status is changed to "received read".
The message storage area from which SMS messages are read is specified by the +CPMS AT
command (command name in text: Preferred Message Storage). Details about the +CPMS AT
command can be found in the earlier section "Preferred Message Storage (AT+CPMS)" of this
SMS tutorial.
+CMGL[=message_status]
The message_status parameter takes a string that specifies the message status to be used to
find messages to return. The SMS specification has defined five message status values, which
are shown below. You can perform a test operation to find the actual values supported by your
GSM/GPRS modem or mobile phone. See the "Finding the Message Status Values Supported
by the +CMGL AT Command in SMS Text Mode" section for the details. Usually all five status
values are supported.
• REC UNREAD. It refers to the message status "received unread". It is the default value.
• REC READ. It refers to the message status "received read".
• STO UNSENT. It refers to the message status "stored unsent".
• STO SENT. It refers to the message status "stored sent".
• ALL. It tells the +CMGL AT command to list all messages.
For example, if "REC READ" is specified to the message_status parameter, the +CMGL AT
command will list all messages that have the "received read" status from the message storage
area.
+CMGL:index,message_status,address,[address_text],
[service_center_time_stamp]
[,address_type,sms_message_body_length]<CR><LF>sms_message_body[<CR><L
F>+CMGL: ...]
Before we discuss each of the fields that appear in the +CMGL information response, let's see
an example that gives you some idea of how an actual +CMGL information response should
look like:
The first field of the information response of the +CMGL AT command, index, is an integer that
specifies the location of the SMS message in the message storage area.
The second field of the information response of the +CMGL AT command, message_status, is a
string that indicates the status of the SMS message. It can be one of the following four values:
The third field of the information response of the +CMGL AT command, address, is a string that
contains the address/phone number stored in the SMS message header. If the SMS message
read is an incoming SMS message, the address field contains the originator address. If the SMS
message read is an outgoing SMS message, the address field contains the recipient address.
Usually the address field value is a phone number formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163). For example, "+85291234567".
The fourth field of the information response of the +CMGL AT command, address_text, is a
string that contains the text associated to address in the phonebook. For example, if the text
"Alice" is associated to the phone number "91234567" in the phonebook, address_text will be
"Alice". The AT command +CSCS (command name in text: Select TE Character Set) can be
used to specify the character set for displaying address_text. Note thataddress_text is an
optional field. Some GSM/GPRS modems and mobile phones (examples: most Nokia products,
including my Nokia 6021) leave this field empty.
Note that service_center_time_stamp is an optional field. This field is available to incoming SMS
messages but not to outgoing SMS messages, since outgoing SMS messages have not gone
through an SMSC.
The sixth field of the information response of the +CMGL AT command, address_type, is an
integer that indicates the type of the address contained in theaddress field. Usually it is one of
the following two values:
• 129. Meaning: The value of address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) but it is not sure whether the value of address is an
international number, a national number or a number of other types. Example
addresses: "85291234567", "91234567".
• 145. Meaning: The value of address is formatted using the typical ISDN / telephony
numbering plan (ITU E.164/E.163) and it is an international number. Example address:
"+85291234567".
Note that address_type is an optional field and it is not shown by default. The AT command
+CSDH (command name in text: Show Text Mode Parameters) can be used to control whether
the field address_type will be shown in the information response of the +CMGL AT command.
Note that sms_message_body_length is an optional field and it is not shown by default. The AT
command +CSDH (command name in text: Show Text Mode Parameters) can be used to
control whether the field sms_message_body_length will be shown in the information response
of the +CMGL AT command.
The eighth field of the information response of the +CMGL AT command, sms_message_body,
contains the body of the SMS message.
If there are multiple SMS messages to be returned, the information response of the +CMGL AT
command will contain more than one "+CMGL: ...". Two characters, <CR><LF>, are used to
delimit two "+CMGL: ...". Here is an example for illustration. Suppose the command line
'AT+CMGL="ALL"' is executed and three SMS messages are listed. If all characters are shown,
the command line and the response returned will be displayed like this:
AT+CMGL="ALL"<CR>
<CR><LF>+CMGL: ...<CR><LF>+CMGL: ...<CR><LF>+CMGL: ...<CR><LF>
<CR><LF>OK<CR><LF>
AT+CMGL="ALL"
+CMGL: ...
+CMGL: ...
+CMGL: ...
OK
As an example, here is the response returned from my Nokia 6021 mobile phone to the
HyperTerminal program in Windows after the execution of the test command "+CMGL=?":
AT+CMGL=?
+CMGL: ("REC UNREAD","REC READ","STO UNSENT","STO SENT","ALL")
OK
From above, we know that the Nokia 6021 mobile phone supports all of the five message status
values defined in the SMS specification.
Instructing the GSM/GPRS Modem or Mobile Phone to Operate in SMS Text Mode
First, enter the command line "AT+CMGF=1" in a terminal program (for example,
HyperTerminal in Microsoft Windows) to instruct the GSM/GPRS modem or mobile phone to
operate in SMS text mode. This step is necessary because the default mode is SMS PDU
mode. Below shows the response returned from Nokia 6021 to HyperTerminal after the
execution of the command line "AT+CMGF=1":
AT+CMGF=1
OK
The final result code OK indicates the +CMGF AT command was executed successfully. If the
final result code ERROR is returned, it is likely that the GSM/GPRS modem or mobile phone
does not support SMS text mode. To check whether the GSM/GPRS modem or mobile phone
supports SMS text mode, enter the command line "AT+CMGF=?" in the terminal program. Here
is the response returned from Nokia 6021 to HyperTerminal:
AT+CMGF=?
+CMGF: (0,1)
OK
The values in the parentheses indicate the modes that the GSM/GPRS modem or mobile phone
can operate in. The values 0 and 1 represent SMS PDU mode and text mode respectively.
From the above response, we know that Nokia 6021 can operate in either SMS PDU mode or
SMS text mode. See the section titled "Selecting the Operating Mode (AT+CMGF)" of this SMS
tutorial if you want to learn further details about the +CMGF AT command.
Selecting the Message Storage Area to Read SMS Text Messages from
Second, use the AT command +CPMS (command name in text: Preferred Message Storage) to
select the message storage area to read SMS text messages from. For example, to instruct the
GSM/GPRS modem or mobile phone to use the message storage area in the SIM card for the
AT command +CMGL, enter the command line 'AT+CPMS="SM"' in the terminal program. The
result should be like this:
AT+CPMS="SM"
+CPMS: 2,10,2,10,5,160
OK
Detailed information about the +CPMS AT command is available in the "Preferred Message
Storage (AT+CPMS)" section of this SMS tutorial.
Third, you can now use the +CMGL AT command to list SMS text messages from the message
storage area. Let's say you want to retrieve all new SMS messages received. As the status of
new inbound SMS messages is "received unread", you should specify "REC UNREAD" to the
+CMGL AT command, as shown below:
AT+CMGL="REC UNREAD"
Since "REC UNREAD" is the default parameter value, you can simply omit it, like this:
AT+CMGL
Now press the Enter key on the keyboard. The GSM/GPRS modem or mobile phone will then
execute the command line "AT+CMGL" and return all text messages that have the "REC
UNREAD" status in the message storage area. In a terminal program such as HyperTerminal of
Microsoft Windows, the result should look something like this:
AT+CMGL
+CMGL: 2,"REC UNREAD","+85291234567",,"07/02/18,00:05:10+32"
A simple demo of SMS text messaging.
+CMGL: 3,"REC UNREAD","+85291234567",,"07/02/18,00:07:22+32"
It is easy to list SMS text messages.
OK
From above, we know that the message storage area contains two new inbound SMS text
messages. The first one is "A simple demo of SMS text messaging." and the second one is "It is
easy to list SMS text messages.". Let's take the first SMS text message as an example to
illustrate the meaning of different field values in the information response:
• The value of the first field, 2, tells us the text message is stored in the memory location
at index 2.
• The value of the second field, "REC UNREAD", indicates the status of the text message
is "received unread".
• The value of the third field, "+85291234567", is the sender's phone number.
• The value of the fourth field should be a string that contains the text associated to the
sender's phone number "+85291234567" in the phonebook. In this example, this field is
empty. One possible reason is that the GSM/GPRS modem or mobile phone (for
example, Nokia 6021 and many other Nokia products) does not support this field.
• The value of the fifth field, "07/02/18,00:05:10+32", tells us that the SMSC received the
text message at 00:05:10 (GMT+8) on 18 Feb 2007. (Don't forget the unit of time zone is
a quarter of an hour. Since 32 quarters of an hour = 8 hours, "+32" means GMT+8
hours.)
• The value of the sixth field, "A simple demo of SMS text messaging.", is the body of the
SMS text message.
The final result code OK indicates the SMS text messages were read from the message storage
area successfully. If the execution of the +CMGL AT command fails, the GSM/GPRS modem or
mobile phone will return either the final result code ERROR or +CMS ERROR.
Now if the command line "AT+CMGL" is executed again, no text message will be listed. Here
shows the response returned from Philips 598:
AT+CMGL
OK
The response returned from Nokia 6021 is slightly different, as shown below. There seems to be
a minor bug in Nokia's implementation. Two extra characters <CR><LF> are outputted and this
does not follow the general syntax of extended AT commands.
AT+CMGL
OK
No SMS text message is listed because the status of the SMS text messages "A simple demo of
SMS text messaging." and "It is easy to list SMS text messages." has been changed from
"received unread" to "received read" after being read by the +CMGL AT command. To see
these two SMS text messages again, specify either "REC READ" or "ALL" to the +CMGL AT
command, like this:
AT+CMGL="ALL"
+CMGL: 1,"STO SENT","+85291234567",,
Hello, welcome to our SMS tutorial.
+CMGL: 2,"REC READ","+85291234567",,"07/02/18,00:05:10+32"
A simple demo of SMS text messaging.
+CMGL: 3,"REC READ","+85291234567",,"07/02/18,00:07:22+32"
It is easy to list SMS text messages.
OK
As mentioned in the earlier section "Format of the Information Response of the +CMGL AT
Command in SMS Text Mode", two optional
fields address_type and sms_message_body_length are not shown in the information response
of the +CMGL AT command by default. To show these optional fields, you have to specify the
value 1 to the +CSDH AT command (command name in text: Show Text Mode Parameters):
AT+CSDH=1
OK
Execute the command line 'AT+CMGL="ALL"' again and the result should be:
AT+CMGL="ALL"
+CMGL: 1,"STO SENT","+85291234567",,,145,35
Hello, welcome to our SMS tutorial.
+CMGL: 2,"REC READ","+85291234567",,"07/02/18,00:05:10+32",145,36
A simple demo of SMS text messaging.
+CMGL: 3,"REC READ","+85291234567",,"07/02/18,00:07:22+32",145,37
It is easy to list SMS text messages.
OK
The value of the address_type fields (the sixth field from the left) of all three SMS text messages
is 145, which indicates the phone numbers stored with these three SMS text messages are
typical phone numbers in international format. The values of
the sms_message_body_length fields (the seventh field from the left) of the three SMS text
messages are 35, 36 and 37. They indicate the SMS text messages contain 35 characters, 36
characters and 37 characters respectively.
+CMGL[=message_status]
The message_status parameter takes an integer that specifies the message status to be used
to find messages to return. The SMS specification has defined five message status values,
which are shown below. You can perform a test operation to find the actual values supported by
your GSM/GPRS modem or mobile phone. See the "Finding the Message Status Values
Supported by the +CMGL AT Command in SMS PDU Mode" section for the details. Usually all
five status values are supported.
For example, if 1 is specified to the message_status parameter, the +CMGL AT command will
list all messages that have the "received read" status from the message storage area.
Note that message_status is an optional parameter. If it is omitted, the +CMGL AT command
will use the default value 0.
+CMGL: index,message_status,
[address_text],TPDU_length<CR><LF>SMSC_number_and_TPDU[<CR><LF>+CMGL:
...]
Before we discuss each of the fields that appear in the +CMGL information response, let's see
an example that gives you some idea of how an actual +CMGL information response should
look like:
+CMGL: 1,0,,62
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F3
3C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
The first field of the information response of the +CMGL AT command, index, is an integer that
specifies the location of the SMS message in the message storage area.
The second field of the information response of the +CMGL AT command, message_status, is
an integer that indicates the status of the SMS message. It can be one of the following four
values:
The third field of the information response of the +CMGL AT command, address_text, is a string
that contains the text associated to address in the phonebook, where address is the phone
number encoded in the TPDU of the SMSC_number_and_TPDU field. For example, if the
phone number encoded in the TPDU is "91234567" and the text "Alice" is associated to the
phone number "91234567" in the phonebook, address_text will be "Alice". The AT command
+CSCS (command name in text: Select TE Character Set) can be used to specify the character
set for displaying address_text.
Note that address_text is an optional field. Some GSM/GPRS modems and mobile phones
leave this field empty. (Examples: Philips 598 supports this field, while most Nokia products,
including my Nokia 6021, and Sony Ericsson T68i does not.)
The fourth field of the information response of the +CMGL AT command, TPDU_length, is an
integer that indicates the length (in octets. 1 octet = 8 bits) of the TPDU contained in
the SMSC_number_and_TPDUfield. In the earlier example command line, the value of
the SMSC_number_and_TPDU field is:
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F3
3C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
It can be divided into two parts. The following part is the TPDU:
040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132
885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
The TPDU is coded in hexadecimal format. Each character represents 4 bits, i.e. 1/2 octet. The
TPDU has 124 characters and so there are totally 62 octets. That's why the value of
the TPDU_length field is 62.
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F3
3C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
The TPDU embedded in the above hexadecimal sequence is of the type SMS-DELIVER. Here
is some of the information encoded in the hexadecimal sequence:
• SMSC number from which the SMS message was received: +85290000000
• Sender phone number: +85291234567
• Time and date at which the SMSC received the SMS message: 12 April 2007, 23:25:42
GMT+8 hours
• Text message: "It is easy to read text messages via AT commands."
For the details about how the hexadecimal sequence of an incoming SMS message is coded,
please refer to the section titled "Some Explanation about the Decoding of the
SMSC_number_and_TPDU Field Value of the +CMGR AT Command" of this SMS tutorial.
07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E3
2885EC6D341EDF27C1E3E97E72E
The TPDU embedded in the above hexadecimal sequence is of the type SMS-SUBMIT. Its
format is different from that of an SMS-DELIVER TPDU. Below shows some of the information
encoded in the hexadecimal sequence above:
For the details about how the hexadecimal sequence of an outgoing SMS message is coded,
please refer to the section titled "Some Explanation about the Coding of the
SMSC_number_and_TPDU Parameter Value of the +CMGS AT Command" of this SMS tutorial.
If there are multiple SMS messages to be returned, the information response of the +CMGL AT
command will contain more than one "+CMGL: ...". Two characters, <CR><LF>, are used to
delimit two "+CMGL: ...". Here is an example for illustration. Suppose the command line
"AT+CMGL=4" (this command line tells the GSM/GPRS modem or mobile phone to retrieve all
messages from message storage) is executed and three SMS messages are listed. If all
characters are shown, the command line and the response returned will be displayed like this:
AT+CMGL=4<CR>
<CR><LF>+CMGL: ...<CR><LF>+CMGL: ...<CR><LF>+CMGL: ...<CR><LF>
<CR><LF>OK<CR><LF>
AT+CMGL=4
+CMGL: ...
+CMGL: ...
+CMGL: ...
OK
+CMGL: (list_of_status_values)
In SMS PDU mode, the values inside the above parentheses are integers. The SMS
specification has defined five message status values: 0, 1, 2, 3 and 4. They are supported by
most GSM/GPRS modems and mobile phones. A description of these five message status
values can be found in the earlier section "Syntax of the +CMGL AT Command in SMS PDU
Mode".
As an example, here is the response returned from my Nokia 6021 mobile phone to the
HyperTerminal program in Windows after the execution of the test command "+CMGL=?":
AT+CMGL=?
+CMGL: (0-4)
OK
From above, we know that the Nokia 6021 mobile phone supports all of the five message status
values defined in the SMS specification.
Do you remember that we described the format of values inside parentheses in the section
"Test Command -- Checks Whether a Certain AT Command is Supported"? If not, you may
want to go back and have a look. Here are a few examples showing some of the possibilities:
"(0-4)", "(0,1,2,3,4)", "(0,2-4)".
Instructing the GSM/GPRS Modem or Mobile Phone to Operate in SMS PDU Mode
First, instruct the GSM/GPRS modem or mobile phone to operate in SMS PDU mode by
entering the command line "AT+CMGF=0" in a terminal program (for example, HyperTerminal in
Microsoft Windows). Below shows the response returned from Nokia 6021 to HyperTerminal
after the execution of the command line "AT+CMGF=0":
AT+CMGF=0
OK
The final result code OK indicates the +CMGF AT command was executed successfully. If the
final result code ERROR is returned, it is likely that the GSM/GPRS modem or mobile phone
does not support SMS PDU mode. To check whether the GSM/GPRS modem or mobile phone
supports SMS PDU mode, enter the command line "AT+CMGF=?" in the terminal program.
Here is the response returned from Nokia 6021 to HyperTerminal:
AT+CMGF=?
+CMGF: (0,1)
OK
The values in the parentheses indicate the modes that the GSM/GPRS modem or mobile phone
can operate in. The value 0 represents SMS PDU mode and the value 1 represents SMS text
mode. From the above response, we know that Nokia 6021 can operate in either SMS PDU
mode or SMS text mode. See the section titled "Selecting the Operating Mode (AT+CMGF)" of
this SMS tutorial if you want to learn further details about the +CMGF AT command.
Selecting the Message Storage Area to Read SMS Text Messages from
Second, use the AT command +CPMS (command name in text: Preferred Message Storage) to
select the message storage area to read SMS text messages from. For example, to instruct the
GSM/GPRS modem or mobile phone to use the message storage area in the SIM card for the
AT command +CMGL, enter the command line 'AT+CPMS="SM"' in the terminal program. Then
press the Enter key on the keyboard and you should see something similar to this:
AT+CPMS="SM"
+CPMS: 2,10,2,10,3,160
OK
Detailed information about the +CPMS AT command is available in the "Preferred Message
Storage (AT+CPMS)" section of this SMS tutorial.
Third, use the +CMGL AT command to list SMS text messages from the message storage area.
Suppose you would like to retrieve all new SMS messages received. As the status of new
inbound SMS messages is "received unread", you should specify 0 to the +CMGL AT
command, as shown below:
AT+CMGL=0
Since 0 is the default parameter value, you can simply omit it, like this:
AT+CMGL
Now press the Enter key on the keyboard and the GSM/GPRS modem or mobile phone will
execute the command line "AT+CMGL". If successful, it returns all messages that have the
"received unread" status in the message storage area. In a terminal program such as
HyperTerminal of Microsoft Windows, the result should look something like this:
AT+CMGL
+CMGL: 2,0,,51
07915892000000F0040B915892214365F70000701010221555232441D03CDD86B3CB20
72B9FD06BDCDA069730AA297F17450BB3C9F87CF69F7D905
+CMGL: 3,0,,62
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F3
3C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
OK
From above, we know that the message storage area contains two new inbound SMS text
messages. Let's take the first SMS text message as an example to illustrate the meaning of
different field values in the +CMGL information response above:
• The value of the first field, 2, tells us the text message is stored in the memory location
at index 2.
• The value of the second field, 0, indicates the status of the text message is "received
unread".
• The value of the third field should be a string that contains the text associated to the
sender's phone number "+85291234567" in the phonebook. In this example, this field is
empty. One possible reason is that the GSM/GPRS modem or mobile phone (for
example, Nokia 6021 and many other Nokia products) does not support this field.
• The value of the fourth field, 51, tells us the TPDU encoded in the hexadecimal
sequence consists of 51 octets.
• The details of the SMS text message are encoded in the hexadecimal sequence.
Examples include the sender's phone number, the body of the SMS text message, the
time and date at which the SMS text message arrived at the SMS center, etc. We have
discussed how to decode the hexadecimal sequence of an inbound SMS text message
in the section titled "Some Explanation about the Decoding of the
SMSC_number_and_TPDU Field Value of the +CMGR AT Command" of this SMS
tutorial. Thus, we will not talk about it again here.
For the decoding of the hexadecimal sequence of an outgoing SMS text message,
please refer to the "Some Explanation about the Coding of the
SMSC_number_and_TPDU Parameter Value of the +CMGS AT Command" section of
this SMS tutorial.
The final result code OK informs us that the SMS text messages were read from message
storage successfully. If the execution of the +CMGL AT command fails, the GSM/GPRS modem
or mobile phone will return either the final result code ERROR or +CMS ERROR.
After using the +CMGL AT command to list the SMS text messages, their status was changed
from "received unread" to "received read". So, if the command line "AT+CMGL" is executed
again, no text message will be returned. Here shows the response returned from Philips 598:
AT+CMGL
OK
The response returned from Nokia 6021 is slightly different, as shown below. There seems to be
a minor bug in Nokia's implementation. Two extra characters <CR><LF> are outputted and this
does not follow the general syntax of extended AT commands.
AT+CMGL
OK
To see the two text messages again, specify either 1 or 4 to the +CMGL AT command. The
value 1 instructs +CMGL to list all messages that have the "received read" status from message
storage, while the value 4 instructs +CMGL to list all messages from message storage. The
response returned from the GSM/GPRS modem or mobile phone is slightly different from the
earlier one. The changes are highlighted in bold type below:
AT+CMGL=1
+CMGL: 2,1,,51
07915892000000F0040B915892214365F70000701010221555232441D03CDD86B3CB20
72B9FD06BDCDA069730AA297F17450BB3C9F87CF69F7D905
+CMGL: 3,1,,62
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F3
3C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
OK