This post is intended to illustrate the received SMS by a GSM module like SIM900.AT commands to handle the received SMS are explained in detail.
We shall use a SIM900 module on RS232 breakout board & an USB-UART converter board to connect it to the PC.
Following is the setup to test received SMS using SIM900.
A terminal software like PUTTY is used to read out the COM port where GSM is connected to PC through USB-UART board.
As you connect the USB-UART board to PC ,the PC allots a COM port which can be seen under Device manager.Open the PUTTY terminal & set this to read the serial port.
Open the Putty terminal & type in AT .If your modem settings & connections are fine you get an OK response from the modem.
Preferred Storage Area
To select the Storage area for SMS type in
AT+CPMS command .This sets the Preferred Message Storage area.
To know the Message areas supported by our GSM ,enter the AT command
As seen above ,our modem returns all 3 message storage areas as SM , which refers to the Message storage area on the SIM card.
The first SM specifies the message storage area that will be used while Reading or Deleting SMS.
The second SM specifies the area that will be used when sending SMS from message storage or writing SMS to storage.
The third SM specifies the preferred message storage area for storing newly received SMS.
In our case ,SM is the preferredstorage area for all SMS functions , Read , Send & Receive.
The other storage areas are ME (storage area on GSM Modem/Mobile phone) , MT (read from all storage area associated with GSM), BM (incoming Broadcast message storage area) , SR (status report) & TA (Terminal adapter )
To know the SMS Service center address (SMSC)
The mobile network operator’s service center number will be displayed.
The number 145 in +CSCA is the address type .145 refers to International number starting with +.
The next AT command
reports the SMS modes supported by the GSM. 0 is for Text mode & 1 is for Protocol Data Unit (PDU) mode.Our modem reports (0,1) supporting both SMS modes.
To check if your modem supports the text mode, you can try the following command:
If the modem responds with “OK” this text mode is supported. It is possible to send only simple text messages in this mode.
To know the current message format use the command
Reading Messages from Storage Area
To read messages from SIM storage type in
The Modem responds with + CPMS: followed by Used space & Maximum space.
In our modem there are currently 2 messages in memory (used space ) & maximum storage capacity is for 30 messages.
To list out all messages in the SM storage type in
The modem responds with a list of all messages in the storage area.
+CMGL: 1 is the Memory Index number used to read or delete message
“REC READ” is the status message.If the message is not Read it shows REC UNREAD
“+91xxx “ is the phone number from where the message originated.
“,” Next column is the reference number of the message.Generally this field is empty.
“13/09/19…” is the Date & time of received SMS in yy/mm/dd,hh:mm : ss format
Finally the actual message in text format is displayed.
To list out a particular message , use the CMGR command with the index number of the message to be read.
AT+CMGR=2 to list the message at index 2
AT+CMGR=4 to list the message at index 4
To delete a message use CMGD command with the index number of message to be deleted.
AT+CMGD=1 to delete the message at index 1.
You can issue the command AT+CMGL=”ALL” to see that the message at index 1 is deleted.
To delete all the messages in the storage area there is no such command like AT+CMGD=”ALL”.
Use the following notation to delete all messages.
1 is the Index value & 4 is the flag value
To know the index & flag values allowed
1 to 30 can be assigned to index parameter & all five flag values from 0 to 4 are supported.
By default flag value is 0 which means “Delete message at location <index>”
Flag value 1 – Delete all READ messages ,ignoring value of index.
Flag value 2 – Delete all READ & SEND messages.
Flag value 3 – Delete all Read,Sent & Unsent messages.
Flag value 4 –Delete all messages.
You can see from above screen shot that all messages are deleted after issuing AT+CMGD=1,4.
AT+CNMI – New message indication to Terminal Equipment TE.
Selects procedure how receiving of new messages from the network is indicated to the TE.
The following command sets the indicators for receiving an SMS message.
AT+CNMI=1,1,0,0,0 Set the new message indicators.
<mode>=1 discard unsolicited result codes indication when TA – TE link is reserved.
=2 controls processing of unsolicited result codes & forward them directly to Terminal Equipment TE
<mt>=1 SMS-DELIVERs are delivered to the SIM and routed using unsolicited code.
<bm>=0 no cell broadcast message indications are routed to the TE.
<ds>=0 no SMS-STATUS-REPORTs are routed.
<bfr>=0 Terminal Adapter ( TA) buffer of unsolicited result codes defined within this command is flushed to the TE (Terminal equipment).
The following command saves the SMS settings. Once the SMS commands have been saved, the initialization commands do not need to be sent again until they are changed.
toSave SMS settings. This may take up to 10 seconds.
Watch this support video :