26. Reading SMS Messages from a Message Storage Area Using AT Commands (AT+CMGR, AT+CMGL)

To enable a computer / PC to read SMS messages from a message storage area, the GSM/GPRS modem or mobile phone has to support either of the AT commands +CMGR (command name in text: Read Messages) and +CMGL (command name in text: List Messages). The +CMGR AT command is used to read an SMS message at a certain location of the message storage area, while the +CMGL AT command is used to read SMS messages that have a certain status from the message storage area. The status can be "received unread", "received read", "stored unsent", "stored sent", etc. The +CMGL AT command also allows you to retrieve all SMS messages stored in the message storage area.

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:


+CMGR: "REC READ","+85291234567",,"07/02/18,00:12:05+32"
Hello, welcome to our SMS tutorial.

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:


+CMGL: 1,"REC UNREAD","+85291234567",,"07/02/18,00:05:10+32"
Reading text messages is easy.
+CMGL: 2,"REC UNREAD","+85291234567",,"07/02/18,00:07:22+32"
A simple demo of SMS text messaging.

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:


+CMGL: 1,"REC READ","+85291234567",,"07/02/18,00:05:10+32"
Reading text messages is easy.
+CMGL: 2,"REC READ","+85291234567",,"07/02/18,00:07:22+32"
A simple demo of SMS text messaging.
+CMGL: 3,"REC READ","+85291234567",,"07/02/18,00:12:05+32"
Hello, welcome to our SMS tutorial.

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:

Here are the message details that can be retrieved by the +CMGL AT command in SMS text mode:

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.


26.1. Comparison Table of the AT Commands +CMGR and +CMGL

The comparison table below summarizes the differences between the AT commands +CMGR and +CMGL that are discussed in the previous section.



+CMGR AT command

+CMGL AT command

Usage

+CMGR is used to read an SMS message at a certain location of the message storage area.

+CMGL is used to read SMS messages that have a certain status (examples: "received unread", "received read", "stored unsent" and "stored sent") from the message storage area. It also allows you to retrieve all SMS messages stored in the message storage area.

Number of SMS messages returned

+CMGR returns one SMS message.

+CMGL returns one or more SMS messages.

Message details returned (SMS text mode)



  1. (Note: +CMGR does not provide the index of the SMS message in the response because it is the parameter value you passed to +CMGR.)

  2. Status of the SMS message ("received unread", "received read", "stored unsent", "stored sent", etc).

  3. Originator/recipient phone number stored in the SMS message header and the type of the phone number.

  4. Text associated to the originator/recipient phone number in the phonebook.

  5. Time and date at which the SMS message arrived at the SMSC (available to incoming SMS messages only).

  6. The first octet (1 octet = 8 bits) of the TPDU (Transport Protocol Data Unit) of the SMS message.

  7. The protocol identifier value in the TPDU of the SMS message.

  8. The data coding scheme value in the TPDU of the SMS message.

  9. SMSC number stored with the SMS message and the type of the SMSC number.

  10. Validity period of the SMS message (available to outgoing SMS messages only).

  11. Body of the SMS message and its length.

  1. The index specifying the location of the SMS message in the message storage area.

  2. Status of the SMS message ("received unread", "received read", "stored unsent", "stored sent", etc).

  3. Originator/recipient phone number stored in the SMS message header and the type of the phone number.

  4. Text associated to the originator/recipient phone number in the phonebook.

  5. Time and date at which the SMS message arrived at the SMSC (available to incoming SMS messages only).

  6. Body of the SMS message and its length.

Message details returned (SMS PDU mode)

Same



Previous Page Page 55 of 65 Next Page

Contents at a Glance (Click Here for Full Table of Contents)

Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page