First of all, thank this article to give me a huge help!
TE sends "At CMGL" instructions, and ME outputs short messages that have been received and stored. This is more in line with the spirit of the AT command: If you ask an answer, a question and answer. But in practical applications, it is found that there is a certain disadvantage:
The Me receives the message and stores it. When the query is transferred to the TE, there will always be a delay in the middle. This delay depends on the query interval. Once the instruction is issued, no matter how many messages are there, there is always a long latency TE to receive the final "OK". The complete process generally lasts for 5-10 seconds. This article describes a method of receiving a short message by serial port "real-time". When ME receives a message, actively issue notification to TE, or forward the message to the TE. Compared to the query mechanism, it is similar to the interrupt mechanism. First, a short message concept: the short message is divided into Class 0 - 3 according to the specified location. You can also specify a class (No class), and the ME is processed by the default setting, stored in a memory or SIM card. In the TPDU's TP-DCS byte, when bit7-bit4 is 00x1, 01x1, 1111, bit1-bit0 pointers the category of the message: 00 - Class 0: Only display, not stored 01 - Class 1: Store in ME memory 02 - Class 2: Store in the SIM card 03 - Class 3: Direct transfer to TE GSM Modem generally support a "At CNMI" instruction, how to set it when there is a short message to arrive, how to deal with: only Store in the specified memory (volatile / non-volatile), first store to notify TE, or forward directly to TE, and so on. "AT CNMI" instruction syntax is AT CNMI = [
AT CNMI =? (See the range of settings that can be supported)
CNMI: (0-2), (0-3), (0, 2, 3), (0, 1), (0, 1)
OK
AT CNMI? (See the current settings)
CNMI: 0, 0, 0, 0, 0
OK
AT CNMI = 2, 1 (set to mod = 2, MT = 1) OK
AT CNMI? (Then view the current settings)
CNMI: 2, 1, 0, 0
OK
(After a while, there is a message arrival)
CMTI "ME", 8 (Notification: Message has been stored in ME memory, serial number 8)
AT CMGR = 8 (read Article 8 Message)
CMGR: 8, 27
0891683108200505f0240d91683158812764f8000040205211037380074119058341E01
OK
AT CMGD = 8 (Delete Article 8 Message)
OK
There is also a way Mode = 2, MT = 2 is also very interesting. In this way, in addition to the Class 2, the message is not stored, directly forward to TE. There are two cases of writing notifications and content, complex. However, if the sender is also controlled by the program, only the NO Class or Class 1 message, which is not stored in the receiver ME memory (typically flash, non-volatile), will definitely extend its service life. The communication process between TE and ME is as follows: AT CNMI = 2, 2 (set to Mode = 2, MT = 2)
OK
(After a while, there is a message arrival)
CMT:, 26
0891683108200505F0040D91683158812764F8000840205211639180064F60597D0021