The Complete Handbook of AT Commands

  • avatar
  • 351 Views
  • 11 mins read

AT commands, short for Attention commands, are a set of instructions used to control modems. These commands originated from the Hayes command set and have become essential for IoT (Internet of Things) devices, especially for managing WiFi modules. They allow users to perform functions such as connecting to a network, sending data, and configuring device settings, making them crucial for IoT applications.

The structure of AT commands is straightforward. Each command starts with the prefix AT (for Attention) followed by the specific instruction. These commands can be sent through a terminal program or software that communicates with the WiFi module. They are not limited to basic tasks; advanced commands can configure security settings, manage power modes, and handle data transmission.

AT Commands structure

In the IoT field, WiFi modules like the ESP8266 and ESP32 are popular for their low cost and flexibility. These modules use AT commands to perform a wide range of functions. This makes AT commands a powerful tool for IoT developers, enabling efficient and effective device management and communication.

Each instruction can have four types of AT commands.

Type

Format

Description

Test

AT+<x>=?

Query the Set command or internal parameters and its range values

Query

AT+<x>?

Returns the current value of the parameter

Set

AT+<x>=<...>

Set the value of user-defined parameters in commands and run

Execute

AT+<x>

Runs commands with no user-defined parameters

Each AT command should end with "\\r\\n" and string values must be enclosed in double quotation marks. Note that not all AT commands include the four options.

AT Commands cheat sheet

This documentation covers the AT command instruction set and its usage. The instruction set is divided into the following categories: basic AT commands, WiFi function AT commands, and TCP/IP AT commands.

Instruction

Description

Basic

AT

Check AT startup

AT+RST

Restart module

AT+GMR

Display version information

AT+GSLP

Enter deep-sleep mode

ATE

Enable/Disable command echo

WiFi

AT+CWMODE

Set WiFi mode (station/softAP/station+softAP)

AT+CWJAP

Connect to access point

AT+CWLAP

List available access points

AT+CWQAP

Disconnect from access point

AT+CWSAP

Configure softAP settings

AT+CWLIF

Get IP addresses of connected stations

AT+CWDHCP

Enable or disable DHCP

AT+CIPSTAMAC

Set station MAC address

AT+CIPAPMAC

Set softAP MAC address

AT+CIPSTA

Set station IP address

AT+CIPAP

Set softAP IP address

TCP/IP

AT+CIPSTATUS

Check connection status

AT+CIPSTART

Start TCP connection or register UDP port

AT+CIPSEND

Transmit data

AT+CIPCLOSE

Terminate TCP/UDP connection

AT+CIFSR

Retrieve local IP address

AT+CIPMUX

Configure multiple connections mode

AT+CIPSERVER

Set up as server

AT+CIPMODE

Configure transmission mode

AT+CIPSTO

Set TCP server timeout

Data RX

+IPD

Indicate data received from network

Below is detailed information on each command, including usage instructions and possible responses.

Basic AT Commands

This section provides an explanation of fundamental AT commands, detailing their essential functions and usage instructions.

AT

This command is used to verify that the AT command interface is operational. When executed, the device should respond with "OK" if it is functioning correctly.

Type

Instruction

Response

Execute

AT

OK


AT+RST

This command restarts the module. It is useful for rebooting the device to apply new settings or recover from an error state.

Type

Instruction

Response

Execute

AT+RST

OK


AT+GMR

This command displays the firmware version of the module. It is helpful for checking the current version and ensuring compatibility with other software.

Type

Instruction

Response

Execute

AT+GMR

<number>

OK

Parameters:

  • <number>: version Info, length: 8bytes


AT+GSLP

This command puts the module into deep-sleep mode to conserve power. It is particularly useful for battery-operated IoT devices that need to minimize power consumption.

Type

Instruction

Response

Set

AT+GSLP=<time>

<time>

OK

Parameters:

  • <time>: set the sleep time in ms. Module will wake up after provided ms in deep-sleep.


ATE

This command controls whether the characters received by the module are echoed back to the terminal. This can be useful for debugging and command verification.

Type

Instruction

Response

Set

ATE

OK

Parameters:

  • ATE0: disable echo.

  • ATE1: enable echo.

WiFi AT Commands

This section presents AT commands specifically designed for managing WiFi functionality. It describes their functions and provides instructions on how to use them effectively.

AT+CWMODE

This command sets the operating mode of the WiFi module. It can be configured to operate as a station, connecting to an existing network, a softAP, creating its own access point, or both simultaneously.

Type

Instruction

Response

Test

AT+CWMODE=?

+CWMODE:<mode>

OK

Query

AT+CWMODE?

+CWMODE:<mode>

OK

Set

AT+CWMODE=<mode>

OK

Parameters:

  • <mode>: WiFi mode

    • 1 - station mode

    • 2 - access point mode

    • 3 - access point + station mode


AT+CWJAP

This command is used to connect the device to a specific access point (AP). It requires the SSID (network name) and password of the target AP to establish a connection.

Type

Instruction

Response

Query

AT+CWJAP?

+CWJAP:<ssid>

OK

Set

AT+CWJAP=<ssid>,<pwd>

OK

ERROR

