GSM Tutorial
GSM Tutorial
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.
If the modem contains a SIM card with is secured with a PIN code, we have to enter this pin
code first:
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>
+CSMP: 1,169,0,0O K
1
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
Reject Duplicates, do not return a message ID when a message
bit 2 RD
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:
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.
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.
AT+CMGS="+31638740161" <ENTER>
Replace the above phone number with your own cell phone number. The modem will respond
with:
>
2
You can now type the message text and send the message using the <CTRL>-<Z> key
combination:
After some seconds the modem will respond with the message ID of the message, indicating
that the message was sent correctly:
+CMGS: 62
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:
>
3
The only thing you have to program by yourself, is a simple routine which converts the Unicode
string to an hexidecimal string like this:
مرحبا
"06450631062D06280627"
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
4
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.
If the modem contains a SIM card with is secured with a PIN code, we have to enter this pin
code first:
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.
5
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
Read SMS messages from the SIM card. This storage is supported on every GSM
SM 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
ME
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
MT 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
BM
normally not used to store SMS messages.
When you enable status reports when sending SMS messages, the status reports
SR that are received are stored in this memory. These reports can read the same way
as SMS messages.
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"))
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.
AT+CPMS="SM" <ENTER>
6
+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.
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:
OK
+CMGL: <index>,<status>,<from_address>,<mr>,<scts><CRLF><data>
index 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"
status
on whether the messages has been read or listed before.
from_address The subscriber number of the person who sent the message.
mr The reference number of this message. Most modems keep this field empty.
scts The time the message was forwarded to this phone or modem.
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>
7
The modem will list the single message:
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>
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".
8
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.
Error Description
9
Error Description
10
Error Description
Error Description
11
Error Description
12
Error Description
13
Error Description
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.
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?4 matrix, with each row representing a low frequency, and
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.
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.
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.
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