/ESP8266-AT-WIFI-MQTT

This is the AT firmware for the ESP8266 WROOM-02. It provides a WIFI and MQTT interface with AT commands.

Primary LanguageC++MIT LicenseMIT

ESP8266 - WROOM-02 - AT Firmware for WIFI and MQTT

This is the AT firmware for the ESP8266 WROOM-02. It provides a WIFI and MQTT interface with AT commands.

AT Command Types

Generic AT command has four types:

Type Command Format Description
Test Command AT+=? Queries the Set Commands’ internal parameters and their range of values.
Query Command AT+? Returns the current value of parameters.
Set Command AT+=<…> Sets the value of user-defined parameters in commands, and runs these commands.
Execute Command AT+ Runs commands with no user-defined parameters.
  • Square brackets [ ] designate parameters that may be omitted; default value of the parameter will be used instead.

    Below are examples of entering command AT+CWJAP with some parameters omitted:

    AT+CWJAP="ssid","password"
    AT+CWJAP="ssid","password","11:22:33:44:55:66"
  • If the parameter which is not the last one is omitted, you can give a , to indicate it.

    Example:

    AT+CWJAP="ssid","password",,1
  • String values need to be included in double quotation marks, for example: AT+CWSAP="ESP756290","21030826",1,4.

  • Escape character syntax is needed if a string contains any special characters, such as ,, " or :

    • \\: escape backslash itself

    • \,: escape comma which is used to separate each parameter

    • \": escape double quotation marks which used to mark string input

    • \<any>: escape <any> character means that drop backslash symbol and only use <any> character

      Example:

      AT+CWJAP="comma\,backslash\\ssid","1234567890"
      AT+MQTTPUB=0,"topic","\"{\"sensor\":012}\"",1,0
  • The default baud rate of AT command is 115200.

  • AT commands are ended with a new-line (CR-LF), so the serial tool should be set into “New Line Mode”.

Basic AT Commands

AT: Test AT Startup

Command:

AT

Response:

OK

AT+RST: Restart a Module

Command:

AT+RST

Response:

OK

AT+GMR: Check Version Information

Command:

AT+GMR

Response:

<AT version info>
<Bin version>

OK

Parameters:

  • <AT version info>: information about the AT library version
  • <Bin version>: firmware version

Example:

AT+GMR
AT version:1.0.0
Bin version:0.0.1

OK

AT+CMD: List all AT commands and types supported in current firmware

Query Command:

AT+CMD?

Response:

+CMD=<index>,<AT command name>,<support test command>,<support query command>,<support set command>,<support execute command>

OK

Parameters:

  • <index>: AT command sequence number.
  • <AT command name>: AT command name.
  • <support test command>: 0 means not supported, 1 means supported.
  • <support query command>: 0 means not supported, 1 means supported.
  • <support set command>: 0 means not supported, 1 means supported.
  • <support execute command>: 0 means not supported, 1 means supported.

WIFI AT Commands

AT+CWMODE: Query/Set the Wi-Fi Mode (Station/SoftAP/Station+SoftAP)

Command:

AT+CWMODE?

Response:

+CWMODE:<mode>

OK

Parameters:

  • <mode>: 0: Null mode. Wi-Fi RF will be disabled. 1: Station mode. 2: SoftAP mode. 3: SoftAP+Station mode.

AT+CWSTATE: Query the Wi-Fi state and Wi-Fi information

Command:

AT+CWSTATE?

Response:

+CWSTATE:<state>,<ssid>

OK

Parameters:

  • <state>: current Wi-Fi state. 0: The station has not started any Wi-Fi connection. 1: The station has connected to an AP, but does not get an IPv4 address yet. 2: The station has connected to an AP, and got an IPv4 address. 3: The station is in Wi-Fi connecting or reconnecting state. 4: The station is in Wi-Fi disconnected state.
  • <ssid>: the SSID of the target AP.

AT+CWJAP: Connect to an AP

Query Command:

Query the AP to which the Station is already connected.

AT+CWJAP?

Response:

+CWJAP:<ssid>,<bssid>,<channel>,<rssi>

OK

Set Command:

Query the AP to which the Station is already connected.

AT+CWJAP=[<ssid>],[<pwd>]

Response:

DISCONNECTED
CONNECTED

OK

or

DISCONNECTED

ERROR

Parameters:

  • <ssid>: the SSID of the target AP. Escape character syntax is needed if SSID or password contains special characters, such ,, ", or \\.
  • <pwd>: password, MAX: 63-byte ASCII.
  • <bssid>: the MAC address of the target AP. It cannot be omitted when multiple APs have the same SSID.
  • <channel>: channel.
  • <rssi>: signal strength.

AT+CWRECONNCFG: Query/Set the Wi-Fi Reconnecting Configuration

Query Command:

AT+CWRECONNCFG?

Response:

+CWRECONNCFG:<reconncfg>

OK

Set Command:

Query the AP to which the Station is already connected.

AT+CWRECONNCFG=<reconncfg>

Response:

OK

Parameters:

  • <reconncfg>: the reconnecting configuration. 0: auto-reconnect is disabled. 1: auto-reconnect is enabled.

AT+CWLAP: List Available APs

Execute Command:

AT+CWLAP

Response:

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

OK