Parameters:

  • <ssid>: service set identifier

  • <pwd>: access password (max 64 bytes)


AT+CWLAP

This command retrieves a list of available access points in the vicinity. It provides information such as the SSID, signal strength, and security type of each detected AP.

Type

Instruction

Response

Set

AT+CWLAP=<ssid>,<mac>,<ch>

+CWLAP:<ecn>,<ssid>,<rssi>,<mac>

OK

ERROR

Execute

AT+CWLAP

+CWLAP:<ecn>,<ssid>,<rssi>,<mac>

OK

ERROR

Parameters:

  • <enc>: encryption

    • 0 - OPEN

    • 1 - WEP

    • 2 - WPA_PSK

    • 3 - WPA2_PSK

    • 4 - WPA_WPA2_PSK

  • <ssid>: service set identifier

  • <rssi>: signal strength

  • <mac>: MAC address


AT+CWQAP

This command disconnects the device from the currently connected access point.

Type

Instruction

Response

Test

AT+CWQAP=?

OK

Execute

AT+CWQAP

OK


AT+CWSAP

When operating in softAP mode, this command configures parameters such as the SSID, password, and channel of the access point being created.

Type

Instruction

Response

Query

AT+CWSAP?

+CWSAP:<ssid>,<pwd>,<chl>,<ecn>

Set

AT+CWSAP=<ssid>,<pwd>,<chl>,<ecn>

OK

ERROR

Parameters:

  • <ssid>: service set identifier

  • <pwd>: access password (max 64 bytes)

  • <chl>: channel ID

  • <enc>: encryption

    • 0 - OPEN

    • 1 - WEP

    • 2 - WPA_PSK

    • 3 - WPA2_PSK

    • 4 - WPA_WPA2_PSK


AT+CWLIF

This command retrieves the IP addresses of devices currently connected to the WiFi module acting as a softAP.

Type

Instruction

Response

Execute

AT+CWLIF

<ip>

OK

Parameters:

  • <ip>: IP address of stations which are connected to the soft AP


AT+CWDHCP

This command controls whether the module assigns IP addresses dynamically using DHCP (Dynamic Host Configuration Protocol). It can be used to enable or disable DHCP functionality.

Type

Instruction

Response

Set

AT+CWDHCP=<mode>,<en>

OK

Parameters:

  • <mode>: WiFi mode

    • 0 - set softAP

    • 1 - set station

    • 2 - set both softAP and station

  • <en>: DHCP status

    • 0 - Enable DHCP

    • 1 - Disable DHCP


AT+CIPSTAMAC

This command allows the user to manually set the MAC address of the WiFi module when operating in station mode.

Type

Instruction

Response

Query

AT+CIPSTAMAC?

+CIPSTAMAC:<mac>

OK

Set

AT+CIPSTAMAC=<mac>

OK

Parameters:

  • <mac>: MAC address


AT+CIPAPMAC

This command allows the user to manually set the MAC address of the WiFi module when operating in softAP mode.

Type

Instruction

Response

Query

AT+CIPAPMAC?

+CIPSTAMAC:<mac>

OK

Set

AT+CIPAPMAC=<mac>

OK

Parameters:

  • <mac>: MAC address


AT+CIPSTA

This command configures the IP address of the WiFi module when operating in station mode.

Type

Instruction

Response

Query

AT+CIPSTA?

+CIPSTA:<ip>

OK

Set

AT+CIPSTA=<ip>

OK

Parameters:

  • <ip>: IP address


AT+CIPAP

This command configures the IP address of the WiFi module when operating in station mode.

Type

Instruction

Response

Query

AT+CIPAP?

+CIPAP:<ip>

OK

Set

AT+CIPAP=<ip>

OK

Parameters:

  • <ip>: IP address

TCP/IP AT Commands

This section covers AT commands related to TCP/IP communication. It outlines their functions and offers guidance on usage.

AT+CIPSTATUS

This command retrieves the current status of the connection, indicating whether it is idle, connected, or in the process of establishing a connection.

Type

Instruction

Response

Execute

AT+CIPSTATUS

STATUS:<status>

+CIPSTATUS:<id>,<type>,<ip>,<port>,<mode>

OK

Parameters:

  • <status>: connection status

    • 2: got IP

    • 3: connected

    • 4: disconnected

  • <id>: id of the connection (0~4), for multi-connect

  • <type>: TCP or UDP

  • <ip> IP address

  • <port>: port number

  • <mode>: connection mode

    • 0: running as client

    • 1: running as server


AT+CIPSTART

This command is used to initiate a TCP connection with a remote server or register a UDP port for communication.

Single connection (+CIPMUX=0):

Type

Instruction

Response

Test

AT+CIPSTART=?

+CIPSTART:(<type>),(<ip>),(<port>)[,(<localport>),(<mode>)]

OK

Set

AT+CIPSTART=<type>,<addr>,<port> [,(<localport>),(<mode>)]

OK

ERROR

ALREADY CONNECT

Multiple connections (+CIPMUX=1):

Type

Instruction

Response

Test

AT+CIPSTART=?

+CIPSTART:(id),(<type>),(<ip>),(<port>)[,(<localport>),(<mode>)]

