Click here to Skip to main content
Click here to Skip to main content

Introduction to AT commands and its uses

, 4 Jun 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
In this article, I will give you a brief introduction of AT commands and its uses.

Introduction

AT commands are instructions used to control a modem. AT is the abbreviation of ATtention. Every command line starts with "AT" or "at". That's why modem commands are called AT commands.

Note that the starting "AT" is the prefix that informs the modem about the start of a command line. It is not part of the AT command name. For example, D is the actual AT command name in ATD, and +CMGS is the actual AT command name in AT+CMGS.

Tasks Performed by AT Commands

Here are some of the tasks that can be done using AT commands with a GSM/GPRS modem or mobile phone:

  • Get basic information about the mobile phone or GSM/GPRS modem. For example, name of the manufacturer (AT+CGMI), model number (AT+CGMM), IMEI number (International Mobile Equipment Identity) (AT+CGSN), and the software version (AT+CGMR).
  • Get basic information about the subscriber. For example, MSISDN (AT+CNUM) and IMSI number (International Mobile Subscriber Identity) (AT+CIMI).
  • Get the current status of the mobile phone or GSM/GPRS modem. For example, mobile phone activity status (AT+CPAS), mobile network registration status (AT+CREG), radio signal strength (AT+CSQ), battery charge level, and battery charging status (AT+CBC).
  • Establish a data connection or voice connection to a remote modem (ATD, ATA, etc.).
  • Send and receive fax (ATD, ATA, AT+F*).
  • Send (AT+CMGS, AT+CMSS), read (AT+CMGR, AT+CMGL), write (AT+CMGW), or delete (AT+CMGD) SMS messages and obtain notifications of newly received SMS messages (AT+CNMI).
  • Read (AT+CPBR), write (AT+CPBW), or search (AT+CPBF) phonebook entries.
  • Perform security-related tasks, such as opening or closing facility locks (AT+CLCK), checking whether a facility is locked (AT+CLCK), and changing passwords (AT+CPWD). (Facility lock examples: SIM lock [a password must be given to the SIM card every time the mobile phone is switched on] and PH-SIM lock [a certain SIM card is associated with the mobile phone; to use other SIM cards with the mobile phone, a password must be entered.])
  • Control the presentation of result codes / error messages of AT commands. For example, you can control whether to enable certain error messages (AT+CMEE), and whether error messages should be displayed in numeric format or verbose format (AT+CMEE=1 or AT+CMEE=2).
  • Get or change the configurations of the mobile phone or GSM/GPRS modem. For example, change the GSM network (AT+COPS), bearer service type (AT+CBST), radio link protocol parameters (AT+CRLP), SMS center address (AT+CSCA), and storage of SMS messages (AT+CPMS).
  • Save and restore configurations of the mobile phone or GSM/GPRS modem. For example, save (AT+CSAS) and restore (AT+CRES) settings related to SMS messaging such as the SMS center address.

Note that mobile phone manufacturers usually do not implement all AT commands, command parameters, and parameter values in their mobile phones. Also, the behavior of the implemented AT commands may be different from that defined in the standard. In general, GSM/GPRS modems designed for wireless applications have better support of AT commands than ordinary mobile phones.

Types of AT Commands

There are two types of AT commands:

  1. Basic commands are AT commands that do not start with "+". For example, D (Dial), A (Answer), H (Hook control), and O (Return to online data state) are basic commands.
  2. Extended commands are AT commands that start with "+". All GSM AT commands are extended commands. For example, +CMGS (Send SMS message), +CMGL (List SMS messages), and +CMGR (Read SMS messages) are extended commands.

General Syntax of AT Commands

The general syntax of extended AT commands is straightforward. The syntax rules are provided below:

Syntax rule 1. All command lines must start with "AT" and end with a carriage return character. In a terminal program like the HyperTerminal of Microsoft Windows, you can press the Enter key on the keyboard to output a carriage return character.

Example: To list all unread inbound SMS messages stored in the message storage area, type "AT", then the extended AT command "+CMGL", and finally a carriage return character, like this:

AT+CMGL<CR>

