PDA

View Full Version : How to sort or list received "UNREAD" SMS messages



flotulopex
- 28th January 2021, 21:06
Hi all,

I'm banging my head playing around with AT commands to find a way to list received SMS messages without changing their status (REC READ, REC UNREAD, etc).

AS a matter of fact, if my GSM controller receives i.e. five messages in a row, how do I read them sequentially, parse them, execute whatever it needs with my microcontroller and finally delete them one-by-one?

Using the AT+CMGL="ALL" command will list all received messages but it will also change their status from "REC UNREAD" to "REC READ". Anyway, it doesn't help me to establish a list of messages I will have to parse.

With the AT+CMGR=n command, I point to the message at index n only not knowing all other indexes.

In fact, I don't know how to sort the received SMS messages to make sure I won't miss any one of them.

Any directions on how I should handle this please?

pedja089
- 29th January 2021, 08:53
Read one by one UNREAD MSG. And let modem take care of rest. So there is a lot advantage, letting modem change status to read.
If you read all unread msg, you wont miss any.
And if you do it quickly, you will have one or non msg to read.
For parsing msg, search forum for string parser using arrayread.

flotulopex
- 30th January 2021, 17:52
Hi pedja089,


Read one by one UNREAD MSG
I think, that's where I'm currently stuck - I have no idea how to achieve this (appart from using command AT+CMGR=n but this implies I have listed/sored the message's index before), reading messages one-by-one. All AT commands I know will list the SMS messages and (unfortunately) change their status from "REC UNREAD" to "REC READ" despite I didn't really read them.

I just noticed that, whenever an SMS message is received by the SIM7600E module I use, I get this through the UART interface:
+CMTI: "SM",n where "n" is the number (or index) of this SMS message.

I could store the message's index into an array an treat them on-by-one. But what if I miss one of these +CMTI information? What if my PIC is doing something else than "listening" to incoming messages?

I'm confused since I can't make sure that I wont miss any incoming message.

Since I don't see how to list unread messages one-by-one (can't find any info about this way of doing), should I go for listing all "REC UNREAD" messages and store their index in a list and parse them from now on "one-by-one"? Is this the way?

pedja089
- 30th January 2021, 18:09
Oh, I see now...

Use AT+CMGR=<index>, and just list all indexes.
And delete that index as soon as PIC receive whole MSG.
Also you can use AT+CMGL="ALL",1 to not change status...
EDIT:

https://simcom.ee/documents/SIM900/SIM900_AT%20Command%20Manual_V1.11.pdf

Look at 4.2.3 AT+CMGL and 4.2.4 AT+CMGR

flotulopex
- 30th January 2021, 18:19
Also you can use AT+CMGL="ALL",1 to not change status...

Okay, this is new to me.

I'll give it a try right now - thanks a lot :wink:

pedja089
- 30th January 2021, 18:24
Look at EDIT in prev. post.
But I prefer described way, to list index one by one, and when pic receive MSG delete.
Do this one per second, and I cant have more than 1 or 2 unread msg. And then it is easy to get correct order, and everything else.
I have done that in past, if I can remember...

flotulopex
- 30th January 2021, 18:26
Well, the AT+CMGL="ALL",1 doesn't exist (at least not for the SIM7600E module).

What it's datsheet says:
9005

flotulopex
- 30th January 2021, 18:27
Thanks pedja089, I'll give it a try the way you suggest :smile: