AT commands (or Hayes commands) form the language used to communicate with cellular modems. Whether you’re developing an IoT device, working with M2M applications, or trying to understand how your device talks to cellular networks, understanding “ATtention” or AT commands is essential.
In this comprehensive guide, I’ll walk you through what AT commands are, how they work, and provide practical examples to get you started.
Table of Contents
What are AT commands?
AT commands are a specific command language originally developed for the Hayes Smartmodem in the 1980s. The name “AT” comes from the fact that each command line starts with “AT,” which stands for “Attention.”
AT commands became the standard, text-based way to communicate with modems through the computer via a serial terminal and have evolved to control modern cellular modems in phones, IoT devices, and other connected products.
A typical AT command might look like: AT+CREG?
(which checks the network registration status).
Do different manufacturers have different AT commands?
You’re probably looking to execute commands to your manufactured device by SIMCom, Quectel, Gemalto, U-Blox, and Telit, just to name a few.
Good news: there’s a shared standard across the industry. However, the specific command set can vary between manufacturers and models. Examples include AT+QIOPEN
for Quectel modules and AT+CIPPING
for SIMCom modules.
Additionally, some commands in the standard are optional and may not be present on all modems.
💡AT commands standard: Most cellular modules implement a core set of standardized AT commands. These standards are defined by ITU-T V.250 and 3GPP TS 27.007 / 27.005. ITU (International Telecommunication Union) is the primary standards body for telecom, while 3GPP (3rd Generation Partnership Project) is also crucial. The ITU V.250 standard hasn’t been updated since 2003 and is quite stable. The 3GPP standard, however, has different versions (releases), and commands specified in the newest release might not be available on older modems.
To read more about telecommunication standardizations, this article paints the full picture.
The role of AT Commands in IoT connectivity
If you’re developing any device that needs cellular connectivity (2G, 3G, 4G, LTE, LTE-M, NB-IoT, and even for 5G modems, to name some), AT commands are your primary interface to the modem. They allow you to:
- Configure the modem
- Establish network connections
- Send/receive SMS messages
- Make voice calls
- Transfer data
- Query signal strength and network status
- Perform diagnostics
From setting the Access Point Name (APN), which is a logical name used to select the gateway to the external packet data network, to dialing a data connection, AT commands are the mechanism used to configure and control the modem to get online.
How do AT commands work?
Understanding how AT commands work requires looking at their syntax and interaction flow. Let’s go through them below.
AT commands syntax basics
AT commands have a specific syntax to function correctly, which is typically as seen below:
AT<COMMAND><SUFFIX><DATA>
The basic format is AT followed by the command, a suffix indicating the command type (e.g., setting a value, querying information), and sometimes additional data. Each command line ends with a carriage return, but multiple commands can be strung together on a single line using semicolons.
Core format and structure
- All commands start with
"AT"
(not case-sensitive) followed by an optional+
and then the command:
E.g. AT+CREG
(or at+creg?
or At+CrEg?
) and ATZ
- Arguments for an AT command are comma-separated
E.g. AT+CGDCONT=1,"IP","onomondo"
Setters, getters, and testers
Character/s | What it does | Example |
---|---|---|
= | Sets a value | AT+CGATT=1 |
? | Gets the current status | AT+CREG? |
=? | Queries supported values/ranges for possible arguments | AT+CREG=? |
Chaining Commands
Use of ;
: AT commands which are to be executed sequentially right after each other can be delimited with a ;
and only the first command should include AT
E.g. AT+CREG?;+GGREG?
AT Command responses
Response | What it means | Example |
---|---|---|
OK | Successful command execution | AT+CGATT=1 |
ERROR | Failed command | AT+CREG? |
+CME ERROR: <code> | Extended error for mobile equipment | |
+CMS ERROR: <code> | Error related to SMS functionality | |
ABORTED | The command has been aborted (applies only to some modems) | AT+CREG=? |
Other responses | When the responses above don’t apply, it could prompt for more data |
According to U-Blox, before each transmitted AT command the device communicating with the modem should:
- Wait 20 ms
- Flush the buffer
This helps the device handle unsolicited result codes (URCs), which the modem sends for various events if enabled. A typical URC would be the one coming from network registrations both data- and phone/SMS wise.
Here’s what it looks like when you issue a command to register on the network — with URC and without URC: