How to read SMS with AT on an embedded system with limited memory?

I am developing a piece of firmware that also communicates with the modem via AT protocol. Now I want to read posts, but I am facing a memory size problem. Maybe there are multiple messages for me, and using the AT command set, I return them all at once. I have no memory to store them all to process them (I only have 1KB or so).

See examples here: http://www.smssolutions.net/tutorials/gsm/receivesmsat/

I am sending AT+CMGL="ALL"

. Then I return something like:

+CMGL: 1,"REC UNREAD","+31625012354",,"07/07/05,09:55:16+08"
Test message 1
+CMGL: 2,"REC UNREAD","+31625012354",,"07/07/05,09:56:03+08"
Test message 2

OK

      

The problem is that the message may contain certain directives that trigger certain actions that may take some time to complete. During this time, the buffer for receiving data from the modem may (will) overflow. On the other hand, I have no memory to read ALL messages in memory first to prevent a buffer overflow and then process them from memory.

An alternative is to read one message with AT+CMGR=2

only one message returning:

+CMGL: 2,"REC UNREAD","+31625012354",,"07/07/05,09:56:03+08"
Test message 2

OK

      

However, for this I need to know the storage location (2 in the above example).

I get the feeling that I first start AT+CMGL

by parsing the data and storing only the storage locations, then querying and parsing (and deleting) them one by one with AT+CMGR

.

However, I would like to get a second opinion. I am not that experienced with AT and with firmware, so maybe I am missing something.

+3


source to share


3 answers


Send AT+CMGL="ALL"

and save the first message until you return. Ignore all other data until you get it OK

, showing that the modem is complete. After processing the first message, delete it by sending AT+CMGD=<NUM>

(where is the number of the first message). Repeat.



Yes, it's disgusting, but it works great.

+3


source


There is an unsolicited message that can be configured for newly received SMS messages. See this question for more information on system setup.

Whenever you receive a message +CMTI

, the index field (the number at the end of the line can be used when reading the message, just pass this value to the command AT+CMGR

to get the last message received.



I would recommend deleting old (in use) messages as most builtins like modules have very limited memory for storing messages.

+2


source


Another solution that I am using. Send AT+CPMS

to find out how many messages are stored in the internal memory of the SIM card and what is the capacity (number of messages) in the memory.

If AT+CPMS

it reports that one or more messages are expected in memory, send AT+CMGR

starting at position 1. You will end up with one message (perhaps at position 2 or 10) that you can receive and parse.

After processing it, delete it with AT+CMGD

(you are now its position).

+1


source







All Articles