Reading SMS Messages from Message Storage Using AT Commands (AT+CMGR, AT+CMGL) (2023)

Toenable a computer / PC to read SMS messages from a message storagearea, the GSM/GPRS modem or mobile phone has to support either of theAT commands +CMGR (command name in text: Read Messages) and +CMGL(command name in text: List Messages). The +CMGR AT command is usedto read an SMS message at a certain location of the message storagearea, while the +CMGL AT command is used to read SMS messages thathave a certain status from the message storage area. The status canbe "received unread", "received read", "storedunsent", "stored sent", etc. The +CMGL AT command alsoallows you to retrieve all SMS messages stored in the message storagearea.

Followingis an example for illustrating the difference between +CMGR and+CMGL. Suppose you want to use your computer / PC to read a textmessage from the message storage area and you know the index at whichthe SMS text message is located. In this case, you should use the+CMGR AT command. Here is the command line to be typed (assume theSMS text message is stored at index 3):

AT+CMGR=3

TheGSM/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

Supposeyou are now in another situation. You want to use your computer / PCto 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="RECUNREAD"

TheGSM/GPRS modem or mobile phone should return something like this:

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

OK

The+CMGL AT command can also be used to read all SMS messages stored inthe message storage area. To do so in SMS text mode, the command lineshould be:

AT+CMGL="ALL"

Thistime the response of the GSM/GPRS modem or mobile phone should besomething like this:

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

OK

Asyou can see above, the +CMGR AT command can only be used to read oneSMS message at a time, while the +CMGL AT command can be used to readmultiple SMS messages at a time.

Anotherdifference between the AT commands +CMGR and +CMGL is that +CMGR canbe used to retrieve more message details than +CMGL when the GSM/GPRSmodem or mobile phone is operating in SMS text mode. Here are themessage details that can be retrieved by the +CMGR AT command in SMStext mode:

Hereare the message details that can be retrieved by the +CMGL AT commandin SMS text mode:

  • Theindex specifying the location of the SMS message in the messagestorage area.

  • Statusof the SMS message ("received unread", "receivedread", "stored unsent","stored sent", etc).

  • Originator/recipientphone number stored in the SMS message header and the type of thephone number.

  • Textassociated to the originator/recipient phone number in thephonebook.

  • Timeand date at which the SMS message arrived at the SMSC (available toincoming SMS messages only).

  • Bodyof the SMS message and its length.

Ifyou compare the above two lists, you will find that the followingmessage details can only be retrieved by the +CMGR AT command but notthe +CMGL AT command:

  • Thefirst octet of the TPDU of the SMS message.

  • Theprotocol identifier value in the TPDU of the SMS message.

  • Thedata coding scheme value in the TPDU of the SMS message.

  • SMSCnumber stored with the SMS message and the type of the SMSC number.

  • Validityperiod 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 thesame.

26.1. ComparisonTable of the AT Commands +CMGR and +CMGL

Thecomparison table below summarizes the differences between the ATcommands +CMGR and +CMGL that are discussed in the previous section.

+CMGRAT command

+CMGLAT command

Usage

+CMGRis used to read an SMS message at a certain location of themessage storage area.

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

Numberof SMS messages returned

+CMGRreturns one SMS message.

+CMGLreturns one or more SMS messages.

Messagedetails returned (SMS text mode)

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

  2. Statusof the SMS message ("received unread", "receivedread", "stored unsent", "stored sent",etc).

  3. Originator/recipientphone number stored in the SMS message header and the type ofthe phone number.

  4. Textassociated to the originator/recipient phone number in thephonebook.

  5. Timeand date at which the SMS message arrived at the SMSC (availableto incoming SMS messages only).

  6. Thefirst octet (1 octet = 8 bits) of the TPDU (Transport ProtocolData Unit) of the SMS message.

  7. Theprotocol identifier value in the TPDU of the SMS message.

  8. Thedata coding scheme value in the TPDU of the SMS message.

  9. SMSCnumber stored with the SMS message and the type of the SMSCnumber.

  10. Validityperiod of the SMS message (available to outgoing SMS messagesonly).

  11. Bodyof the SMS message and its length.

  1. Theindex specifying the location of the SMS message in the messagestorage area.

  2. Statusof the SMS message ("received unread", "receivedread", "stored unsent", "stored sent",etc).

  3. Originator/recipientphone number stored in the SMS message header and the type ofthe phone number.

  4. Textassociated to the originator/recipient phone number in thephonebook.

  5. Timeand date at which the SMS message arrived at the SMSC (availableto incoming SMS messages only).

  6. Bodyof the SMS message and its length.

Messagedetails returned (SMS PDU mode)

Same

Previous PagePage 55 of 65Next Page

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

  • 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)

Print this Web Page | | Back to Top


Feedback Form (ExpandCollapse)

Top Articles
Latest Posts
Article information

Author: Roderick King

Last Updated: 02/25/2023

Views: 6060

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.