# About AT Commands

***

Any developer who must work with a cellular modem will have to make use of what are called 'AT commands' at some point. AT commands are essentially modem instructions. Originally developed by the modem maker Hayes as means to operate their dial-up landline products, AT commands — the 'AT' stands for 'come to ATtention' — are now used by all modems, of all types.

AT commands are primarily used to configure a modem and establish its network connection. They can be used to interact with the modem's SIM, such as a KORE [Super SIM](https://www.korewireless.com/super-sim-card) . They can also be used to get modem and connection status information, and this can be very helpful in debugging applications and in confirming that a modem is operating correctly: it has connected to the right network, is using the correct cellular technology, has roaming enabled, etc. We'll look at some useful commands for tasks like these shortly.

{% hint style="info" %}
This page covers AT commands at a high level. Which AT commands are supported, how to send them, and how to process responses may vary from modem to modem. Refer to your specific modem's AT command documentation to learn more about functionality, including some useful abstractions, is available.
{% endhint %}

***

## How to send AT commands <a href="#how-to-send-at-commands" id="how-to-send-at-commands"></a>

AT commands are sent to the modem as plain text over a serial (UART) connection comprising two wires, one for receive (RX) and one for transmit (TX), or via USB. In the field, a cellular-enabled IoT device will manage its modem by sending it AT commands, but during application development and debugging, it's not uncommon to tap the modem's USB connection. This allows you to fire up a terminal and interact with the modem directly by issuing AT commands of your own. You do this with serial terminal software — just follow the instructions provided below for the computer operating system you're using.

{% tabs %}
{% tab title="Linux" %}

1. Open your distribution's terminal app.
2. Install the command-line serial console tool Minicom using your operating system's package manager, such as `apt`, `rpm`, `dpkg`, or similar, e.g., `sudo apt install minicom`.
3. Get the modem's device file with `ls /dev/ttytUSB*`. It'll be something like `/dev/ttyUSBx` where `x` is 0 or above. You may see multiple devices listed. Your modem's documentation should indicate which one is the modem, but you may need to use trial and error to find it.\
   You may also need to ensure you have access to the serial port: on most distributions this can be done by adding your user account to the `dialout` user group or using `sudo`.
4. Enter `minicom -o -D /dev/ttyUSBx` to open a connection to the module. If Minicom posts an error indicating that the device is inaccessible, you may need to try one of the other devices listed in step&#x20;
   {% endtab %}

{% tab title="macOS" %}

