How to receive an SMS Message with a modem using AT commands

The following AT commands show you how to work wiht the SMS protocol in a real life scenario. It explains, how you can read an incoming SMS from the SIM card of an SMS modem in either PDU more or Text mode. You will see, that the SMS PDU returned matched the SMS protocol explanation.

How to receive SMS with at commands (Quick steps)

To receive SMS with at commands:

  1. Receive the message to the SMS modem
  2. Use the AT+CGMR=location command to read the SMS message
  3. Modify the code depending on it's in PDU or text mode
  4. Use AT+CMGD=location command to delete one SMS message
  5. Check the log from the SMS modem

Receiving an SMS with an SMS modem

When there a new SMS message arrives to the SMS modem, it will be stored in the SIM card or the memory of the modem. This is done automatically. You have no control over this procedure

To read the SMS message, Ozeki SMS Gateway will issue the Read memory command using an AT command. By default Ozeki uses the modem in PDU mode and it uses the AT+CMGR command to get the message. Ozeki uses two methods, it can rely on the message indication (AT+CMTI) or it can loop through all the memory cells of the SIM card the modem memory.

How to read the memory of a GSM modem in PDU mode

In PDU mode, when the SMS modem receives a SMS message, the following message will be sent to the PC over the serial or USB PORT:

+CMTI: “SM”, 1

where 1 is the memory location in which the message can be read from.

To read a SMS message from a particular location in memory (eg. location 1) use the AT+CGMR command IS required.

AT+CMGR=1[ENTER]
The SMS modem should return the PDU message as follow.
+CMGR: 0,,24
07916314786007F0040B911604994743F400009930139100406B05E8329BFD06
OK

where 0 is the status code indicating a received and already read message, 24 is the hexadecimal number indicating the length of the message.

How to read the memory of a GSM modem in text mode

Like PDU mode, when the SMS modem receives a SMS message, the following message will appear on the PC screen.

+CMTI: “SM”, 1

where 1 is the memory location in which the message can be read from.

To read the SMS message use the AT+CGMR command as follow.

AT+CMGR=1[ENTER]

The SMS modem should return the text message as follow.

+CMGR: “REC READ”,“+3620201234567”,“20/12/01,20:18:12+44”

hello

OK

How to delete an SMS message from the SIM card or modem memory

The SMS message can be deleted from the SIM card or the memory (eg. location 1) using the AT+CMGD command as follows. Note that there is no AT command to delete all the SMS messages at once.

AT+CMGD=1[ENTER]

The SMS modem should return OK.

More information