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:
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:
The first octet of the TPDU 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).
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) |
|
|
Message details returned (SMS PDU mode) |
Same |
Previous Page | Page 55 of 65 | Next Page |
- 1. Introduction to SMS Messaging
- 2. What Makes SMS Messaging So Successful Worldwide?
- 3. Example Applications of SMS Messaging
- 4. What is an SMS Center / SMSC?
- 5. Basic Concepts of SMS Technology
- 6. Intra-operator SMS Messages
- 7. Inter-operator SMS Messages
- 8. International SMS Messages
- 9. What is an SMS Gateway?
- 10. How to Send SMS Messages from a Computer / PC?
- 11. How to Receive SMS Messages Using a Computer / PC?
- 12. Introduction to GSM / GPRS Wireless Modems
- 13. How to Use Microsoft HyperTerminal to Send AT Commands to a Mobile Phone or GSM/GPRS Modem?
- 14. Introduction to AT Commands
- 15. General Syntax of Extended AT Commands
- 16. Result Codes of AT Commands
- 17. AT Command Operations: Test, Set, Read and Execution
- 18. Testing the Communication between the PC and GSM/GPRS Modem or Mobile Phone
- 19. Checking if the GSM/GPRS Modem or Mobile Phone Supports the Use of AT Commands to Send, Receive and Read SMS Messages
- 20. Operating Mode: SMS Text Mode and SMS PDU Mode
- 21. Setting or Reading the Service Center Address / SMSC Address (AT+CSCA)
- 22. Preferred Message Storage (AT+CPMS)
- 23. Writing SMS Messages to Memory / Message Storage (AT+CMGW)
- 24. Deleting SMS Messages from Message Storage (AT+CMGD)
- 25. Sending SMS Messages from a Computer / PC Using AT Commands (AT+CMGS, AT+CMSS)
- 26. Reading SMS Messages from a Message Storage Area Using AT Commands (AT+CMGR, AT+CMGL)
- 27. Appendix A: How to Choose an SMS Service Provider (SMS Gateway Provider, SMS Reseller, SMS Broker)?
- 28. Appendix B: Comparison Table of SMS Service Providers (SMS Gateway Providers, SMS Resellers, SMS Brokers)
- 29. Appendix C: Free Software/Tools and Libraries for Sending and Receiving SMS Messages with a Computer / PC
- 30. Appendix D: GSM 7-bit Default Alphabet Table (with Character Codes of ISO 8859 Latin 1)