26.3.8. Example
Demonstrating How to Use the +CMGL AT Command to List SMS Text
Messages from a Message Storage Area (SMS PDU Mode)
Now
let's see a more detailed example that demonstrates how to use the
+CMGL AT command to list SMS text messages from a message storage
area when SMS PDU mode is used, and how the +CMGL AT command should
be used together with other AT commands.
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.
Listing
SMS Text Messages
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 07915892000000F0040B915892214365F70000701010221555232441D03CDD86B3CB2072B9FD06BDCDA069730AA297F17450BB3C9F87CF69F7D905 +CMGL:
3,0,,62 07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
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 07915892000000F0040B915892214365F70000701010221555232441D03CDD86B3CB2072B9FD06BDCDA069730AA297F17450BB3C9F87CF69F7D905 +CMGL:
3,1,,62 07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
OK
Previous Page
|
Page 65 of 65 |
|
 |
Feedback Form (ExpandCollapse)
|
|