GPRS text message sending Method

Source: Internet
Author: User

Recently, I did a simple test on the GPRS module, in which the short message method is relatively simple and also common with other GPRS modules. Now I will write down my debugging notes.

Short Message mode:

I. At commands related to SMS

At + cmgc send an SMS command (send a short message command)

At + cmgd Delete SMS message (Short Message for deleting SIM card memory)

At + cmgf select SMS message formate (select the short message sending and receiving format: 0-pdu; 1-text)

At + cmgl list SMS message from preferred store (list short messages in the SIM card

At + cmgr read SMS message (read short message)

At + cmgs send SMS message (send short message)

At + cmgw write SMS message to memory (write a short message to be sent to the sim memory)

At + CMSS send SMS message from storage (send short messages from sin | M memory)

At + cnmi new SMS message indications (display new short messages)

At + CPMS preferred SMS message storage (select Short Message Memory)

At + csca SMS service center address (Short Message Center address)

At + CSCB select Cell Broadcast messages (select cellular broadcast messages)

At + CSMP set SMS text mode parameters (Set Short Message text mode parameters)

At + CSMs select message service (select short message service)

You can send short messages in PDU and text modes.

2. Send short messages in Chinese and English in PDU Mode

At + cmgf = 0 // first set the Short Message format to PDU Mode

At + CSCs = "ucs2" // set the character format to ucs2 Mode

At + csca = "+ 86138xxxxxxxx", 145 // set the address of the Short Message Service Center

Note: For China Mobile, the text message service center number is + 861380xxxx500, of which XXXX is your long-distance phone area number. If there are less than four digits, add 0. For example, my Beijing is 010, if the value after 0 is 0100, it should be + 8613800100500.

[PDU] The data unit format is defined:

The following example sends "hello" to 13912345678

Sending data is: Hello

Unicode decoding: 4f60597d

At + cmgs = 019 // 15 (PDU protocol header fixed length 15 bytes) + 4 (packet length 4 bytes)

> 0011000d91683119325476f8000801044f60597d [Ctrl-Z]

00 // reserved for SCA

11 // FO: Set the PDU type

00 // Mr sending reference number

0d // da destination number length

91 // da destination number type

68 // da China Region Code

3119325476f8 // da destination number encoding

00 // PID sending Method

08 // DCS encoding Mode

01 // VP Validity Period

The pdu header before user data in the PDU is 15 bytes in length.

04 // udl Data Length

4f60597d // Unicode Decoding of UD data content

In this example, the destination number is a memory encoding method that swaps the location of each two-digit data. The remaining final unit is supplemented with F, for example, 13912345678 is encoded as 3119325476f8. When sending short messages in PDU mode, you only need to change the tpdu's decimal length, mobile phone number encoding, message length, and message content Unicode decoding according to the preceding example.

Set the DCS encoding mode to change the short message sending level:

According to the gsm08.38 protocol, the DCS field (bit7... 0) it is used to set the encoding method and sending level of the Short Message content. bit4 is used to determine whether bit1 and bit0 are valid (1 is valid, 0 is invalid ); bit1 and bit0 are both set to 0, indicating that the short message sending level is 0, that is, they are directly sent to the terminal rather than stored in the SIM card; if bit3 is set to 1 and bit2 is set to 0, the short message content is ucs2 encoded. In the preceding example, the DCS field is 08, indicating that the short message content is ucs2 encoded and has no sending level. If it is changed to 18, the short message content is ucs2 encoded and sent at 0 level, that is, it is directly sent to the destination terminal.

3. Send short messages in text mode

The text mode only supports transmitting English and digital information, but its encoding is much simpler than the PDU mode. Therefore, we recommend that you use the txet mode to send and receive short messages.

1. Send short Chinese messages in text mode

At + cmgf = 1 // set the Short Message format to text

At + CSCs = "ucs2" // set the character format to ucs2 mode:

At + csca = "+ 86138xxxxxxxx", 145 // set the address of the Short Message Service Center

Note: For China Mobile, the text message service center number is + 861380xxxx500, of which XXXX is your long-distance phone area number. If there are less than four digits, add 0. For example, my Beijing is 010, if the value after 0 is 0100, it should be + 8613800100500.

At + CSMP = 17,167, // set parameters for Sending Short Messages: four parameters are fo, VP, PID, and DCS, which indicate that the parameters are the same as those in PDU mode, the difference is that it must be expressed in decimal format. 24 indicates that the short message content is ucs2 encoded and directly sent to the destination terminal. If it is changed to 25, the short message content is ucs2 encoded and sent to the SIM card for storage.

Sent: At + cmgs = mobile phone number code [Cr]

Send a response after receiving [>]

[Unicode Decoding of message content] [Ctrl-Z]

The following example sends "hello" to 13912345678

Sending data is: Hello

Unicode decoding: 4f60597d

At + cmgs = "00310033003900310032003300340035003600370038" // enter the mobile phone number code directly

> 4f60597d [Ctrl-Z]

When sending short messages in text mode, you only need to follow the above example to change the mobile phone number encoding and Unicode decoding of the message content.

2. Send short messages in text mode

At + cmgf = 1 // set the Short Message format to text

At + CSCs = "GSM" // set the character format to GSM

At + csca = "+ 86138xxxxxxxx", 145 // set the address of the Short Message Service Center

Note: For China Mobile, the text message service center number is + 861380xxxx500, of which XXXX is your long-distance phone area number. If there are less than four digits, add 0. For example, my Beijing is 010, if the value after 0 is 0100, it should be + 8613800100500.

At + CSMP = 17,167, 0,240 // set parameters for Sending Short Messages: four parameters are fo, VP, PID, and DCS, which indicate that the parameters are the same as those in PDU mode, the difference is that the short message content must be expressed in decimal format. The value 240 indicates that the short message content is the default GSM Code and is directly sent to the target terminal. If it is changed to 241, the short message content is GSM encoded and sent to the SIM card for storage.

Send: At + cmgs = "13xxxxxxxxx" [Cr]

Send a response after receiving [>]

[Message content] [Ctrl-Z]

The following example sends "hello" to 13912345678

The message is hello.

At + cmgs = "13912345678" // enter the mobile phone number directly

> Hello [Ctrl-Z]

When sending short messages in text mode, you only need to change the mobile phone number and message content according to the preceding example.

The above shows how to send text messages and how to accept the short messages you just received? You can use either the terminal query method or the event Method to receive a short message. The query method is not to process the information sent from the network. The "at + cmgl = 0" command is periodically used to read unread text messages. If yes, the messages are read and handed over to the upper-level program for processing. Then delete the short message. This method is simple, but it is useless and inefficient many times. In reality, we use the event Method to store the received short messages to the SIM card through the at + cnmi command, and return a prompt.

 

The concept of Short Message class: according to the specified storage location, short messages are divided into four categories: Class 0-3. You can also choose not to specify a class (no class), which is processed by me according to the default settings and stored in the memory or SIM card. In the TP-DCS bytes of the tpdu, when the bit7-bit4 is 00x1, 01x1, 1111, The bit1-bit0 points out the message's class:

00-Class 0: display only, not store
01-Class 1: stored in me memory
02-Class 2: stored in SIM card
03-Class 3: directly transmitted to te
Generally, GSM Modem supports an "at + cnmi" command, which can be used to set how to handle a short message when it arrives: it is only stored in the specified memory (easy to lose/non-easy). It is stored first and then notified to the Te, or directly forwarded to the Te.

 

The "at + cnmi" command syntax is

At + cnmi = [<mode> [, <Mt> [, <BM> [, <DS> [, <BFR>]

Mode-notification method:

0-Te is not notified.

1-only notify the Te when the data line is idle; otherwise, the Te is not notified.

2-Notification te. When the data line is occupied, it is buffered first, and then notified when the data line is idle.

3-Notification te. When the data line is occupied, the notification is sent together.

MT-message storage or direct forwarding to te:

0-store to the default memory location (including class 3)

1-store it in the default memory location and send a notification to te (including class 3)

2-for Class 2, store the message to the SIM card and send a notification to te; for other classes, directly forward the message to te

3-for Class 3, messages are directly forwarded to te; for other classes, the same as Mt = 1

For the meanings of BM, DS, and BFR, see the relevant standard documentation. Generally, you do not need to care about them.

In the specific implementation of the program, use mode = 2, MT = "1", that is, at + cnmi =, 0: relatively simple. For all types of short messages, you only need to read the message content using the "at + cmgr" command after receiving the "+ cmti" notification sent by me.

Example:

(Blue indicates the data sent by the PC, and red indicates the data returned by the module)

At + cmgf = 1 // set the Short Message format to text

OK

At + CCS = "csm" // set the character format to GSM

OK

At + csca = "+ 8613800100500", 145 // set the address of the Short Message Service Center

OK

At + cnmi =, 0 // set to receive notifications of concurrent cmti messages stored in the SIM card

OK

 

+ Cmti: "SM", 1 // The message is displayed automatically. 1 indicates the serial number in the sim.

At + cmgr = 1 // read the text message, where 1 corresponds to the serial number above

+ Cmgr: "rec unread", "8615810533873", "09/04/30, 10: 59: 17 + 32", 8613800100500, 36, ",

ABCD // receives a text message from mobile phone 15810533873 with the content of ABCD

 

OK

At + cmgd = 1 // Delete the SMS, where 1 is the SMS serial number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.