Send SMS using AT commands

04 Feb.,2024

 

You are here:

SMSSolutions.net > Tutorials > GSM Modem tutorials > Send SMS using AT commands

Send SMS using AT commands

Some advanced gsm modems like WaveCom and Multitech, support the SMS text mode. This mode allows you to send SMS messages using AT commands, without the need to encode the binairy PDU field of the SMS first. This is done by the GSM modem

Check if your GSM phone or modem supports SMS text mode

To check if your modem supports this text mode, you can try the following command:

AT+CMGF=1 <ENTER>

If the modem reponds with "OK" this mode is supported. Please note that using this mode it is onluy possible to send simple text messages. It is not possible to send multipart, Unicode, data and other types of messages.

Setting up the modem

If the modem contains a SIM card with is secured with a PIN code, we have to enter this pin code first:

AT+CPIN="0000" <ENTER>&nbsp (replace 0000 with your PIN code).

&nbsp (replace 0000 with your PIN code).

Please not that in most cases you have only 3 attemps to set the correct PIN code. After setting the PIN code, wait some seconds before issueing the next command to give the modem some time to register with the GSM network.

In order to send a SMS, the modem has to be put in SMS text mode first using the following command:

AT+CMGF=1 <ENTER>

In text mode there are some additional parameters that can be set. Using the following command we can read the current values:

AT+CSMP? <ENTER>

The modem will reponse with a string like this:

+CSMP: 1,169,0,0OK

The first value is a combination of some option bits:

bit 7 RP Reply path, not used in text mode bit 6 UDHI User Data Header Information bit 5 SRR Set this bit to request a delivery report bit 3,4 VPF Validity Period, set b4=1 if a VP value is present bit 2 RD Reject Duplicates, do not return a message ID when a message with the same destination and ID is still pending bit 0,1 MTI Message Type Indicatorb1=0 & b0=0 -> SMS-DELIVERb1=0 & b0=1 -> SMS-SUBMIT

Bit 0 of the message is always set when sending messages (SMS-SUBMIT). So the first value should be 1 or higher. The second parameter sets the Validity Period of the message. This value is encoded as follows:

0 - 143 (VP + 1) x 5 minutes 144 - 167 12 Hours + ((VP-143) x 30 minutes) 168 - 196 (VP-166) x 1 day 197 - 255 (VP-192) x 1 week

The third parameter contains the PID (Protocol Identifier). This parameter is only used for advanced messaging. The fourth parameter contains the DCS (Data Coding Scheme). This parameter is used to select the characterset/messagetype. When setting the DCS parameter to '0' standard 7 bit text is send. When setting this parameter to '16' the message is sent as a flash message.

To send a message with a validity period of 1 day, the parameters have to be set like this:

Bit 0 and 4 of the first field has to be set, so the first value will become 1 + 16 = 17.

Send the following command to the modem to set this parameters:

AT+CSMP=17,167,0,16 <ENTER>

If the modem responds with "OK" ,the modem is ready to send (flash) text messages with a validity period of 1 day.

Sending the message

To send the SMS message, type the following command:

AT+CMGS="+31638740161" <ENTER>

Replace the above phone number with your own cell phone number. The modem will respond with:

>

You can now type the message text and send the message using the <CTRL>-<Z> key combination:

Hello World ! <CTRL-Z>

After some seconds the modem will respond with the message ID of the message, indicating that the message was sent correctly:

+CMGS: 62

The message will arrive on the mobile phone shortly.

Sending an Unicode SMS message

Some modems also have the capability to send Unicode or UCS2 messages without encoding a PDU. You can send Unicode messages by only converting the Unicode data to a HEX string and send this string to the modem.

To check whether your modem supports this mode, just type the following command:

AT+CSCS=?

This commands displays the codepages supported by the modem. The modem will respond like this:

+CSCS: ("GSM","PCCP437","CUSTOM","HEX")

If this string contains "HEX" or "UCS2", Unicode seems to be supported. To specify that you will use an HEX string to send the message, set the codepage to "HEX" or "UCS2" depending on the modem response. In our example we will set the modem to "HEX" :

AT+CSCS="HEX" <ENTER>

Next, we have to specify the correct DCS (Data Coding Scheme) for Unicode messages, which is 0x08. We can set this value by changing the fourth parameter of the AT+CSMP command to '8':

AT+CSMP=1,167,0,8 <ENTER>

The modem is now ready to send messages as Unicode. Now is the time to send the actual message:

AT+CMGS="+31638740161" <ENTER>

Replace the above phone number with your own cell phone number. The modem will respond with:

>

The only thing you have to program by yourself, is a simple routine which converts the Unicode string to an hexidecimal string like this:

مرحبا

مرحبا

Which is 'Hello' in arabic will be converted like this:

"06450631062D06280627"

"06450631062D06280627"

You can send this hexidecimal string to the modem:

06450631062D06280627 <CTRL-Z>

After some seconds the modem will respond with the message ID of the message, indicating that the message was sent correctly:

+CMGS: 63

The message will arrive on the mobile phone shortly.