You are on page 1of 17

GSM TUTORIAL

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> (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,0O K The first value is a combination of some option bits:

bit bit bit bit

7 6 5 3,4

RP UDHI SRR VPF RD MTI

bit 2 bit 0,1

Reply path, not used in text mode User Data Header Information Set this bit to request a delivery report Validity Period, set b4=1 if a VP value is present Reject Duplicates, do not return a message ID when a message with the same destination and ID is still pending 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 144 - 167 168 - 196 197 - 255 (VP + 1) x 5 minutes 12 Hours + ((VP-143) x 30 minutes) (VP-166) x 1 day (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" 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.

Receiving SMS messages using AT commands


Introduction Some advanced GSM modems like WaveCom and Multitech, support the SMS text mode. This mode allows you to send and receive SMS messages using AT commands, without the need to decode the binairy PDU field of the SMS first. This is done by the GSM modem. To send the commands discussed in this tutorial, you can use a terminal program, for instance Hyperterminal. 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> (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> If the modem responds with error, either the modem does not support SMS text mode, or the SIM card is not ready. In this case please check that the SIM card is inserted and the pincode is entered. You can also turn on extended error reports by using the following command: AT+CMEE=1 <ENTER> Instead of just an "ERROR" the modem will now respond with "+CMS ERROR: xxx" or "+CME ERROR: xxx". For a list of possible error codes please check this list. Selecting the preferred message storage

A GSM phone or modem receives messages automatically. Basically you are just retrieving the messages from the memory of the device or SIM card. To select the message storage used to read the messages from, you have to use the "AT+CPMS" command. You can select one of the following message storages, not all storages are supported on every device. Storage ID Description SM Read SMS messages from the SIM card. This storage is supported on every GSM phone, because a SIM card should always be present. Usually a SIM card can store up to 15 messages. Read SMS messages from the modem or mobile phone memory. The number of messages that can be stored here depends on the size of the phones memory. Read SMS messages from all storages on the mobile phone. For instance when the phone supports "ME" and "SM", the "MT" memory combines the "ME" and "SM" memories as if it was a single storage. This storage is only used to read stored incoming cell broadcast messages. It is normally not used to store SMS messages. When you enable status reports when sending SMS messages, the status reports that are received are stored in this memory. These reports can read the same way as SMS messages.

ME

MT

BM

SR

To find out which storages are supported by your mobile phone, use the command line below: AT+CPMS=? The modem will respond with a list of supported storages, for instance: +CPMS: (("SM","BM","SR"),("SM")) The storage can be selected using the following command: AT+CPMS=<read>[,<send>,<receive>] <ENTER> The first parameter sets the storage to read from the second optional specifies the storage to send messages from and the last optional parameter tells the device where to store newly received messages. For example, to read messages from the SIM card use: AT+CPMS="SM" <ENTER> The modem should respond with the following string:

+CPMS: <used_space>,<max_space> <ENTER> The used_space indicates the number of messages currently in this memory, the max_space the number of messages that can be stored. Listing the messages Once you have successfully set the messages storage, you can list the messages available using the list command: AT+CMGL="ALL" <ENTER> Please not that "ALL" has to be send in uppercase on some modems. The modem will respond with a list of decoded SMS messages: +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 response messages are formatted like this: +CMGL: <index>,<status>,<from_address>,<mr>,<scts><CRLF><data> index status from_address mr scts data The memory index number, use this index to read or delete this message.

The status of this message. For received messages this can be "REC READ" or "REC UNREAD" on whether the messages has been read or listed before. The subscriber number of the person who sent the message. The reference number of this message. Most modems keep this field empty. The time the message was forwarded to this phone or modem. The actual message data in plain text

Reading a message To list a single message, you have to use the read command. You must use the list command first, so you know the indexes of the messages in the storage. For instance, to read the message on memory location '2' use: AT+CMGR=2 <ENTER>

The modem will list the single message: +CMGR: "REC READ","+31625012254",,"07/07/05,09:56:03+08" Test message 2 OK Please note that the status of the message is now "REC_READ" instead of "REC_UNREAD" because we read the message. Deleting a message Once you have read a message, you can free the memory by deleting the message from the storage. For instance, to delete the message on memory location '2' use: AT+CMGD=2 <ENTER> The modem will delete the single message.

GSM Equipment and Network Error Codes


When controlling GSM devices using AT commands, the device can respond with either "OK" or "ERROR". Sometimes you will receive an error and you do not know the cause of this error. That's why most advanced GSM devices support extended errors. Instead of just displaying the "ERROR" message, it also shows an error number. The syntax of this extended error is either "+CMS ERROR: xxx" or "+CME ERROR: xxx".

When the error starts with "+CME ERROR", it means that the error is a device specific error code. For instance, you are trying to read a phonebook entry before entering a pincode. When there is a network error, for instance, when you try to send an SMS message when there is no network coverage, you will receive an error which starts with "+CMS ERROR". To enable these extended commands, execute the following commands, or add them to your modems init string: AT+CMEE=1 AT&W Below you can find a list containing almost every error code supported by GSM devices. We try to keep this list up to date, so please send your comments to webmaster@smssolutions.net or post them in our forum.
CME ERROR's (GSM Equipment related codes)
Error CME ERROR: 0 CME ERROR: 1 CME ERROR: 2 CME ERROR: 3 CME ERROR: 4 CME ERROR: 5 CME ERROR: 6 CME ERROR: 7 CME ERROR: 10 CME ERROR: 11 CME ERROR: 12 CME ERROR: 13 CME ERROR: 14 CME ERROR: 15 CME ERROR: 16 CME ERROR: 17 CME ERROR: 18 CME ERROR: 20 Description Phone failure No connection to phone Phone adapter link reserved Operation not allowed Operation not supported PH_SIM PIN required PH_FSIM PIN required PH_FSIM PUK required SIM not inserted SIM PIN required SIM PUK required SIM failure SIM busy SIM wrong Incorrect password SIM PIN2 required SIM PUK2 required Memory full

Error CME ERROR: 21 CME ERROR: 22 CME ERROR: 23 CME ERROR: 24 CME ERROR: 25 CME ERROR: 26 CME ERROR: 27 CME ERROR: 30 CME ERROR: 31 CME ERROR: 32 CME ERROR: 40 CME ERROR: 41 CME ERROR: 42 CME ERROR: 43 CME ERROR: 44 CME ERROR: 45 CME ERROR: 46 CME ERROR: 47 CME ERROR: 48

Description Invalid index Not found Memory failure Text string too long Invalid characters in text string Dial string too long Invalid characters in dial string No network service Network timeout Network not allowed, emergency calls only Network personalization PIN required Network personalization PUK required Network subset personalization PIN required Network subset personalization PUK required Service provider personalization PIN required Service provider personalization PUK required Corporate personalization PIN required Corporate personalization PUK required PH-SIM PUK required

CME ERROR: 100 Unknown error CME ERROR: 103 Illegal MS CME ERROR: 106 Illegal ME CME ERROR: 107 GPRS services not allowed CME ERROR: 111 PLMN not allowed CME ERROR: 112 Location area not allowed CME ERROR: 113 Roaming not allowed in this location area CME ERROR: 126 Operation temporary not allowed CME ERROR: 132 Service operation not supported CME ERROR: 133 Requested service option not subscribed CME ERROR: 134 Service option temporary out of order

10

Error

Description

CME ERROR: 148 Unspecified GPRS error CME ERROR: 149 PDP authentication failure CME ERROR: 150 Invalid mobile class CME ERROR: 256 Operation temporarily not allowed CME ERROR: 257 Call barred CME ERROR: 258 Phone is busy CME ERROR: 259 User abort CME ERROR: 260 Invalid dial string CME ERROR: 261 SS not executed CME ERROR: 262 SIM Blocked CME ERROR: 263 Invalid block CME ERROR: 772 SIM powered down

CMS ERROR's (GSM Network related codes) Error CMS ERROR: 1 CMS ERROR: 8 CMS ERROR: 10 CMS ERROR: 21 CMS ERROR: 27 CMS ERROR: 28 CMS ERROR: 29 CMS ERROR: 30 CMS ERROR: 38 CMS ERROR: 41 CMS ERROR: 42 CMS ERROR: 47 CMS ERROR: 50 CMS ERROR: 69 Description Unassigned number Operator determined barring Call bared Short message transfer rejected Destination out of service Unindentified subscriber Facility rejected Unknown subscriber Network out of order Temporary failure Congestion Recources unavailable Requested facility not subscribed Requested facility not implemented

11

Error

Description

CMS ERROR: 81 CMS ERROR: 95 CMS ERROR: 96 CMS ERROR: 97 CMS ERROR: 98 CMS ERROR: 99

Invalid short message transfer reference value Invalid message unspecified Invalid mandatory information Message type non existent or not implemented Message not compatible with short message protocol Information element non-existent or not implemente

CMS ERROR: 111 Protocol error, unspecified CMS ERROR: 127 Internetworking , unspecified CMS ERROR: 128 Telematic internetworking not supported CMS ERROR: 129 Short message type 0 not supported CMS ERROR: 130 Cannot replace short message CMS ERROR: 143 Unspecified TP-PID error CMS ERROR: 144 Data code scheme not supported CMS ERROR: 145 Message class not supported CMS ERROR: 159 Unspecified TP-DCS error CMS ERROR: 160 Command cannot be actioned CMS ERROR: 161 Command unsupported CMS ERROR: 175 Unspecified TP-Command error CMS ERROR: 176 TPDU not supported CMS ERROR: 192 SC busy CMS ERROR: 193 No SC subscription CMS ERROR: 194 SC System failure CMS ERROR: 195 Invalid SME address CMS ERROR: 196 Destination SME barred CMS ERROR: 197 SM Rejected-Duplicate SM CMS ERROR: 198 TP-VPF not supported CMS ERROR: 199 TP-VP not supported CMS ERROR: 208 D0 SIM SMS Storage full CMS ERROR: 209 No SMS Storage capability in SIM

12

Error

Description

CMS ERROR: 210 Error in MS CMS ERROR: 211 Memory capacity exceeded CMS ERROR: 212 Sim application toolkit busy CMS ERROR: 213 SIM data download error CMS ERROR: 255 Unspecified error cause CMS ERROR: 300 ME Failure CMS ERROR: 301 SMS service of ME reserved CMS ERROR: 302 Operation not allowed CMS ERROR: 303 Operation not supported CMS ERROR: 304 Invalid PDU mode parameter CMS ERROR: 305 Invalid Text mode parameter CMS ERROR: 310 SIM not inserted CMS ERROR: 311 SIM PIN required CMS ERROR: 312 PH-SIM PIN required CMS ERROR: 313 SIM failure CMS ERROR: 314 SIM busy CMS ERROR: 315 SIM wrong CMS ERROR: 316 SIM PUK required CMS ERROR: 317 SIM PIN2 required CMS ERROR: 318 SIM PUK2 required CMS ERROR: 320 Memory failure CMS ERROR: 321 Invalid memory index CMS ERROR: 322 Memory full CMS ERROR: 330 SMSC address unknown CMS ERROR: 331 No network service CMS ERROR: 332 Network timeout CMS ERROR: 340 No +CNMA expected CMS ERROR: 500 Unknown error CMS ERROR: 512 User abort

13

Error

Description

CMS ERROR: 513 Unable to store CMS ERROR: 514 Invalid Status CMS ERROR: 515 Device busy or Invalid Character in string CMS ERROR: 516 Invalid length CMS ERROR: 517 Invalid character in PDU CMS ERROR: 518 Invalid parameter CMS ERROR: 519 Invalid length or character CMS ERROR: 520 Invalid character in text CMS ERROR: 521 Timer expired CMS ERROR: 522 Operation temporary not allowed CMS ERROR: 532 SIM not ready CMS ERROR: 534 Cell Broadcast error unknown CMS ERROR: 535 Protocol stack busy CMS ERROR: 538 Invalid parameter

14

SMS Cell Broadcast


SMS Cell Broadcast is designed for simultaneous delivery of messages to multiple users in a specified area. Whereas the Short Message Service (SMS) is a one-to-one and one-to-a-few service, Cell Broadcast is one-to-many geographically focused service. It enables messages to be communicated to multiple mobile phone customers who are located within a given part of its network coverage area at the time the message is broadcast. Cell Broadcast is more akin to other mass distribution media such as teletext or Radio Data System (RDS). SMS Cell Broadcast is defined within Phase 2 of the GSM standard in GSM 03.49. Cell Broadcast has some similarities with SMS since both services use the GSM network's signaling path. A (Each) Cell Broadcast message may be from 1 to 15 pages in length. Each page can be up to 93 alphanumeric characters or 82 octets of binary data in length. Additionally, up to 15 Cell Broadcast messages can be concatenated. Cell Broadcast messages are transmitted to the applicable Base Station Controllers (BSCs) for subsequent broadcast. The Message Destination is described in terms of cell identifiers which the BSC uses to route the message content to Base Transceiver Station Cells. Messages are broadcast for a user defined number of broadcasts with a user specified broadcast repetition rate. Cell Broadcast messages may be updated or removed from the BSC and subsequent BTS/ Cells anytime during the message broadcast period. (The BTSs are selected to determine the area over which the message is broadcast). On Cell Broadcast the GSM operators send different news or data. Often they offer business news, weather forcast and so one. The German GSM operator Mannesmann D2 offers a way to build your own Cell Broadcast channel. The costs of that service will be charged to the owner of the service, to the user of that service or the costs can be shared.

What are DTMF tones ? There are companies which have a telephone system which can be controlled by DTMF tones (for instance: pager systems). To use these services you need to have a phone which is capable to send DTMF tones. DTMF stands for Dual Tone Multiple Frequency. When a key on the phone is pressed during a phone call this character is send using DTMF. The following characters can be send using DTMF: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,* and #. The DTMF keypad is laid out in a 4? matrix, with each row representing a low frequency, and 4 each column representing a high frequency (see table). Pressing a single key such as '1' will send a sinusoidal tone of the two frequencies 697 and 1209 hertz (Hz). The original keypads had levers inside, so each button activated two contacts. The multiple tones are the reason for

15

calling the system multifrequency. These tones are then decoded by the switching center to determine which key was pressed. 1209Hz 1 4 7 * 1336Hz 2 5 8 0 1477Hz 3 6 9 # 1633Hz A B C D

697Hz 770 852Hz 941Hz

How to send DTMF tones Of course you can send DTMF phones using your fixed line phone or cellphone, but if you want to automate the sending of these tones over a phone connection, it becomes difficult because most modems can only send DTMF to dial a number, but when the connection is made, there is no way to send these tones. Some GSM modems do have this featuresuch as the WaveCom and the Multitech GSM modems. Sending DTMF tones using a GSM modem The following code sample demonstrates how to send a numeric text message to a pager using a GSM modem. The sample checks if there is a PIN code on the SIM card in the GSM modem and sets the code. If the code is correct, the modem will dial the number in voice mode, waits till the connection has been established and sends the DTMF code. Finally, the connection is terminated. The following AT Commands are used: ATDxxxxxxxxxxxxxxx; The ATD command is used to dial a number. The semi-colon at the end of this number indicates that this connection has to be setup as a voice call. When leaving this semi-colon, the connection is set up as a data call. AT+VTD=xx This command is optional, and is used to set the DTMF tone duration in 100mS steps. AT+VTS=x To send the actual DTMF code, you have to call this command for every digit sent. To send, for instance "*1234#", you have to send: AT+VTD=*;+VTD=1;+VTD=2;+VTD=3;+VTD=4;+VTD=# ATH0

16

Terminates the phone connection (hangup).

17

You might also like