Syntax rule 2. A command line can contain more than one AT command. Only the first AT command should be prefixed with "AT". AT commands in the same command-line string should be separated with semicolons.

Example: To list all unread inbound SMS messages stored in the message storage area and obtain the manufacturer name of the mobile device, type "AT", then the extended AT command "+CMGL", followed by a semicolon and the next extended AT command "+CGMI":

AT+CMGL;+CGMI<CR>

An error will occur if both AT commands are prefixed with "AT", like this:

AT+CMGL;AT+CGMI<CR>

Syntax rule 3. A string is enclosed between double quotes.

Example: To read all SMS messages from a message storage in SMS text mode, you need to assign the string "ALL" to the extended AT command +CMGL, like this:

AT+CMGL="ALL"<CR>

Syntax rule 4. Information responses and result codes (including both final result codes and unsolicited result codes) always start and end with a carriage return character and a linefeed character.

Example: After sending the command line "AT+CGMI<CR>" to the mobile device, the mobile device should return a response similar to this:

<CR><LF>Nokia<CR><LF>
<CR><LF>OK<CR><LF>

The first line is the information response of the AT command +CGMI, and the second line is the final result code. <CR> and <LF> represent a carriage return character and a linefeed character, respectively. The final result code "OK" marks the end of the response. It indicates no more data will be sent from the mobile device to the computer / PC.

When a terminal program such as the HyperTerminal of Microsoft Windows sees a carriage return character, it moves the cursor to the beginning of the current line. When it sees a linefeed character, it moves the cursor to the same position on the next line. Hence, the command line "AT+CGMI<CR>" that you entered and the corresponding response will be displayed like this in a terminal program such as HyperTerminal of Microsoft Windows:

AT+CGMI
Nokia

OK

Information Response and Final Result Code

AT+CGMI  <-- Command line entered
Nokia  <-- Information response
OK  <-- Final result code

Result Code of AT Commands

Result codes are messages sent from the GSM/GPRS modem or mobile phone to provide you information about the execution of an AT command and the occurrence of an event. Two types of result codes are useful to you when dealing with AT commands for SMS messaging:

  • Final result codes
  • Unsolicited result codes

Final Result Code of AT Commands

A final result code marks the end of an AT command response. It is an indication that the GSM/GPRS modem or mobile phone has finished the execution of a command line. Two frequently used final result codes are OK and ERROR. Only one final result code will be returned for each command line. Thus, you will not see both OK and ERROR in the response of a command line.

The OK Final Result Code

The OK final result code indicates that a command line has been executed successfully by the GSM/GPRS modem or mobile phone. It always starts and ends with a carriage return character and a linefeed character.

The ERROR Final Result Code

The ERROR final result code indicates that an error occurs when the GSM/GPRS modem or mobile phone tries to execute a command line. After the occurrence of an error, the GSM/GPRS modem or mobile phone will not process the remaining AT commands in the command-line string.

Below are some common causes of error:

  1. The syntax of the command line is incorrect.
  2. The value specified to a certain parameter is invalid.
  3. The name of the AT command is spelt incorrectly.
  4. The GSM/GPRS modem or mobile phone does not support one or more of the AT commands, command parameters, or parameter values in the command-line string.

Like the OK final result code, the ERROR final result code always starts and ends with a carriage return character and a linefeed character.

Final Result Code Specific to SMS AT Commands

The final result codes OK and ERROR are available to all AT commands. Unlike OK and ERROR, the +CMS ERROR final result code is only available to SMS AT commands. It notifies you about the occurrence of a message service failure.

Unsolicited Result Codes of AT Commands

Unsolicited result codes are messages sent from the GSM/GPRS modem or mobile phone to provide you information about the occurrence of an event. For example, you can use the +CNMI AT command (command name in text: New Message Indications to TE) to request the GSM/GPRS modem or mobile phone to send the unsolicited result code "+CMTI" to your computer / PC every time a new SMS message is received from the SMS center.