Parameters:

  • <ecn>: encryption method. 0: OPEN 1: WEP 2: WPA PSK 3: WPA2 PSK 4: WPA WPA2 PSK
  • <ssid>: string parameter showing SSID of the AP.
  • <rssi>: signal strength.
  • <mac>: string parameter showing MAC address of the AP.
  • <channel>: channel.

AT+CWQAP: Disconnect from an AP

Execute Command:

AT+CWQAP

Response:

OK

AT+CWSAP: Query/Set the configuration of an ESP32 SoftAP

Query Command:

AT+CWSAP?

Response:

+CWSAP:<ssid>,<pwd>,<channel>

OK

Set Command:

AT+CWSAP=<ssid>,<pwd>,<chl>,<ecn>,<max conn>,<ssid hidden>

Response:

OK

Parameters:

  • <ssid>: string parameter showing SSID of the AP.
  • <pwd>: string parameter showing the password. Length: 8 ~ 63 bytes ASCII.
  • <channel>: channel ID.
  • <ecn>: encryption method; WEP is not supported.
    • 0: OPEN
    • 2: WPA_PSK
    • 3: WPA2_PSK
    • 4: WPA_WPA2_PSK
  • [<max conn>]: maximum number of stations that SoftAP can connect. Range: [1,10].
  • [<ssid hidden>]:
    • 0: broadcasting SSID (default).
    • 1: not broadcasting SSID.

AT+CWLIF: Obtain IP Address of the Station That Connects to an SoftAP

Execute Command:

AT+CWLIF

Response:

+CWLIF:<ip addr>,<mac>

OK

Parameters:

  • <ip addr>: IP address of the station that connects to the SoftAP.
  • <mac>: MAC address of the station that connects to the SoftAP.

AT+CWQIF: Disconnect Stations from an SoftAP

Execute Command:

AT+CWQIF

Response:

OK

AT+CWDHCP: Enable/Disable DHCP

Query Command:

AT+CWDHCP?

Response:

+CWDHCP:<state>

OK

Set Command:

AT+CWDHCP=<operate>,<mode>

Response:

OK

Parameters:

  • <operate>: 0: disable 1: enable
  • <mode>: 0: Station DHCP 1: SoftAP DHCP
  • <state>: the status of DHCP Bit0: 0: Station DHCP is disabled. 1: Station DHCP is enabled. Bit1: 0: SoftAP DHCP is disabled. 1: SoftAP DHCP is enabled.

AT+CIPSTA: Query/Set the IP Address of an ESP32 Station

Query Command:

AT+CIPSTA?

Response:

+CIPSTA:ip:<ip>
+CIPSTA:gateway:<gateway>
+CIPSTA:netmask:<netmask>

OK

Parameters:

  • <ip>: string parameter showing the IPv4 address of the station.
  • <gateway>: gateway.
  • <netmask>: netmask.

AT+CWHOSTNAME: Query/Set the Host Name of an ESP32 Station

Query Command:

AT+CWHOSTNAME?

Response:

+CWHOSTNAME:<hostname>

OK

Set Command:

AT+CWHOSTNAME=<hostname>

Response:

OK

Parameters:

  • <hostname>: the host name of the Station. Maximum length: 32 bytes.

TCP/IP AT Commands

AT+CIPSERVER: Delete/create a TCP Server

Query Command:

AT+CIPSERVER?

Response:

+CIPSERVER:<mode>,<port>

OK

Set Command:

AT+CIPSERVER=<mode>,<port>

Response:

OK

Parameters:

  • <mode>: 0: delete a server. 1: create a server.
  • <port>: represents the port number. Range: [1024,65535].

AT+CIPRECVLEN: Obtain Socket Data Length in Passive Receiving Mode

Query Command:

AT+CIPRECVLEN?

Response:

+CIPRECVLEN:<chan>,<len>

OK

Parameters:

  • <chan>: the channel identifier [0-3].
  • <len>: length of the entire data buffered for the connection.

AT+CIPRECVDATA: Obtain Socket Data in Passive Receiving Mode

Set Command:

AT+CIPRECVDATA=<chan>,<r_len>

Response:

AT+CIPRECVDATA=<chan>,<a_len>,<remote_ip>,<remote_port>,<data>

OK

Parameters:

  • <chan>: the channel identifier [0-3].
  • <r_len>: length of the requested buffer.
  • <a_len>: length of the data you actually obtain. If the actual length of the received data is less than len, the actual length will be returned.
  • <remote_ip>: string parameter showing the remote IPv4 address.
  • <remote_port>: the remote port number.

AT+CIPSTATE: Obtain the TCP Connection Information

Query Command:

AT+CIPSTATE?

Response:

+CIPSTATE:<channel>,<remote_ip>,<remote_port>,<local_port>

OK

Parameters:

  • <chan>: the channel identifier [0-3].
  • <remote_ip>: string parameter showing the remote IPv4 address.
  • <remote_port>: the remote port number.
  • <local_port>: the local port number.

AT+CIPSEND: Send Data in the Normal Transmission Mode

Set Command:

AT+CIPSEND=<chan>,<len>

Response:

OK

>

This response indicates that AT is ready for receiving serial data. You should enter the data, and when the data length reaches the <len> value, the transmission of data starts.

If the connection cannot be established or is disrupted during data transmission, the system returns:

ERROR

If data is transmitted successfully, the system returns:

SEND OK

OK

Parameters:

  • <chan>: the channel identifier [0-3].
  • <len>: length of the data to send.