OK

Set

AT+CIPSTART=<id>,<type>,<ip>,<port> [,(<localport>),(<mode>)]

OK

ERROR

ALREADY CONNECT

Note: <mode> can only be used when <localport> is set.

Parameters:

  • <id>: id of the connection (0~4), for multi-connect

  • <type>: TCP or UDP

  • <ip> remote IP address

  • <port> remote port

  • <localport> local port for UDP connections only

  • <mode> connection mode for UDP connections only

    • 0 - destination peer entity of UDP will not change.

    • 1 - destination peer entity of UDP can change once.

    • 2 - destination peer entity of UDP is allowed to change.


AT+CIPSEND

This command is used to send data over an established TCP or UDP connection. It allows users to transmit information to remote servers or other devices.

Type

Instruction

Response

Test

AT+CIPSEND=?

OK

Set

Single connection (+CIPMUX=0):

AT+CIPSEND=<length>

Multiple connections (+CIPMUX=1):

AT+CIPSEND=<id>,<length>

Wrap return ">" after set command.

Begins receive of serial data, when data length is met, starts transmission of data.

ERROR

SEND OK

Execute

Unvarnished transmission mode

AT+CIPSEND

Wrap return ">" after execute command.

Enters unvarnished transmission:

  • 20ms interval between each packet

  • maximum 2048 bytes per packet

It returns to command mode when single packet containing "+++" is received.

Parameters:

  • <id>: id of the connection (0~4), for multi-connect

  • <length>: data length (max 2048 bytes)


AT+CIPCLOSE

This command terminates an active TCP or UDP connection, freeing up resources and ending communication with the remote server or device.

Type

Instruction

Response

Test

AT+CIPCLOSE=?

Set

Multiple connections (+CIPMUX=1):

AT+CIPCLOSE=<id>

OK

Execute

Single connection (+CIPMUX=0):

AT+CIPCLOSE

OK

ERROR

UNLINK

When connection id 5 is provided, all connections will be closed.

Parameters:

  • <id>: id of the connection (0~4), for multi-connect


AT+CIFSR

This command retrieves the local IP address assigned to the module, allowing users to identify the device on the network.

Type

Instruction

Response

Test

AT+CIFSR=?

OK

Execute

AT+CIFSR

+CIFSR:<ip>

OK

ERROR

Parameters:

  • <ip> IP address


AT+CIPMUX

This command configures the module to support multiple simultaneous connections, enabling it to handle multiple clients or connections concurrently.

Type

Instruction

Response

Query

AT+CIPMUX?

+CIPMUX:<mode>

OK

Set

AT+CIPMUX=<mode>

OK

LINK IS BUILDED

This mode can only be changed after all connections are disconnected. If server is started, reboot is required.

Parameters:

  • <mode>: connection mode

    • 0 - single connection

    • 1 - multiple connections


AT+CIPSERVER

This command sets up the module as a server, allowing it to accept incoming connections from clients and respond to requests.

Type

Instruction

Response

Set

AT+CIPSERVER= <mode>[,<port>]

OK

ERROR

Note:

  1. Server can only be created when AT+CIPMUX=1

  2. Server monitor will automatically be created when Server is created.

  3. When a client is connected to the server, it will take up one connection ID.

Parameters:

  • <mode>: server action

    • 0 - delete server (need to follow by restart)

    • 1 - create server

  • <port>: port number, default is 333


AT+CIPMODE

This command configures the transmission mode of the module, allowing users to choose between transparent and non-transparent modes for data communication.

Type

Instruction

Response

Query

AT+CIPMODE?

+CIPMODE:<mode>

OK

Set

AT+CIPMODE=<mode>

OK

LINK IS BUILDED

Parameters:

  • <mode>: transmission mode

    • 0 - normal

    • 1 - unvarnished


AT+CIPSTO

This command sets the timeout duration for connections when the module is operating as a TCP server. It helps manage connection durations and resource usage effectively.

Type

Instruction

Response

Query

AT+CIPSTO?

+CIPSTO:<time>

OK

Set

AT+CIPSTO=<time>

OK

Parameters:

  • <time>: server timeout, range 0-7200 seconds


+IPD

When network data is received, the module will send the data through the serial port using the +IPD command.

Single connection (+CIPMUX=0)

+IPD,<length>:<data>

Multiple connections (+CIPMUX=1)

+IPD,<id>,<length>:<data>

Parameters:

  • <id>: id of the connection (0~4), for multi-connect

  • <length>: data length

  • <data>: data received

Conclusion

AT commands are important for the operation of IoT devices, particularly those with WiFi modules. Their straightforwardness and efficiency make them indispensable for connecting devices, configuring settings, and managing data transmission. Mastering AT commands can significantly enhance the performance and control of IoT systems, highlighting their key contribution to the advancement of smart, connected technologies.

 Join Our Monthly Newsletter

Get the latest news and popular articles to your inbox every month

We never send SPAM nor unsolicited emails

0 Comments

Leave a Reply

Your email address will not be published.

Replying to the message: View original

Hey visitor! Unlock access to featured articles, remove ads and much more - it's free.