Espressif Systems ESP32 Instruction Set

At instruction set and examples
Hide thumbs Also See for ESP32:
Table of Contents

Advertisement

Quick Links

ESP32
AT Instruction Set and Examples
Version 1.3
Espressif Systems
Copyright © 2019

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for Espressif Systems ESP32

  • Page 1 ESP32 AT Instruction Set and Examples Version 1.3 Espressif Systems Copyright © 2019...
  • Page 2 About This Guide This document introduces the ESP32 AT commands, explains how to use them and provides examples of several common AT commands. Release Notes Date Version Release notes 2017.11 V1.0 Initial release. Updated Section 4.2.15,5.2.8,5.2.15,6.2.5, 6.2.11 and Chapter 8.
  • Page 3: Table Of Contents

    4.2.3. AT+CWLAPOPT—Sets the Configuration for the Command AT+CWLAP ......4.2.4. AT+CWLAP—Lists the Available APs ..................4.2.5. AT+CWQAP—Disconnects from the AP ................. 4.2.6. AT+CWSAP—Configuration of the ESP32 SoftAP ..............4.2.7. AT+CWLIF—IP of Stations to Which the ESP32 SoftAP is Connected ........ 4.2.8. AT+CWDHCP—Enables/Disables DHCP ................
  • Page 4 4.2.9. AT+CWDHCPS—Sets the IP Address Allocated by ESP32 SoftAP DHCP (The configuration is saved in Flash.) ......................... 4.2.10. AT+CWAUTOCONN—Auto-Connects to the AP or Not ............4.2.11. AT+CWSTARTSMART—Starts SmartConfig ................4.2.12. AT+CWSTOPSMART—Stops SmartConfig ................4.2.13. AT+WPS—Enables the WPS Function ..................4.2.14. AT+CWHOSTNAME—Configures the Host Name of ESP32 Station * .........
  • Page 5 5.2.25. AT+PING—Ping Packets ......................6. BLE-Related AT Commands ....................6.1. Overview ..........................6.2. Commands ..........................6.2.1. AT+BLEINIT—BLE Initialization ....................6.2.2. AT+BLEADDR—Sets BLE Device's Address ................6.2.3. AT+BLENAME—Sets BLE Device's Name ................6.2.4. AT+BLESCANPARAM—Sets Parameters of BLE Scanning ..........6.2.5. AT+BLESCAN—Enables BLE Scanning .................
  • Page 6 9.2.2. UDP (with Changeable Remote IP and Port) ................9.3. Transparent Transmission ......................9.3.1. ESP32 as a TCP Client in UART-Wi-Fi Passthrough (Single Connection Mode) ....9.3.2. UDP Transmission (UART-Wi-Fi PassthroughTransmission) ..........9.4. ESP32 as a TCP Server in Multiple Connections ..............
  • Page 7: Overview

    1. Overview Overview This document introduces the ESP32 AT commands, and explains how to use them. The AT command set is divided into different categories: Basic AT commands, Wi-Fi AT commands, TCP/IP AT commands, etc. Please note that the AT commands marked with * are beta versions that have not been fully tested.
  • Page 8 �� Note: • If the ESP32-AT bin fails to boot, and prints log "ota data partition invalid", please erase all flash or download the blank.bin into the address labeled as "otadata" in esp32-at/partitions_at.csv. • Users can change to use another UART for AT communication. For example, if you want to use UART0 for AT communication, you need to: make menuconfig ->...
  • Page 9: Command Description

    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". • Definitions of AT command error codes are in esp32-at/components/at/include/esp_at.h. Espressif ! /! 3 97 2019.06...
  • Page 10: Basic At Commands

    3. Basic AT Commands Basic AT Commands 3.1. Overview Commands Description Tests AT startup. Restarts a module. AT+RST Checks version information. AT+GMR Enters Deep-sleep mode. AT+GSLP Configures echoing of AT commands. Restores the factory default settings of the module. AT+RESTORE Current UART configuration.
  • Page 11: At+Gmr-Checks Version Information

    AT+GSLP—Enters Deep-sleep Mode Set Command AT+GSLP=<time> <time> Response <time>: the duration of ESP32's sleep. Unit: ms. Parameters ESP32 will wake up after Deep-sleep for as many milliseconds (ms) as <time> indicates. 3.2.5. ATE—AT Commands Echoing Execute Command Response ATE0: Switches echo off.
  • Page 12: At+Uart_Cur-Current Uart Configuration, Not Saved In Flash

    3. Basic AT Commands The execution of this command will reset all parameters saved in flash, and Note restore the factory default settings of the module. The chip will be restarted when this command is executed. 3.2.7. AT+UART_CUR—Current UART Configuration, Not Saved in Flash Set Command: Query Command: Command...
  • Page 13: At+Uart_Def-Default Uart Configuration, Saved In Flash

    3. Basic AT Commands 3.2.8. AT+UART_DEF—Default UART Configuration, Saved in Flash Query Command: Set Command: AT+UART_DEF? Command AT+UART_DEF=<baudrate>,<databits>,<stop Function: bits>,<parity>,<flow control> Read the UART configuration from flash. +UART_DEF:<baudrate>,<databits>,<stopbi Response ts>,<parity>,<flow control> • <baudrate>: UART baud rate • <databits>: data bits ‣ 5: 5-bit data ‣...
  • Page 14: At+Sleep-Sets The Sleep Mode

    3. Basic AT Commands 3.2.9. AT+SLEEP—Sets the Sleep Mode Set Command AT+SLEEP=<sleep mode> Response <sleep mode>: Parameters ‣ 0: disable the sleep mode. ‣ 1: Modem-sleep mode. Example AT+SLEEP=0 3.2.10. AT+SYSRAM—Checks the Remaining Space of RAM Query Command AT+SYSRAM? +SYSRAM:<remaining RAM size> Response Parameters <remaining RAM size>: remaining space of RAM, unit: byte AT+SYSRAM? Example...
  • Page 15: At+Fs-Filesystem Operations

    ESP32 AT firmware. Notes • at_customize.bin has to be downloaded, so that the relevant commands can be used. The definitions of user partitions are in esp32-at/at_customize.csv. Please refer to the ESP32_Customize_Partitions for more details. Espressif ! /! 9 97 2019.06...
  • Page 16 3. Basic AT Commands // delete a file. AT+FS=0,0,"filename" // write 10 bytes to offset 100 of a file. AT+FS=0,1,"filename",100,10 Example // read 100 bytes from offset 0 of a file. AT+FS=0,2,"filename",0,100 // list all files in the root directory. AT+FS=0,4,"."...
  • Page 17: At+Rfpower-Set Rf Tx Power

    3. Basic AT Commands 3.2.13. AT+RFPOWER—Set RF TX Power * Set Command: Command AT+RFPOWER=<wifi_power>[,<ble_adv_power>,<ble_scan_power>,<ble_conn_power>] Response <wifi_power>: range [0, 11] ‣ 0:level 0. Refer to the 44th byte of phy_init_data.bin, the default value is 19.5 dBm ‣ 1:level 1. Refer to the 45th byte of phy_init_data.bin, the default value is 19 dBm ‣...
  • Page 18: Wi-Fi At Commands

    AT+CWLAP Disconnects from the AP. AT+CWQAP Sets the configuration of the ESP32 SoftAP. AT+CWSAP Gets the Station IP to which the ESP32 SoftAP is connected. AT+CWLIF Enables/disables DHCP. AT+CWDHCP Sets the IP range of the ESP32 SoftAP DHCP server. AT+CWDHCPS Saves the setting in flash.
  • Page 19 4. Wi-Fi AT Commands <mode>: ‣ 0: Null mode, Wi-Fi RF will be disabled * Paramete ‣ 1: Station mode ‣ 2: SoftAP mode ‣ 3: SoftAP+Station mode Note The configuration changes will be saved in the NVS area. Example AT+CWMODE=3 Espressif 13 97...
  • Page 20: At+Cwjap-Connects To An Ap

    ‣ others: unknown error occurred. Escape character syntax is needed if SSID or password contains any special characters, such as, or " or \. // If ESP32 station connects to an AP, it will prompt messages: WIFI CONNECTED Messages WIFI GOT IP...
  • Page 21: At+Cwlapopt-Sets The Configuration For The Command At+Cwlap

    4. Wi-Fi AT Commands 4.2.3. AT+CWLAPOPT—Sets the Configuration for the Command AT+CWLAP Set Command AT+CWLAPOPT=<sort_enable>,<mask> Response <sort_enable>: determines whether the result of command AT+CWLAP will be listed • according to RSSI: ‣ 0: the result is not ordered according to RSSI. ‣...
  • Page 22: At+Cwlap-Lists The Available Aps

    4. Wi-Fi AT Commands 4.2.4. AT+CWLAP—Lists the Available APs Set Command: Execute Command: AT+CWLAP=<ssid>[,<mac>,<channel>] Commands AT+CWLAP Function: to query the APs with specific SSID Function: to list all available APs. and MAC on a specific channel. +CWLAP:<ecn>,<ssid>,<rssi>,<mac>,<chann +CWLAP:<ecn>,<ssid>,<rssi>,<mac>,<chann Response el> el>...
  • Page 23: At+Cwsap-Configuration Of The Esp32 Softap

    This command is only available when ‣ 4: WPA_WPA2_PSK SoftAP is active. • [<max conn>](optional parameter): maximum number of Stations to which ESP32 SoftAP can be connected; within the range of [1, 10]. • [<ssid hidden>](optional parameter): ‣ 0: SSID is broadcast. (the default setting) ‣...
  • Page 24: At+Cwlif-Ip Of Stations To Which The Esp32 Softap Is Connected

    • <mac>: MAC address of Stations to which ESP32 SoftAP is connected. This command cannot get a static IP. It only works when both DHCPs of the ESP32 Note SoftAP, and of the Station to which ESP32 is connected, are enabled.
  • Page 25: At+Cwdhcps-Sets The Ip Address Allocated By Esp32 Softap Dhcp (The Configuration Is Saved In Flash.)

    <lease time>: lease time, unit: minute, range [1, 2880]. • <start IP>: start IP of the IP range that can be obtained from ESP32 SoftAP DHCP server. • <end IP>: end IP of the IP range that can be obtained from ESP32 SoftAP DHCP server.
  • Page 26: At+Cwstartsmart-Starts Smartconfig

    The message Smart get wifi info means that SmartConfig has successfully acquired • Notes the AP information. ESP32 will try to connect to the target AP. Message smartconfig connected wifi is printed if the connection is successful. • Use command AT+CWSTOPSMART to stop SmartConfig before running other commands.
  • Page 27: At+Wps-Enables The Wps Function

    Parameters <hostname>: the host name of the ESP32 Station, maximum length: 32 bytes The configuration changes are not saved in the flash. • Notes The default host name of the ESP32 Station is ESP_XXXXXX; XXXXXX is the lower 3 bytes • of the MAC address, for example, +CWHOSTNAME:<ESP_A378DA>. AT+CWMODE=3 Example AT+CWHOSTNAME="my_test"...
  • Page 28 4. Wi-Fi AT Commands • <enable>: ‣ 1: enables the MDNS function; the following three parameters need to be set. ‣ 0: disables the MDNS function; the following three parameters need not to be set. Parameters <hostname>: MDNS host name •...
  • Page 29: Tcp/Ip-Related At Commands

    Set the maximum connections that server allows AT+CIPSERVERMAXCONN Configures the transmission mode. AT+CIPMODE Saves the transparent transmission link in flash. AT+SAVETRANSLINK Sets timeout when ESP32 runs as a TCP server. AT+CIPSTO Updates the software through Wi-Fi. AT+CIUPDATE Shows remote IP and remote port with +IPD. AT+CIPDINFO Configures the time domain and SNTP server.
  • Page 30: Commands

    <stat>: status of the ESP32 Station interface. • ‣ 2: The ESP32 Station is connected to an AP and its IP is obtained. ‣ 3: The ESP32 Station has created a TCP or UDP transmission. ‣ 4: The TCP or UDP transmission of ESP32 Station is disconnected.
  • Page 31: At+Cipstamac-Sets The Mac Address Of The Esp32 Station

    • make sure that you do not set the same MAC address for both of them. Notes Bit 0 of the ESP32 MAC address CANNOT be 1. For example, a MAC address can be "1a: • …" but not "15:…".
  • Page 32: At+Cipsta-Sets The Ip Address Of The Esp32 Station

    MAC address for both of them. Notes • Bit 0 of the ESP32 MAC address CANNOT be 1. For example, a MAC address can be "18: …" but not "15:…". • FF:FF:FF:FF:FF:FF and 00:00:00:00:00:00 are invalid MAC and cannot be set.
  • Page 33: At+Cipstart-Establishes Tcp Connection, Udp Transmission Or Ssl Connection

    5. TCP/IP-Related AT Commands The configuration changes will be saved in the NVS area. • Currently, ESP32 only supports class C IP addresses. • The set command interacts with DHCP-related AT commands (AT+CWDHCP-related • Notes commands): ‣ If static IP is enabled, DHCP will be disabled;...
  • Page 34 <remote IP>: string parameter indicating the remote IP address. • <remote port>: remote port number. • [<UDP local port>]: optional. It is the UDP port of ESP32. • [<UDP mode>] (optional parameter): the entity of UDP transmission. For UDP transparent Parameters transmission, the value of this parameter has to be 0.
  • Page 35: At+Cipsslcconf-Set Configuration Of Ssl Client

    On how to generate the bin file, please refer to PKI Bin esp32-at/tools/ readme.md. <CA_ID>: The CA ID that starts from 0. ESP32 AT supports multiple certificates. On how to • generate the bin file, please refer to PKI Bin in esp32-at/tools/readme.md.
  • Page 36: At+Cipsend-Sends Data

    20ms. starts. When a single packet containing +++ is If the connection cannot be established or gets received, ESP32 returns to normal disrupted during data transmission, the system command mode. Please wait for at least Response returns:...
  • Page 37: At+Cipsendex-Sends Data

    5. TCP/IP-Related AT Commands 5.2.11. AT+CIPSENDEX—Sends Data Set Command: 1. Single connection: ( +CIPMUX=0 AT+CIPSENDEX=<length> 2. Multiple connections: ( +CIPMUX=1 Commands AT+CIPSENDEX=<link ID>,<length> 3. Remote IP and ports can be set in UDP transmission: AT+CIPSENDEX=[<link ID>,]<length>[,<remote IP>,<remote port>] Function: to configure the data length in normal transmission mode. Send data of designated length.
  • Page 38: At+Cifsr-Gets The Local Ip Address

    Parameters <MAC address> MAC address of the ESP32 SoftAP; MAC address of the ESP32 Station. Notes Only when the ESP32 Station is connected to an AP can the Station IP be queried. 5.2.14. AT+CIPMUX—Enables/Disables Multiple Connections Set Command: Query Command: Commands AT+CIPMUX=<mode>...
  • Page 39: At+Cipserver-Deletes/Creates Tcp Or Ssl Server

    5. TCP/IP-Related AT Commands 5.2.15. AT+CIPSERVER—Deletes/Creates TCP or SSL Server * Query Command: Set Command: AT+CIPSERVER? AT+CIPSERVER=<mode>[,<port>] Command [,<SSL>,<SSL CA enable>] Function: to obtain information about the server mode. Function: to set a TCP or SSL server. +CIPSERVER:<mode>,<port>,<SSL>,<SSL CA Response enable> <mode> ‣ 0 : delete server.
  • Page 40: At+Cipmode-Configures The Transmission Mode

    During the UART-Wi-Fi passthrough transmission, if the TCP connection breaks, ESP32 will • keep trying to reconnect until +++ is input to exit the transmission. If it is a normal TCP transmission and the TCP connection breaks, ESP32 will give a prompt and will not attempt Notes to reconnect.
  • Page 41: At+Savetranslink-Saves The Transparent Transmission Link In Flash

    Save TCP Single Connection in Flash AT+SAVETRANSLINK=<mode>,<remote IP or domain name>,<remote port>[,<type>,<TCP Command keep alive>] Response • <mode> ‣ 0 : normal mode, ESP32 will NOT enter UART-Wi-Fi passthrough mode on power-up. ‣ 1 will : ESP32 enter UART-Wi-Fi passthrough mode on power-up. • : remote IP or domain name. <remote IP>...
  • Page 42: At+Cipsto-Sets The Tcp Server Timeout

    Parameter <time> : TCP server timeout within the range of 0 ~ 7200 • ESP32 configured as a TCP server will disconnect from the TCP client that does not communicate with it until timeout. Notes • If AT+CIPSTO=0, the connection will never time out. This configuration is not recommended.
  • Page 43: At+Cipsntpcfg-Sets The Time Zone And The Sntp Server

    5. TCP/IP-Related AT Commands 5.2.20. AT+CIPSNTPCFG—Sets the Time Zone and the SNTP Server Set Command: Query Command: Command AT+CIPSNTPCFG=<enable>[,<timezone>][,<SNTP AT+CIPSNTPCFG? server0>,<SNTP server1>,<SNTP server2>] +CIPSNTPCFG:<enable>,<timezone>,<SN TP server1>[,<SNTP server2>,<SNTP Response server3>] • <enable>: ‣ 0: SNTP is disabled; ‣ 1: SNTP is enabled. Parameter <timezone>: time zone; range: [-11,13]; if SNTP is enabled, the <timezone> has to be set; •...
  • Page 44: At+Cipdinfo-Shows The Remote Ip And Port With "+Ipd

    5. TCP/IP-Related AT Commands +CIPUPDATE:<n> //<n> means the FOTA steps: Response ‣ 1 : find the server. ‣ 2: check software version from server, this step will be skipped if upgrading to a specific version ‣ 3: get the software version, this step will be skipped if upgrading to a specific version ‣...
  • Page 45: At+Ping-Ping Packets

    5. TCP/IP-Related AT Commands The command is valid in normal command mode. When the module receives network data, it will send the data through the serial port using the +IPD command. [<remote IP>]: remote IP, enabled by command AT+CIPDINFO=1. • [<remote port>]: remote port, enabled by command AT+CIPDINFO=1. Parameters •...
  • Page 46: Ble-Related At Commands

    6. BLE-Related AT Commands BLE-Related AT Commands 6.1. Overview Commands Commands Description Bluetooth Low Energy (BLE) initialization AT+BLEINIT Sets BLE device's address AT+BLEADDR Sets BLE device's name AT+BLENAME Sets parameters of BLE scanning AT+BLESCANPARAM Enables BLE scanning AT+BLESCAN Sets BLE scan response AT+BLESCANRSPDATA Sets parameters of BLE advertising AT+BLEADVPARAM...
  • Page 47 AT+BLECONFREPLY Lists All Devices that Bonded AT+BLEENCDEV Unbinds Device AT+BLEENCCLEAR ⚠ Notice: Download BLE Spec (ESP32 supports Core Version 4.2): https://www.bluetooth.com/specifications/ • adopted-specifications The BLE commands and the UART-Wi-Fi passthrough mode cannot be used together, so before BLE • initialization, please ensure that the UART-Wi-Fi passthrough mode is not enabled (AT+CIPMODE=0).
  • Page 48: Commands

    After being initialized, the BLE role cannot be changed directly. If the user wants to • change the BLE role, AT+RST or AT+BLEINIT=0 needs to be called first. If using ESP32 as a BLE server, a service bin should be downloaded into Flash. • Notes ‣...
  • Page 49: At+Blename-Sets Ble Device's Name

    6. BLE-Related AT Commands For the time being, only two actions are supported: getting the public address and • setting the BLE random address. Notes The two most significant bits of the random address shall be equal to 1. More details are •...
  • Page 50: At+Blescan-Enables Ble Scanning

    6. BLE-Related AT Commands <scan_type>: ‣ 0: passive scan ‣ 1: active scan <own_addr_type>: ‣ 0: public address ‣ 1: random address ‣ 2: RPA public address ‣ 3: RPA random address Parameters <filter_policy>: ‣ 0: BLE_SCAN_FILTER_ALLOW_ALL ‣ 1: BLE_SCAN_FILTER_ALLOW_ONLY_WLST ‣...
  • Page 51: At+Blescanrspdata-Sets Ble Scan Response

    6. BLE-Related AT Commands <enable>: ‣ 0: disable scanning ‣ 1: enable scanning [<interval>]: optional parameter, unit: second ‣ When disabling the scanning, this parameter should be omitted ‣ When enabling the scanning, - if the <interval> is 0 or omitted, it means that scanning is continuous - if the <interval>...
  • Page 52: At+Bleadvparam-Sets Parameters Of Advertising

    6. BLE-Related AT Commands 6.2.7. AT+BLEADVPARAM—Sets Parameters of Advertising Set Command: Query Command: AT+BLEADVPARAM=<adv_int_min>,<adv_int_max >, AT+BLEADVPARAM? Commands <adv_type>,<own_addr_type>,<channel_map> Function: to query the parameters of [,<adv_filter_policy>,<peer_addr_type>,<p eer_addr>] advertising. Function: to set the parameters of advertising. +BLEADVPARAM:<adv_int_min>,<adv_int_ max>,<adv_type>,<own_addr_type>,<cha Response nnel_map>,<adv_filter_policy>,<peer_ addr_type>,<peer_addr> <adv_int_min>: minimum value of advertising interval; range: 0x0020 ~ 0x4000 <adv_int_max>: maximum value of advertising interval;...
  • Page 53: At+Bleadvdata-Sets Advertising Data

    6. BLE-Related AT Commands 6.2.8. AT+BLEADVDATA—Sets Advertising Data Set Command: Commands AT+BLEADVDATA=<adv_data> Function: to set advertising data. Response <adv_data>: advertising data; this is a HEX string. For example, to set the advertising data Parameters as "0x11 0x22 0x33 0x44 0x55", the command should be AT+BLEADVDATA="1122334455". Note The maximum length of the advertising data is 31 bytes.
  • Page 54: At+Bleconn-Establishes Ble Connection

    6. BLE-Related AT Commands 6.2.11. AT+BLECONN—Establishes BLE connection Set Command: Query Command: AT+BLECONN=<conn_index>,<remote_address>[ Commands AT+BLECONN? ,<addr_type>] Function: to query the BLE connection. Function: to establish the BLE connection. +BLECONN:<conn_index>,<remote_addres If the connection established successfully, it will s> prompt message Response +BLECONN:<conn_index>,<remote_address>...
  • Page 55: At+Bledisconn-Ends Ble Connection

    6. BLE-Related AT Commands <conn_index>: index of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future. <min_interval>: minimum value of connecting interval; range: 0x0006 ~ 0x0C80 <max_interval>: maximum value of connecting interval; range: 0x0006 ~ 0x0C80 Parameters <cur_interval>: current connecting interval value <latency>: latency;...
  • Page 56: At+Blecfgmtu-Sets Gatt Mtu Length

    Response Parameter None • If using ESP32 as a BLE server, a service bin should be downloaded into Flash in order to provide services. ‣ To learn how to generate a service bin, please refer to esp32-at/tools/readme.md. Notes ‣ The download address of the service bin is the "ble_data" address in esp32-at/ at_customize.csv.
  • Page 57: At+Blegattssrvstart-Gatts Starts Services

    6. BLE-Related AT Commands 6.2.17. AT+BLEGATTSSRVSTART—GATTS Starts Services Execute Command: Set Command: Commands AT+BLEGATTSSTART AT+BLEGATTSSRVSTART=<srv_index> Function: GATTS starts all services. Function: GATTS starts a specific service. Response None Parameter <srv_index>: service's index starting from 1 AT+BLEINIT=2 // role: server Example AT+BLEGATTSSRVCRE AT+BLEGATTSSRVSTART 6.2.18.
  • Page 58: At+Blegattschar-Gatts Discovers Characteristics

    6. BLE-Related AT Commands AT+BLEINIT=2 // role: server Example AT+BLEGATTSSRVCRE AT+BLEGATTSSRV? 6.2.20. AT+BLEGATTSCHAR—GATTS Discovers Characteristics Query Command: Command AT+BLEGATTSCHAR? Function: GATTS characteristics discovery. // when showing a characteristic, it will be as: +BLEGATTSCHAR:"char",<srv_index>,<char_index>,<char_uuid>,<char_prop> Response // when showing a descriptor, it will be as: +BLEGATTSCHAR:"desc",<srv_index>,<char_index>,<desc_index>...
  • Page 59: At+Blegattsind-Gatts Indicates Characteristics

    6. BLE-Related AT Commands <conn_index>: index of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future. <srv_index>: service's index; it can be fetched with command AT+BLEGATTSCHAR? Parameters <char_index>: characteristic's index; it can be fetched with command AT+BLEGATTSCHAR? <length>: data length A simple workflow is shown below.
  • Page 60: At+Blegattssetattr-Gatts Sets Characteristic

    6. BLE-Related AT Commands A simple workflow is shown below. Users can refer to Section 9.5 BLE AT Examples for more details. AT+BLEINIT=2 // role: server AT+BLEGATTSSRVCRE AT+BLEGATTSSRVSTART AT+BLEADVSTART // starts advertising. After the client is connected, it must be configured to Example receive indications.
  • Page 61: At+Blegattcprimsrv-Gattc Discovers Primary Services

    6. BLE-Related AT Commands 6.2.24. AT+BLEGATTCPRIMSRV—GATTC Discovers Primary Services Query Command: Commands AT+BLEGATTCPRIMSRV=<conn_index> Function: GATTC discovers primary services. +BLEGATTCPRIMSRV:<conn_index>,<srv_index>,<srv_uuid>,<srv_type> Response <conn_index>: index of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future. <srv_index>: service's index starting from 1 Parameters <srv_uuid>: service's UUID...
  • Page 62: At+Blegattcchar-Gattc Discovers Characteristics

    6. BLE-Related AT Commands AT+BLEINIT=1 // role: client AT+BLECONN=0,"24:12:5f:9d:91:98" Example AT+BLEGATTCPRIMSRV=0 AT+BLEGATTCINCLSRV=0,1 // set a specific index according to the result of the previous command 6.2.26. AT+BLEGATTCCHAR—GATTC Discovers Characteristics Set Command: Commands AT+BLEGATTCCHAR=<conn_index>,<srv_index> Function: GATTC discovers characteristics. // when showing a characteristic, it will be as: +BLEGATTCCHAR:"char",<conn_index>,<srv_index>,<char_index>,<char_uuid>,<char_p rop>...
  • Page 63: At+Blegattcwr-Gattc Writes Characteristic

    6. BLE-Related AT Commands +BLEGATTCRD:<conn_index>,<len>,<value> Response <conn_index>: index of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future. <srv_index>: service's index; it can be fetched with command AT+BLEGATTCPRIMSRV=<conn_index> <char_index>: characteristic's index;...
  • Page 64: At+Blesppcfg-Configures Ble Spp

    6. BLE-Related AT Commands <conn_index>: index of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future. <srv_index>: service's index; it can be fetched with command AT+BLEGATTCPRIMSRV=<conn_index> Parameters <char_index>: characteristic's index; it can be fetched with command AT+BLEGATTCCHAR=<conn_index>,<srv_index>...
  • Page 65 6. BLE-Related AT Commands <cfg_enable>: 0: clears BLE SPP configuration, the following four parameters need not to be set. • 1: sets BLE SPP configuration, the following four parameters have to be set. • <tx_srv_index>: the index of the service that contains the target characteristic for sending data.
  • Page 66: At+Blespp-Enables Ble Spp

    Function: to enable BLE SPP (Serial Port Profile, UART-BLE passthrough mode). // waiting for serial data > The wrap return is > after this command is executed. Then, ESP32 enters UART-BLE Response passthrough mode. When a single packet containing +++ is received, ESP32 returns to normal command mode.
  • Page 67: At+Blesecparam-Set Parameters Of Ble Smp

    6. BLE-Related AT Commands AT+BLEINIT=2 // role: server AT+BLEGATTSSRVCRE AT+BLEGATTSSRVSTART AT+BLEGATTSCHAR? AT+BLEADVSTART // start advertising // After a BLE client connects to the ESP server, the message +BLECONN:0,<client MAC> will return. Example // For example, to configure the 7th characteristic in the 1st service as a TX channel for sending data;...
  • Page 68: At+Bleenc-Starts A Pairing Request

    6. BLE-Related AT Commands <auth_req>: authentication requirements ‣ 0: ESP_LE_AUTH_NO_BOND ‣ 1: ESP_LE_AUTH_BOND ‣ 2: ESP_LE_AUTH_REQ_MITM ‣ 4: ESP_LE_AUTH_REQ_SC_ONLY ‣ 5: ESP_LE_AUTH_REQ_SC_BOND ‣ 6: ESP_LE_AUTH_REQ_SC_MITM ‣ 7: ESP_LE_AUTH_REQ_SC_MITM_BOND <iocap>: IO capabilities ‣ 0: ESP_IO_CAP_OUT    /*!< DisplayOnly */        ‣ 1: ESP_IO_CAP_IO    /*!< DisplayYesNo */        ‣ 2: ESP_IO_CAP_IN    /*!< KeyboardOnly */        ‣ 3: ESP_IO_CAP_NONE    /*!< NoInputNoOutput */   ‣ 4: ESP_IO_CAP_KBDISP    /*!< Keyboard display */  Parameters <key_size>: encryption key size, range : [7, 16] <init_key>: ‣...
  • Page 69: At+Bleencrsp-Sets A Pairing Response

    6. BLE-Related AT Commands 6.2.33. AT+BLEENCRSP—Sets a Pairing Response Set Command: Commands AT+BLEENCRSP=<conn_index>,<accept> Function: to set a pairing response. Response <conn_index>: index of BLE connection; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future. Parameters <accept>: ‣...
  • Page 70: At+Bleencdev-Lists All Devices That Bonded

    6. BLE-Related AT Commands 6.2.36. AT+BLEENCDEV—Lists All Devices that Bonded Query Command: Command AT+BLEENCDEV? +BLEENCDEV:<enc_dev_index>,<mac_address> Response <enc_dev_index>: index of bonded devices; only 0 is supported for the single connection right now, but multiple BLE connections will be supported in the future. Parameters <mac_address>: Mac address Example...
  • Page 71: At Commands With Configuration Saved In The Nvs Area

    AT+CIPAPMAC AT+CIPAPMAC="1a:fe:36:97:d5:7b" AT+CIPSTA AT+CIPSTA="192.168.6.100" AT+CIPAP AT+CIPAP="192.168.5.1" AT+CWDHCPS AT+CWDHCPS=1,3,"192.168.4.10","192.168.4.15" AT+SAVETRANSLINK AT+SAVETRANSLINK=1,"192.168.6.10",1001 AT+CWMODE AT+CWMODE=3 AT+CWJAP AT+CWJAP="abc","0123456789" AT+CWSAP AT+CWSAP="ESP32","12345678",5,3 AT+CWAUTOCONN AT+CWAUTOCONN=1 AT+CIPSSLCCONF AT+CIPSSLCCONF=1,3,0,0 ⚠ Notice: NVS parameter area is 0xFA000 ~ 0x110000, and it is 88 KB in size. Espressif 65 97 2019.06...
  • Page 72: At Messages

    8. AT Messages AT Messages Messages of ESP32 AT are as below: Messages Description The AT firmware is ready. ready AT command error, or error occurred during execution. ERROR ESP station connected to an AP. WIFI CONNECTED ESP station got IP address.
  • Page 73: At Commands Examples

    AT+CIFSR Response: 192.168.3.106 // device got an IP from router 4. Connect the PC to the same router which ESP32 is connected to. Use a network tool on the PC to create a TCP server. - For example, the TCP server on PC is 192.168.3.116, port 8080.
  • Page 74: Udp Transmission

    Response: +CIFSR:STAIP,"192.168.101.104" // IP address of ESP32 Station 4. Connect the PC to the same router which ESP32 is connected to. Use a network tool on the PC to create UDP transmission. - For example, the PC's IP address is 192.168.101.116 and the port is 8080.
  • Page 75: Udp (With Changeable Remote Ip And Port)

    "192.168.101.110" and 8080 are the remote IP and port of UDP transmission on the remote side, i.e., • the UDP configuration set by PC. 1112 is the local port number of ESP32. Users can define this port number. The value of this parameter • will be random if it is not defined beforehand.
  • Page 76: Transparent Transmission

    PC in Section 9.2.1. • 1112 is the local port of ESP32. Users can define this port. The value of this parameter will be random if it is not defined beforehand. 2 means the means the opposite terminal of UDP transmission can be changed. The remote IP and •...
  • Page 77: Esp32 As A Tcp Client In Uart-Wi-Fi Passthrough (Single Connection Mode)

    Response: 192.168.101.105 // device's IP that got from router 4. Connect the PC to the same router to which ESP32 is connected. Use a network tool on the PC to create a TCP server. - For example, the PC's IP address is 192.168.101.110 and the port is 8080.
  • Page 78: Udp Transmission (Uart-Wi-Fi Passthroughtransmission)

    AT+CIPCLOSE Response: CLOSED 9.3.2. UDP Transmission (UART-Wi-Fi PassthroughTransmission) Here is an example of the ESP32 working as a SoftAP in UDP transparent transmission. 1. Set the Wi-Fi mode: AT+CWMODE=3 // SoftAP+Station mode Response: 2. Connect the PC to the ESP32 SoftAP: 3. Use a network tool on PC to create a UDP.
  • Page 79 9. AT Commands Examples 4. Create a UDP transmission between ESP32 and the PC with a fixed remote IP and port. AT+CIPSTART="UDP","192.168.4.2",1001,2233,0 Response: 5. Enable the transparent transmission mode: AT+CIPMODE=1 Response: 6. Send data: AT+CIPSEND Response: > // from now on, data received from UART will be transparent transmitted to server 7. Stop sending data: When receiving a packet that contains only “+++”, the UART-WiFi passthrough...
  • Page 80: Esp32 As A Tcp Server In Multiple Connections

    ⚠ Notice: When ESP32 works as a TCP server, there is a timeout mechanism. If the TCP client is connected to the ESP32 TCP server, while there is no data transmission for a period of time, the server will disconnect from the client.
  • Page 81 9. AT Commands Examples 6. Send data: // ID number of connection is defaulted to be 0 AT+CIPSEND=0,4 // send 4 bytes to connection NO.0 >TEST // enter the data, no CR Response: SEND OK ⚠ Notice: • If the number of bytes inputted are more than the size defined (n): the system will reply busy, and send the first n bytes. and after sending the first n bytes, the system will reply SEND OK. 7.
  • Page 82: Ble At Examples

    Used to identify the location of a specific Beacon within a store TX power Used to calculate the distance between the ESP32 device and the phone 9.5.1.1. ESP32 Device Advertising iBeacons 1. Initialize the role of the ESP32 device as a BLE server: AT+BLEINIT=2 // server role Response:...
  • Page 83 MCU. ⚠ Notice: If the ESP32 device has already been initialized as a BLE server, you need to call AT+BLEINIT=0 to de-init it first, and then re-init it as a BLE client. 1. Initialize the role of the ESP32 device as a BLE client:...
  • Page 84: Ble Communication Examples

    BLE Communication Examples 9.5.2.1. Basic Communication Below is an example of using two ESP32 modules, one as a BLE server (hereafter named "ESP32 Server") and the other one as a BLE client (hereafter named "ESP32 Client"). The example shows how to use BLE functions with AT commands.
  • Page 85 9. AT Commands Examples Response: ESP32 Client: • AT+BLEINIT=1 // client role Response: 2. Establish BLE connection: ESP32 Server: • - Query the BLE address. For example, if the address is "24:0a:c4:03:f4:d6". AT+BLEADDR? // get server's BLE address Response: +BLEADDR:24:0a:c4:03:f4:d6 - Configure parameters of advertisements. This is optional, though. If you do not configure the parameters of advertisements, default parameters will be applied.
  • Page 86 9. AT Commands Examples AT+BLEADVSTART Response: ESP32 Client: • - Configure the scanning parameters. This is optional, though. For example, in the active-scan mode, the command is as follows: AT+BLESCANPARAM=1,0,0,100,50 Response: - Start scanning. AT+BLESCAN=1,3 Response: +BLESCAN:<BLE address>,<rssi>,<adv_data>,<scan_rsp_data> - Establish the BLE connection, when the server is scanned successfully.
  • Page 87 9. AT Commands Examples AT+BLECFGMTU=0,200 You can also query the result: AT+BLECFGMTU? +BLECFGMTU:0,200 3. Read/Write a characteristic: ESP32 Server: • - Discover local services. AT+BLEGATTSSRV? Response: +BLEGATTSSRV:1,1,0xA002,1 - Discover characteristics. AT+BLEGATTSCHAR? Response: +BLEGATTSCHAR:"char",1,1,0xC300 +BLEGATTSCHAR:"desc",1,1,1 +BLEGATTSCHAR:"char",1,2,0xC301 +BLEGATTSCHAR:"desc",1,2,1 +BLEGATTSCHAR:"char",1,3,0xC302 +BLEGATTSCHAR:"desc",1,3,1 ESP32 Client: •...
  • Page 88 • For example, the <srv_index> of the above-mentioned service, 0xA002, is 3 when the ESP32 Client is in the process of discovering services. But if the ESP32 Server tries to discover it with command AT+BLEGATTSSRV?, the <srv_index> will be 1.
  • Page 89 • If the ESP32 Client receives the notification, it will prompt message +NOTIFY:<conn_index>,<srv_index>,<char_index>, <len>,<value>. • For the same service, the <srv_index> on the ESP32 Client side equals the <srv_index> on the ESP32 Server side + 2. 5. Indicate a characteristic: •...
  • Page 90 If the ESP32 Client receives the indication, it will prompt message +INDICATE:<conn_index>,<srv_index>,<char_index>, <len>,<value> • For the same service, the <srv_index> on the ESP32 Client side equals the <srv_index> on the ESP32 Server side + 2. 9.5.2.2. UART-BLE Passthrough Mode Below is an example of using two ESP32 modules: one as a BLE server (hereafter named as "ESP32 Server") and the other one as a BLE client (hereafter named as "ESP32 Client").
  • Page 91 9. AT Commands Examples Response: - Create services: AT+BLEGATTSSRVCRE Response: - Start services: AT+BLEGATTSSRVSTART Response: ESP32 Client: • AT+BLEINIT=1 // client role Response: 2. Establish BLE connection: • ESP32 Server: - Query the BLE address. The following section takes "24:0a:c4:03:f4:d6" as a example.
  • Page 92 9. AT Commands Examples - Start advertising. AT+BLEADVSTART Response: +BLEADDR:24:0a:c4:03:f4:d6 • ESP32 Client: - Start scanning: AT+BLESCAN=1,3 Response: +BLESCAN:<BLE address>,<rssi>,<adv_data>,<scan_rsp_data> - Establish the BLE connection, after the server is scanned successfully. AT+BLECONN=0,"24:0a:c4:03:f4:d6" Response: +BLECONN:0,"24:0a:c4:03:f4:d6" �� Notes: If the BLE connection is established successfully, the message •...
  • Page 93 • For example, the <srv_index> of the above-mentioned service, 0xA002, is 3 when the ESP32 Client is in the process of discovering services. But if the ESP32 Server tries to discover it with command AT+BLEGATTSSRV?, the <srv_index> will be 1.
  • Page 94 AT+BLESPP Response: > // waiting for serial data �� Note: After ESP32 Client enabling BLE SPP, data received from serial port will be transmitted to the BLE server directly. ESP32 Server: • - Set a characteristic that supports notification or indication to TX channel for sending data.
  • Page 95 • If the ESP32 Client does not enable BLE SPP first, or uses other device as BLE client, then the BLE client needs to listen to the notification or indication first. For example, if the ESP32 Client does not enable BLE SPP first, then it should enable listening with command AT+BLEGATTCWR=0,3,7,1,1 first...
  • Page 96: Ota Update

    10. OTA Update OTA Update The following steps guide the users in creating a device on and updating iot.espressif.cn the OTA BIN on it. 1. Open the website iot.espressif.cn. If using SSL OTA, it should be https://iot.espressif.cn. 2. Click "Join" in the upper right corner of the webpage, and enter your name, email address, and password.
  • Page 97 10. OTA Update 4. A key is generated when the device is successfully created, as the figure below shows. Espressif 91 97 2019.06...
  • Page 98 10. OTA Update 5. Use the key to compile your own OTA BIN. The process of configuring the AT OTA token key is as follows: Espressif 92 97 2019.06...
  • Page 99 10. OTA Update ⚠ Notice: If using SSL OTA, the option "OTA based upon ssl" should be selected. 6. Click on "Product" to enter the webpage, as shown below. Click on the device created. Enter version and corename under "ROM Deploy". Rename the BIN compiled in Step 5 as "ota.bin"...
  • Page 100 10. OTA Update 7. Click on the ota.bin to save it as the current version. Espressif 94 97 2019.06...
  • Page 101 10. OTA Update 8. Run the command AT+CIUPDATE. If the network is connected, OTA update w.
 Espressif 95 97 2019.06...
  • Page 102: Q & A

    11. Q & A Q & A If you have any questions about the execution of AT commands, please contact us via Espressif Technical Inquiries. Please describe the issues that you might encounter, including any relevant details, as follows: AT Version information or AT Command: You can use command AT+GMR to acquire •...
  • Page 103 Disclaimer and Copyright Notice Information in this document, including URL references, is subject to change without notice. THIS DOCUMENT IS PROVIDED AS IS WITH NO WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY, NON-INFRINGEMENT, FITNESS FOR ANY PARTICULAR PURPOSE, OR ANY WARRANTY OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE.

Table of Contents