1. Open the Terminal app.
2. Install the command-line serial console tool called Minicom using [Homebrew](https://brew.sh/) with the command `brew install minicom`. You may need to install Homebrew first.
3. Get the modem's device file. Enter `ls /dev/cu*`. You should see a single entry like `/dev/cu.usbmodem14244201`.
4. Enter `minicom -o -D <DEVICE_FILE>` to open a connection to the module. `<DEVICE_FILE>` is the filename you got in step 3. If Minicom posts an error indicating that the device is inaccessible, please check that you've connected the modem to your computer and that you copied its device file name correctly.
   {% endtab %}

{% tab title="Windows 10" %}

1. Open Windows 10's Device Manager. It will show the modem as a USB Serial Device in the **Ports (COM & LPT)** section. Note its COM number.
2. Right-click on the modem's entry in the Device Manager list and select **Properties...** . Select the **Port Settings** tab and note the **Bits per second:** value.
3. [Download and install PuTTY](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html), a terminal emulator for Windows.
4. Run PuTTY, select **Serial** as the **Connection type** , and enter the COM number (for example, `COM3`) in the **Serial line** field. Make sure the **Speed** field is set to match the **Bits per second:** value you got from Device Manager.
5. Click **Open** .
   {% endtab %}
   {% endtabs %}

***

## How to format AT commands <a href="#how-to-format-at-commands" id="how-to-format-at-commands"></a>

The commands you send must obey the following basic syntax:

```
AT<COMMAND><SUFFIX><DATA><CR>
```

This is called a 'command line'. As you can see, it starts with `AT`, followed by a command, a suffix to indicate command mode or 'type', and finally some data, though not all commands need this field to be included.

This structure is called a 'command line' and it is always terminated by a single carriage return, `<CR>`. You can include multiple commands in the line, each separated by a semi-colon:

```
AT<COMMAND><SUFFIX><DATA>;<COMMAND><SUFFIX><DATA>;<COMMAND><SUFFIX><DATA><CR>
```

Every line, no matter how many commands it contains, only has one `AT`, at the start. You'll get an error if you include `AT` more than once in a single line. The commands in multi-command lines are processed sequentially. The line length is usually, but not always, limited to 80 characters. Here's an example:

```
AT+CMEE=2;+CMGF=1;+CMGD=,4;+CNMP=38;+CMNB=1;+CGDCONT=1,"IP","super"
```

This sets error reporting to level 2, sets the modem to text mode, deletes all stored SMS, selects LTE-only mode, selects Cat-M only mode, and sets the APN.

***

## AT command line fields <a href="#at-command-line-fields" id="at-command-line-fields"></a>

The `<COMMAND>` field indicates what you want the modem to do. Older, 'basic' commands have single-character names; later additions to the commands set, called 'extended' commands, are prefixed with a `+` sign, such as `AT+COPS` (scan for networks) and `AT+CGMI` (get modem manufacturer). Some commands are prefixed with & — for example, `AT&F`, which resets the modem's settings. All cellular commands are extended commands. According to the AT command specification, commands must comprise uppercase characters, but many modems allow commands to be sent in lowercase too. We'll stick with the standard.

If you're sending a sequence of AT commands as shown above, make sure you include the `+` or `&` after each semi-colon.

The values of the `<DATA>` and `<SUFFIX>` fields depend on the command type, of which there are four:

| Type    | Suffix | Role                                                                                                                          |
| ------- | ------ | ----------------------------------------------------------------------------------------------------------------------------- |
| Read    | `?`    | Get a modem configuration setting                                                                                             |
| Set     | `=`    | Set a modem configuration setting                                                                                             |
| Execute | None   | Trigger a modem operation                                                                                                     |
| Test    | `=?`   | Check whether a modem supports the named command — but note that `AT+COPS=?` works slightly differently, as we'll see shortly |

We'll see how these types affect the use of AT commands in a moment, but first let's see how the modem responds to commands.

***

## AT command response <a href="#at-command-response" id="at-command-response"></a>

When an AT command is issued, depending on the command sent, the modem may or may not return data, ie. make what's called an 'information response'. Either way, the command operation always ends with the modem returning a 'result code'.

For example, suppose we ask for the name of the modem's manufacturer using the following command:

```
AT+CGMI
```

This will generate the following response when called on a u-blox modem:

```
u-blox

OK
```

Each unit of the response — the information (top line) and the result code (bottom line) — are bracketed by Carriage Return Line Feed characters (Ascii codes `0x0D` and `0x0A`, respectively, or in string form `"\r\n"`), hence the empty line before the `OK`.

`OK` is one return code; the other is `ERROR` — you made a mistake. Perhaps the modem doesn't respond to the AT command you sent, or you mistyped it. Maybe you provided too few or too many data values or command parameters. By default, modems may not provide much in the way of explanation. Fortunately, some of them can be set to return extended error information; again, you'll need to send an AT command to apply this setting: `AT+CMEE=2`.

It's important to understand that you may also receive `ERROR` from a perfectly valid AT command. When this happens, it's an indication that the modem is in state that is incompatible with the command. For example, if you attempt to change a modem's Access Point Name (APN) while it is active, this will typically return `ERROR`. The remedy is to deactivate the modem, make the APN change, and then reactivate it.

***

## AT command types and testing <a href="#at-command-types-and-testing" id="at-command-types-and-testing"></a>

You can mitigate the problem of seemingly correct commands throwing errors by making use of the test command suffix (`=?`), which is used to ask the modem if it supports the given command. If it doesn't, you'll receive an `ERROR` return code; you know not to issue this command. If the modem does support the command, you will receive an information response indicating the command's parameters, if it has any, followed by `OK`.

The example above can be used to demonstrate command testing. We can ask the modem if it supports the `+CGMI` command:

```
AT+CGMI=?
```

and it will return `OK` because it does support this command. However, because the modem's manufacturer is fixed, attempting to change it will always result in `ERROR`. How might we have attempted to change its value? With a set command suffix (`=`):

```
AT+CGMI="Fintlewoodlewix"

ERROR
```

Note how the string data is placed within double quotes — this too is an AT command requirement.

{% hint style="info" %}
There's one key exception to the command test rule: `AT+COPS=?`. This does not report on the availability of the `+COPS` command, but instead triggers a network scan and reports the results. `AT+COPS?` reports the network to which the modem is currently connected.
{% endhint %}

Test mode can also be used to determine what parameters a supported command takes. For example, if you send the command `+CBC` in test mode (it asks the modem what its current battery level is) you will get a result indicating the number of parameters and the range of values for each:

```
AT+CBC=?
+CBC: (0-2),(1-100),(voltage)

OK
```

The parameters are separated by commas; each parameter's value range is presented in brackets in the form `<LOWEST VALUE>-<HIGHEST VALUE>`.

Issue the command to a [Simcom 7080G](https://docs.korewireless.com/en-us/supersim/get-started/get-started-with-super-sim-sms-commands-and-the-raspberry-pi-pico) and you might see:

```
AT+CBC
+CBC: 0,66,3863

OK
```

Again, the parameters are separated by a comma and preceded with a colon and a space. You can use these separator characters to help you extract the data values. Numeric values will have to be converted from the source string, of course, but double quote delimited values are intended to remain strings.

Here's an example of a multi-parameter command: this sets the modem's power-on welcome text:

<pre><code>AT+CSGT=1,"A Super SIM-containing Modem"
<strong>
</strong>OK
</code></pre>

There are no spaces in the command line; only those within strings are permitted.

We can read back the values with a read command suffix (`?`):

```
AT+CSGT?

1,A Super SIM-containing Modem

OK
```

Which commands a given module supports and what values are returned are generally manufacturer specific and the list of commands is often extensive. You will need to download the command guide for your chosen modem from its manufacturer's website.

***

## How to respond to modem requests <a href="#how-to-respond-to-modem-requests" id="how-to-respond-to-modem-requests"></a>

Sometimes the modem will ask your application code for data. It will signal this by including the character `>` in its response to a command you issued. You now send a Carriage Return, `<CR>` or `"\r"` followed by the requested data. Finally, you send the keyboard combination `Ctrl-Z` to tell the modem to use the data you supplied, or `ESC` to cancel the operation.

How do you send `Ctrl-Z`? You include the character as a numeric character value: `0x1A` in hex, or 26 in decimal. Typically you'll do this with a string format command in your chosen language. For example, here's some C++:

```
string response = modem.send_at_and_get_response(data + "\x1A");
```

And here's the equivalent in Python:

```
response = modem.send_at_and_get_response(data + chr(26))
```

`ESC` is sent in the same way; you just use the code `0x1B` or 27.

One example of returning responses to a modem is sending a text message. Usually you do this with the `AT+CMGS` command and supply the target number. Here's how you send a [Super SIM SMS Command](https://docs.korewireless.com/en-us/api/products/supersim/smscommand-resource):

```
AT+CMGS="000"
```

The modem will respond with `>` and your code needs to look for this and then send a string comprising a Carriage Return, the SMS body, and either `Ctrl-Z` (to send) or `ESC` to cancel.

***

## Key AT commands <a href="#key-at-commands" id="key-at-commands"></a>

The following table lists some of the most useful AT commands you may need while working with a cellular modem and Super SIM.

* **Command**`AT+CGMI`
* **Example Response**`u-blox``OK`
* **Description**Return the modem's manufacturer.

***

* **Command**`AT+CGMM`
* **Example Response**`LARA-R211``OK`
* **Description**Return the modem's model number.

***

* **Command**`AT+CGSN`
* **Example Response**`1234567890``OK`
* **Description**Return the modem's serial number.

***

* **Command**`AT+CPIN?`
* **Example Response**`+CPIN: READY``OK`
* **Description**Confirm the modem's SIM is ready.

***

* **Command**`AT+CIMI`
* **Example Response**`<imsi>``OK`
* **Description**Get the SIM's current International Mobile Subscriber Identifier (IMSI).

***

* **Command**`AT+CCID`
* **Example Response**`<iccid>``OK`
* **Description**Get the SIM's ICCID (Integrated Circuit Card ID).

***

* **Command**`AT+CMEE=2`
* **Example Response**`OK`
* **Description**Enabled extended error reporting: instead of the usual `ERROR`, you will receive `+CME ERROR:` followed by an error message.

***

* **Command**`AT+CSQ`
* **Example Response**`+CSQ: 4,7``OK`
* **Description**Get the current signal strength in the format: ,\<ERR\_RATE>. is an indexed dbM value. \<ERR\_RATE> is an indexed percentage bit error rate. A `99` in either field indicates the value is unknown.

***

* **Command**`AT+CREG?`
* **Example Response**`+CREG: 0,7``OK`
* **Description**Get the current network registration status in the format: \<URC\_MODE>,. \<URC\_MODE> indicates whether network registration status notifications are enabled (`1`) or not (`0`). is value indicating the network status, e.g., `0` shows the modem is not registered, `5` shows the modem is registered and is roaming, and `7` shows the modem is registered for SMS only.

***

* **Command**`AT+COPS?`
* **Example Response**`+COPS: 0,0,"vodafone UK KORE",0``OK`
* **Description**The output fields are: operator selection mode, operator name format, operator name, and network type.

***

* **Command**`AT+COPS=?`
* **Example Response**`+COPS: (2,"EE","EE","23440",7),(1,"3 UK","3 UK","23420",7)``OK`
* **Description**Scan and report visible networks.

***

* **Command**`AT+CGDCONT?`
* **Example Response**`+CGDCONT: 1,"IP","super","0.0.0.0",0,0,0,0``OK`
* **Description**Get the APN (the third response parameter).

***

* **Command**`AT+CMGF=<MODE>`
* **Example Response**`OK`
* **Description**Set the SMS message format. Usually a choice between a binary format and text. For some modems is an integer, for others it is a string, possibly indicating the character set to be used.

### Super SIM setup AT commands <a href="#super-sim-setup-at-commands" id="super-sim-setup-at-commands"></a>

To use a Super SIM, its host modem's APN must be set to `super`, and roaming must be enabled. The following AT commands will help you do so.

{% hint style="info" %}
Other modules will require their own vendor-specific roaming setup commands — please check their documentation. We hope to extend the following sections to include other modules over time. You can also check out the [**Cellular Module Knowledgebase**](https://docs.korewireless.com/en-us/supersim/cellular-module-knowledgebase) .
{% endhint %}

#### **Set APN**

* **Command**`AT+CGDCONT=1,"IP","super"`
* **Example Response**`AT+CGDCONT=1,"IP","super"``OK`
* **Description**Set the modem's APN. It's possible to set multiple APNs, for different IP types (the second parameter), but we recommend setting just one.

#### **Enable roaming**

* **Command** *Quectel BG96 only*`AT+QCFG="roamservice",2`
* **Example Response**`AT+QCFG="roamservice",2``OK`
* **Command** *u-blox Lara-R2xx only*`AT+UDCONF=20,1`
* **Example Response**`OK`

***

## Further Reading <a href="#further-reading" id="further-reading"></a>

* [How to Determine Good Cellular Signal Strength](https://docs.korewireless.com/en-us/supersim/cellular-module-knowledgebase/how-to-determine-good-cellular-signal-strength)
* [How Super SIM Devices Connect to Cell Networks](https://docs.korewireless.com/en-us/supersim/cellular-module-knowledgebase/how-super-sim-devices-connect-to-cell-networks)
* [Best Practices for Cellular Module Registration](https://docs.korewireless.com/en-us/supersim/cellular-module-knowledgebase/four-best-practices-for-cellular-module-registration)
* You can [download](https://www.etsi.org/deliver/etsi_ts/127000_127099/127007/15.07.00_60/ts_127007v150700p.pdf) the comprehensive *AT Command Set for User Equipment* from the ETSI standards agency. It lists all AT commands that are not vendor specific.
* See the [**Cellular Module Knowledgebase**](https://docs.korewireless.com/en-us/supersim/cellular-module-knowledgebase) for more module-specific useful AT commands.