How to Test GSM Modem Connectivity Using HyperTerminal
  • First, find the best GSM modem that suits the needs.
  • Understand the AT Command set required to communicate with the modem.
  • Connect the modem to the computer according to the setup guide specified in the manual provided with the GSM modem.
  • Put a valid SIM card into the mobile phone or GSM/GPRS modem.
  • Connect your mobile phone or GSM/GPRS modem to a computer and set up the corresponding wireless modem driver.
  • Run MS HyperTerminal by selecting Start -> Programs -> Accessories -> Communications -> HyperTerminal.
  • In the Connection Description dialog box, enter a name and choose an icon you like for the connection. Then click the OK button.
  • In the Connect To dialog box, choose the COM port that your mobile phone or GSM/GPRS modem is connecting to in the Connect using combo box. For example, choose COM1 if your mobile phone or GSM/GPRS modem is connecting to the COM1 port. Then click the OK button.
  • The Properties dialog box comes out. Enter the correct port settings for your mobile phone or GSM/GPRS modem. Then click the OK button.
  • To find the correct port settings that should be used with your mobile phone or GSM/GPRS modem, consult the manual of your mobile phone or GSM/GPRS modem.
  • Type "AT" in the main window. A response "OK" should be returned from the mobile phone or GSM/GPRS modem.
  • If "OK" returns, it means your mobile phone or GSM/GPRS modem is connected successfully Smile | :) .

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Syeda Anila Nusrat
Software Developer
Pakistan Pakistan
Name: Syeda Anila Nusrat
 
Education:-
National University of Computer and Emerging Sciences
MS (Computer Science) 2010–2012
Federal Urdu University of Arts, Science and Technology
BS (Computer Science) 2004–2007
 
Professional Experience:-
Software Engineer at Systems Pvt Ltd (Nov 2010-Mar 2011)
Software Engineer at Syndustria Pvt Ltd (Jun2008-Feb2010)
Software Engineer(internee) at yEvolve Pvt Ltd (Feb2008-Apr 2008)
 
Specialties:-
IDE: Ms Visual Studio 2005 and 2008
Programming Languages: C++.NET, C#.NET, VB.NET, ADO.NET
Web Technologies: ASP.NET, AJAX, Html, CSS, Java Scripting
Databases: SQL Server 2000, SQL Server 2005
Programming Methodologies: Multithreading and DLLs
Scheduling and Modeling tools: Ms-Project 2000, MS Visio, Rational Rose
 
Honors and Awards:-
Received Merit Certificate for scoring 3.81 CGPA on scale of 4.0 in BS(CS)
 
My professional Network
http://pk.linkedin.com/in/syedaanila

Comments and Discussions

 
GeneralMy vote of 2 PinmemberBonheur Yumba24-Jan-14 1:35 
QuestionUse at commands in C# application PinmemberMember 1029939328-Dec-13 19:13 
QuestionWhat if SMS message contains <CR><LF>OK<CR><LF>? Pinmemberdgi19-Nov-13 22:43 
QuestionIVR Calls through GSM modem PinmemberUzair Saleem Cheema7-Jun-13 0:56 
GeneralMy vote of 5 PinmemberAnisuzzaman Sumon6-Jun-13 12:11 
QuestionFeed Back Pinmemberfahad jamal uddin29-Jan-13 19:00 
Questionany AT Command for sending Bulk essages PinmemberRaziSadiq25-Dec-12 2:12 
GeneralMy vote of 5 PinmemberJITHIL P PONNAN18-Nov-12 19:16 
Questionusing huawei e1550 Pinmembernaq_ninetwo9230-Sep-12 1:48 
GeneralI Want a Code Pinmemberkumar.bravo25-Apr-12 20:28 
QuestionRecord mobile calls on PC Pinmemberpankaj motiyar12-Feb-12 20:56 
QuestionRe: Record mobile calls on PC PinmemberPraveen212124-Apr-14 20:56 
Questionbulk sms Pinmemberahsan misbah24-Oct-11 10:24 
GeneralAT command for voice modem PinmemberLittle Daffodil29-Sep-10 1:21 
GeneralMy vote of 2 Pinmemberhotblood30-Aug-10 23:02 
Answeryou rock lady PinmemberNMRKMAN29-Nov-10 14:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 4 Jun 2010
Article Copyright 2010 by Syeda Anila Nusrat
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid