-2

How to count unread SMS or revived SMS using AT command?

void UnreadMEssage() {
  fonaSS.println("AT+CMGF=0");
  delay(1000);
  fonaSS.println("AT+CMGL=\"REC UNREAD\",1");
}

Using this code, I can show the all received text messages, but I want to count the unread SMS.

dda
  • 6,030
  • 2
  • 25
  • 34

2 Answers2

2

Answering in reference to this blog :

There is no direct command to count the number of unread messages . We can use AT+CMGL command in a modified way to count unread messages .

  1. Use the command AT+CPMS? to find out how many messages are stored in your SIM in total.
  2. Use AT+GMGL=<stat> for each status other than 0 "REC UNREAD" and count the number of messages for each of these.
  3. Add each of these counts together and subtract that from the total memory used as reported by +CPMS and you've got the number of unread messages.

P.B : If you don't mind "reading" the messages just do the +CMGL for status 0 "REC UNREAD" and count, i.e those messages will be marked as read.

Mathews Sunny
  • 1,796
  • 7
  • 21
  • 31
1

The AT command +CPMS (Preferred Message Storage) is used to figure out,

  1. Select the message storage area that will be used when sending, receiving, reading, writing or deleting SMS messages.

  2. Find the number of messages that are currently stored in the message storage area.

  3. Find the maximum number of messages that can be stored in the message storage area. try AT+CPMS? to list the available spaces. and issue a command like this,

     AT+CPMS="SM","SM","SM"
    

the response should show used space,available space repeatedly like this,

+CPMS: "SM",19,20,"SM",19,20,"SM",19,20

here is SM signifies SIM card space and a list of available options is below. A typical response shows,

+CPMS: used1,max1,used2,max2,used3,max3

Based on the count, read each response using AT+CMGR=x (x is the index of the message) and parse the response for "REC UNREAD" and subtract to get read messages.

PS: here, SM is storage area in SIM card. others are,

SM. msg storage area on the SIM card.

ME. msg storage area on the GSM/GPRS modem or device. A larger storage space than SIM card(SM).

MT. all msg storage areas associated with the your modem or device. BM. broadcast message storage area. (In some devices, ME & MT -> Flash message storage.) SR. It refers to the status report message storage area. It is used to store status reports.

TA. Terminal Adaptor msg storage area.

Arun Panneerselvam
  • 2,263
  • 1
  • 17
  • 24