# AT command in SIM900A GSM/GPRS module to find out originating address of an SMS

I am using SIM900A for some purpose and want to know the number of the sender from where a message comes. I am unable to find the specific AT command related to receiving message which give me number from where latest message comes.

I had used AT+CNMI (it corresponds to notification regarding latest received message), but am unable to find sender number.

I had seen AT+CMGL=<stat>[,<mode>] will give you a string which will have oa i.e. originating address and once that is stored in a string I can easily parse it out, but when I had data format of that string. Need help or any suggestion if somebody can help me out with any other possible solution.

### Text mode vs PDU mode

The SIM900 module supports both text and PDU mode. Please note that some AT commands have different syntax depending on which mode is currently active.

To check which mode is currently active (0: PDU mode, 1: Text mode):

 AT+CMGF?


### Retrieving SMS's

You can use the CMGL command to retrieve unread, read, stored unsent, stored sent, or all messages.

If text mode is currently selected:

 AT+CMGL=STAT,MODE


Parameters:

STAT:
"STO UNSENT"  Stored unsent messages
"STO SENT"    Stored sent messages
"ALL"         All messages
MODE: (OPTIONAL)
0 Normal
1 Not change status of the specified SMS record

In other words, the following command should print all SMS messages:

AT+CMGL="ALL"


If PDU mode is currently selected:

 AT+CMGL=STAT,MODE


Parameters:

STAT:
2  Stored unsent messages
3  Stored sent messages
4  All messages
MODE: (OPTIONAL)
0 Normal
1 Not change status of the specified SMS record

In other words, the following command should print all SMS messages:

AT+CMGL=4


### Example

If text mode is currently selected, and a CMGL command is issued, the following is an example of what could be expected (note there's a line break before the actual message starts).

AT+CMGL="ALL"