.. _BT-AT: [ESP32 Only] Classic Bluetooth® AT Commands ============================================ :link_to_translation:`zh_CN:[中文]` ESP32 AT firmware supports `Bluetooth® Core Specification Version 5.0 `_. - [ESP32 Only] :ref:`AT+BTINIT `: Classic Bluetooth initialization. - [ESP32 Only] :ref:`AT+BTNAME `: Query/Set Classic Bluetooth device name. - [ESP32 Only] :ref:`AT+BTSCANMODE `: Set Classic Bluetooth scan mode. - [ESP32 Only] :ref:`AT+BTSTARTDISC `: Start Classic Bluetooth discovery. - [ESP32 Only] :ref:`AT+BTSPPINIT `: Classic Bluetooth SPP profile initialization. - [ESP32 Only] :ref:`AT+BTSPPCONN `: Query/Establish SPP connection. - [ESP32 Only] :ref:`AT+BTSPPDISCONN `: End SPP connection. - [ESP32 Only] :ref:`AT+BTSPPSTART `: Start Classic Bluetooth SPP profile. - [ESP32 Only] :ref:`AT+BTSPPSEND `: Send data to remote Classic Bluetooth SPP device. - [ESP32 Only] :ref:`AT+BTA2DPINIT `: Classic Bluetooth A2DP profile initialization. - [ESP32 Only] :ref:`AT+BTA2DPCONN `: Establish A2DP connection. - [ESP32 Only] :ref:`AT+BTA2DPDISCONN `: End A2DP connection. - [ESP32 Only] :ref:`AT+BTA2DPSRC `: Query/Set the audio file URL. - [ESP32 Only] :ref:`AT+BTA2DPCTRL `: Control the audio play. - [ESP32 Only] :ref:`AT+BTSECPARAM `: Query/Set the Classic Bluetooth security parameters. - [ESP32 Only] :ref:`AT+BTKEYREPLY `: Input the Simple Pair Key. - [ESP32 Only] :ref:`AT+BTPINREPLY `: Input the Legacy Pair PIN Code. - [ESP32 Only] :ref:`AT+BTSECCFM `: Reply the confirm value to the peer device in the legacy connection stage. - [ESP32 Only] :ref:`AT+BTENCDEV `: Query Classic Bluetooth encryption device list. - [ESP32 Only] :ref:`AT+BTENCCLEAR `: Clear Classic Bluetooth encryption device list. - [ESP32 Only] :ref:`AT+BTCOD `: Set class of devices. - [ESP32 Only] :ref:`AT+BTPOWER `: Query/Set power of Classic Bluetooth. .. _cmd-BTINIT: [ESP32 Only] :ref:`AT+BTINIT `: Classic Bluetooth Initialization --------------------------------------------------------------------------- Query Command ^^^^^^^^^^^^^ **Function:** Query the initialization status of Classic Bluetooth. **Command:** :: AT+BTINIT? **Response:** If Classic Bluetooth is initialized, AT will return: :: +BTINIT:1 OK If Classic Bluetooth is not initialized, AT will return: :: +BTINIT:0 OK Set Command ^^^^^^^^^^^ **Function:** Initialize or deinitialize Classic Bluetooth. **Command:** :: AT+BTINIT= **Response:** :: OK Parameter ^^^^^^^^^^ - ****: - 0: deinitialize Classic Bluetooth. - 1: initialize Classic Bluetooth. Example ^^^^^^^^ :: AT+BTINIT=1 .. _cmd-BTNAME: [ESP32 Only] :ref:`AT+BTNAME `: Query/Set Classic Bluetooth Device Name ------------------------------------------------------------------------------- Query Command ^^^^^^^^^^^^^ **Function:** Query the Classic Bluetooth device name. **Command:** :: AT+BTNAME? **Response:** :: +BTNAME: OK Set Command ^^^^^^^^^^^ **Function:** Set the Classic Bluetooth device name. **Command:** :: AT+BTNAME= **Response:** :: OK Parameter ^^^^^^^^^^ - ****: the Classic Bluetooth device name. The maximum length is 32. Notes ^^^^^ - The configuration changes will be saved in the NVS area if :ref:`AT+SYSSTORE=1 `. - The default Classic Bluetooth device name is "ESP32_AT". Example ^^^^^^^^ :: AT+BTNAME="esp_demo" .. _cmd-BTSCANMODE: [ESP32 Only] :ref:`AT+BTSCANMODE `: Set Classic Bluetooth Scan Mode --------------------------------------------------------------------------- Set Command ^^^^^^^^^^^ **Function:** Set the scan mode of Classic Bluetooth. **Command:** :: AT+BTSCANMODE= **Response:** :: OK Parameter ^^^^^^^^^^ - ****: - 0: Neither discoverable nor connectable. - 1: Connectable but not discoverable. - 2: Both discoverable and connectable. - 3: Discoverable but not connectable. Example ^^^^^^^^ :: AT+BTSCANMODE=2 // both discoverable and connectable .. _cmd-BTDISC: [ESP32 Only] :ref:`AT+BTSTARTDISC `: Start Classic Bluetooth Discovery ------------------------------------------------------------------------------- Set Command ^^^^^^^^^^^ **Function:** Start Classic Bluetooth discovery. **Command:** :: AT+BTSTARTDISC=,, **Response:** :: +BTSTARTDISC:,,,,, OK Parameters ^^^^^^^^^^ - ****: - 0: general inquiry mode. - 1: limited inquiry mode. - ****: inquiry duration. Range: 0x01 ~ 0x30. - ****: number of inquiry responses that can be received. If you set it to 0, AT will receive an unlimited number of responses. - ****: Classic Bluetooth address. - ****: device name. - ****: - 0x0: miscellaneous. - 0x1: computer. - 0x2: phone (cellular, cordless, pay phone, modem). - 0x3: LAN, Network Access Point. - 0x4: audio/video (headset, speaker, stereo, video display, VCR). - 0x5: peripheral (mouse, joystick, keyboard). - 0x6: imaging (printer, scanner, camera, display). - 0x7: wearable. - 0x8: toy. - 0x9: health. - 0x1F: uncategorized device. - ****: please refer to `Minor Device Class field `_. - ****: - 0x0: an invalid value. - 0x1: Limited Discoverable Mode. - 0x8: positioning (location identification). - 0x10: networking, such as LAN, Ad hoc. - 0x20: rendering, such as printing, speakers. - 0x40: capturing, such as scanner, microphone. - 0x80: object transfer, such as v-Inbox, v-Folder. - 0x100: audio, such as speaker, microphone, headerset service. - 0x200: telephony, such as cordless telephony, modem, headset service. - 0x400: information, such as WEB-server, WAP-server. - ****: signal strength. Example ^^^^^^^^ :: AT+BTINIT=1 AT+BTSCANMODE=2 AT+BTSTARTDISC=0,10,10 .. _cmd-BTSPPINIT: [ESP32 Only] :ref:`AT+BTSPPINIT `: Classic Bluetooth SPP Profile Initialization ------------------------------------------------------------------------------------------ Query Command ^^^^^^^^^^^^^ **Function:** Query the initialization status of Classic Bluetooth SPP profile. **Command:** :: AT+BTSPPINIT? **Response:** If Classic Bluetooth SPP profile is initialized, it will return: :: +BTSPPINIT:1 OK If Classic Bluetooth SPP profile is not initialized, it will return: :: +BTSPPINIT:0 OK Set Command ^^^^^^^^^^^ **Function:** Initialize or deinitialize Classic Bluetooth SPP profile. **Command:** :: AT+BTSPPINIT= **Response:** :: OK Parameter ^^^^^^^^^^ - ****: - 0: deinitialize Classic Bluetooth SPP profile. - 1: initialize Classic Bluetooth SPP profile, the role is master. - 2: initialize Classic Bluetooth SPP profile, the role is slave. Example ^^^^^^^^ :: AT+BTSPPINIT=1 // master AT+BTSPPINIT=2 // slave .. _cmd-BTSPPCONN: [ESP32 Only] :ref:`AT+BTSPPCONN `: Query/Establish SPP Connection ------------------------------------------------------------------------- Query Command ^^^^^^^^^^^^^ **Function:** Query Classic Bluetooth SPP connection. **Command:** :: AT+BTSPPCONN? **Response:** :: +BTSPPCONN:, OK If the connection has not been established, AT will return: :: +BTSPPCONN:-1 Set Command ^^^^^^^^^^^ **Function:** Establish the Classic Bluetooth SPP connection. **Command:** :: AT+BTSPPCONN=,, **Response:** :: OK If the connection is established successfully, AT will return: :: +BTSPPCONN:, Otherwise, AT will return: :: +BTSPPCONN:,-1 Parameters ^^^^^^^^^^ - ****: index of Classic Bluetooth SPP connection. Only 0 is supported for the single connection right now. - ****: - 0x0000: no security. - 0x0001: authorization required (only needed for out going connection). - 0x0036: encryption required. - 0x3000: Man-In-The-Middle protection. - 0x4000: Min 16 digit for pin code. - ****: remote Classic Bluetooth SPP device address. Example ^^^^^^^^ :: AT+BTSPPCONN=0,0,"24:0a:c4:09:34:23" .. _cmd-BTSPPDISCONN: [ESP32 Only] :ref:`AT+BTSPPDISCONN `: End SPP Connection -------------------------------------------------------------------- Execute Command ^^^^^^^^^^^^^^^ **Function:** End the Classic Bluetooth SPP connection. **Command:** :: AT+BTSPPDISCONN= **Response:** :: OK If the command is successful, it will prompt: :: +BTSPPDISCONN:, If the command is fail, it will prompt: :: +BTSPPDISCONN:-1 Parameters ^^^^^^^^^^ - ****: index of Classic Bluetooth SPP connection. Only 0 is supported for the single connection right now. - ****: remote Classic Bluetooth A2DP device address. Example ^^^^^^^^ :: AT+BTSPPDISCONN=0 .. _cmd-BTSPPSEND: [ESP32 Only] :ref:`AT+BTSPPSEND `: Send Data to Remote Classic Bluetooth SPP Device ----------------------------------------------------------------------------------------------- Execute Command ^^^^^^^^^^^^^^^ **Function:** Enter Classic Bluetooth SPP mode. **Command:** :: AT+BTSPPSEND **Response:** :: > Set Command ^^^^^^^^^^^^^^^ **Function:** Send data to the remote Classic Bluetooth SPP device. **Command:** :: AT+BTSPPSEND=, **Response:** :: OK Parameters ^^^^^^^^^^ - ****: index of Classic Bluetooth SPP connection. Only 0 is supported for the single connection right now. - ****: the length of the data which is ready to be sent. Notes ^^^^^ - The wrap return is > after this command is executed. Then, the ESP device enters UART Bluetooth passthrough mode. When the packet which only contains :ref:`+++ ` is received, the device returns to normal command mode. Please wait for at least one second before sending the next AT command. Example ^^^^^^^^ :: AT+BTSPPSEND=0,100 AT+BTSPPSEND .. _cmd-BTSPPSTART: [ESP32 Only] :ref:`AT+BTSPPSTART `: Start Classic Bluetooth SPP Profile --------------------------------------------------------------------------------------- Execute Command ^^^^^^^^^^^^^^^ **Function:** Start Classic Bluetooth SPP profile. **Command:** :: AT+BTSPPSTART **Response:** :: OK Note ^^^^ - During the SPP transmission, AT will not prompt any connection status changes unless bit2 of :ref:`AT+SYSMSG ` is 1. Example ^^^^^^^^ :: AT+BTSPPSTART .. _cmd-BTA2DPINIT: [ESP32 Only] :ref:`AT+BTA2DPINIT `: Classic Bluetooth A2DP Profile Initialization -------------------------------------------------------------------------------------------- Query Command ^^^^^^^^^^^^^ **Function:** Query the initialization status of Classic Bluetooth A2DP profile. **Command:** :: AT+BTA2DPINIT? **Response:** If Classic Bluetooth A2DP profile is initialized, AT will return: :: +BTA2DPINIT:1 OK Otherwise, AT will return: :: +BTA2DPINIT:0 OK Set Command ^^^^^^^^^^^ **Function:** Initialize or deinitialize Classic Bluetooth A2DP profile. **Command:** :: AT+BTA2DPINIT=, **Response:** :: OK Parameters ^^^^^^^^^^ - ****: - 0: source. - 1: sink. - ****: - 0: deinitialize Classic Bluetooth A2DP profile. - 1: initialize Classic Bluetooth A2DP profile. Example ^^^^^^^^ :: AT+BTA2DPINIT=0,1 .. _cmd-BTA2DPCONN: [ESP32 Only] :ref:`AT+BTA2DPCONN `: Query/Establish A2DP Connection --------------------------------------------------------------------------- Query Command ^^^^^^^^^^^^^ **Function:** Query Classic Bluetooth A2DP connection. **Command:** :: AT+BTA2DPCONN? **Response:** :: +BTA2DPCONN:, OK If the connection has not been established, AT will NOT return the parameter and . Set Command ^^^^^^^^^^^ **Function:** Establish the Classic Bluetooth A2DP connection. **Command:** :: AT+BTA2DPCONN=, **Response:** :: OK If the connection is established successfully, it will prompt the message below: :: +BTA2DPCONN:, Otherwise, it will return: :: +BTA2DPCONN:,-1 Parameters ^^^^^^^^^^ - ****: index of Classic Bluetooth A2DP connection. Only 0 is supported for the single connection right now. - ****: remote Classic Bluetooth A2DP device address. Example ^^^^^^^^ :: AT+BTA2DPCONN=0,0,0,"24:0a:c4:09:34:23" .. _cmd-BTA2DPDISCONN: [ESP32 Only] :ref:`AT+BTA2DPDISCONN `: End A2DP Connection ---------------------------------------------------------------------- Execute Command ^^^^^^^^^^^^^^^ **Function:** End the Classic Bluetooth A2DP connection. **Command:** :: AT+BTA2DPDISCONN= **Response:** :: +BTA2DPDISCONN:, OK Parameters ^^^^^^^^^^ - ****: index of Classic Bluetooth A2DP connection. Only 0 is supported for the single connection right now. - ****: remote Classic Bluetooth A2DP device address. Example ^^^^^^^^ :: AT+BTA2DPDISCONN=0 .. _cmd-BTA2DPSRC: [ESP32 Only] :ref:`AT+BTA2DPSRC `: Query/Set the Audio File URL ----------------------------------------------------------------------------- Query Command ^^^^^^^^^^^^^ **Function:** Query the audio file URL. **Command:** :: AT+BTA2DPSRC? **Response:** :: +BTA2DPSRC:, OK Execute Command ^^^^^^^^^^^^^^^ **Function:** Set the audio file URL. **Command:** :: AT+BTA2DPSRC=, **Response:** :: OK Parameters ^^^^^^^^^^ - ****: index of Classic Bluetooth A2DP connection. Only 0 is supported for the single connection right now. - ****: the path of the source file. HTTP, HTTPS and FLASH are currently supported. - ****: the type of audio file, such as "mp3". Note ^^^^^ - Only mp3 format is currently supported. Example ^^^^^^^^ :: AT+BTA2DPSRC=0,"https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.mp3" AT+BTA2DPSRC=0,"flash://spiffs/zhifubao.mp3" .. _cmd-BTA2DPCTRL: [ESP32 Only] :ref:`AT+BTA2DPCTRL `: Control the Audio Play --------------------------------------------------------------------- Execute Command ^^^^^^^^^^^^^^^ **Function:** Control the audio play. **Command:** :: AT+BTA2DPCTRL=, **Response:** :: OK Parameters ^^^^^^^^^^ - ****: index of Classic Bluetooth A2DP connection. Only 0 is supported for the single connection right now. - ****: types of control. - 0: A2DP Sink, stop play. - 1: A2DP Sink, start play. - 2: A2DP Sink, forward. - 3: A2DP Sink, backward. - 4: A2DP Sink, fastward start. - 5: A2DP Sink, fastward stop. - 0: A2DP Source, stop play. - 1: A2DP Source, start play. - 2: A2DP Source, suspend. Example ^^^^^^^^ :: AT+BTA2DPCTRL=0,1 // start play audio .. _cmd-BTSECPARAM: [ESP32 Only] :ref:`AT+BTSECPARAM `: Query/Set the Classic Bluetooth Security Parameters ------------------------------------------------------------------------------------------------------ Query Command ^^^^^^^^^^^^^ **Function:** Query Classic Bluetooth security parameters. **Command:** :: AT+BTSECPARAM? **Response:** :: +BTSECPARAM:,, OK Set Command ^^^^^^^^^^^ **Function:** Set the Classic Bluetooth security parameters. **Command:** :: AT+BTSECPARAM=,, **Response:** :: OK Parameters ^^^^^^^^^^ - ****: input and output capability. - 0: DisplayOnly. - 1: DisplayYesNo. - 2: KeyboardOnly. - 3: NoInputNoOutput. - ****: use variable or fixed PIN. - 0: variable. - 1: fixed. - ****: Legacy Pair PIN Code. Maximum: 16 bytes. Note ^^^^^ - If you set the parameter ```` to 0, ```` will be ignored. Example ^^^^^^^^ :: AT+BTSECPARAM=3,1,"9527" .. _cmd-BTKEYREPLY: [ESP32 Only] :ref:`AT+BTKEYREPLY `: Input the Simple Pair Key --------------------------------------------------------------------- Execute Command ^^^^^^^^^^^^^^^ **Function:** Input the Simple Pair Key. **Command:** :: AT+BTKEYREPLY=, **Response:** :: OK Parameters ^^^^^^^^^^ - ****: index of Classic Bluetooth connection. Currently, only 0 is supported for the single connection. - ****: the Simple Pair Key. Example ^^^^^^^^ :: AT+BTKEYREPLY=0,123456 .. _cmd-BTPINREPLY: [ESP32 Only] :ref:`AT+BTPINREPLY `: Input the Legacy Pair PIN Code ----------------------------------------------------------------------------- Execute Command ^^^^^^^^^^^^^^^ **Function:** Input the Legacy Pair PIN Code. **Command:** :: AT+BTPINREPLY=, **Response:** :: OK Parameters ^^^^^^^^^^ - ****: index of Classic Bluetooth connection. Currently, only 0 is supported for the single connection. - ****: the Legacy Pair PIN Code. Example ^^^^^^^^ :: AT+BTPINREPLY=0,"6688" .. _cmd-BTSECCFM: [ESP32 Only] :ref:`AT+BTSECCFM `: Reply the Confirm Value to the Peer Device in the Legacy Connection Stage ---------------------------------------------------------------------------------------------------------------------- Execute Command ^^^^^^^^^^^^^^^ **Function:** Reply the confirm value to the peer device in the legacy connection stage. **Command:** :: AT+BTSECCFM=, **Response:** :: OK Parameters ^^^^^^^^^^ - ****: index of Classic Bluetooth connection. Currently, only 0 is supported for the single connection. - ****: reject or accept. - 0: reject. - 1: accept. Example ^^^^^^^^ :: AT+BTSECCFM=0,1 .. _cmd-BTENCDEV: [ESP32 Only] :ref:`AT+BTENCDEV `: Query Classic Bluetooth Encryption Device List ---------------------------------------------------------------------------------------- Query Command ^^^^^^^^^^^^^ **Function:** Query the bound devices. **Command:** :: AT+BTENCDEV? **Response:** :: +BTENCDEV:, OK Parameters ^^^^^^^^^^ - ****: index of the bound devices. - ****: MAC address. Example ^^^^^^^^ :: AT+BTENCDEV? .. _cmd-BTENCCLEAR: [ESP32 Only] :ref:`AT+BTENCCLEAR `: Clear Classic Bluetooth Encryption Device List ------------------------------------------------------------------------------------------ Set Command ^^^^^^^^^^^ **Function:** Remove a device from the security database list with a specific index. **Command:** :: AT+BTENCCLEAR= **Response:** :: OK Execute Command ^^^^^^^^^^^^^^^ **Function:** Remove all devices from the security database. **Command:** :: AT+BLEENCCLEAR **Response:** :: OK Parameter ^^^^^^^^^^ - ****: index of the bound devices. Example ^^^^^^^^ :: AT+BTENCCLEAR .. _cmd-BTCOD: [ESP32 Only] :ref:`AT+BTCOD `: Set Class of Devices ------------------------------------------------------------- Set Command ^^^^^^^^^^^ **Function:** Set the Classic Bluetooth class of devices. **Command:** :: AT+BTCOD=,, **Response:** :: OK Parameters ^^^^^^^^^^ - ****: `major class `_. - ****: `minor class `_. - ****: `service class `_. Example ^^^^^^^^ :: AT+BTCOD=6,32,32 // the printer .. _cmd-BTPWR: [ESP32 Only] :ref:`AT+BTPOWER `: Query/Set TX power of Classic Bluetooth ------------------------------------------------------------------------------- Query Command ^^^^^^^^^^^^^ **Function:** Query Classic Bluetooth tx power level. **Command:** :: AT+BTPOWER? **Response:** :: +BTPOWER:, OK Set Command ^^^^^^^^^^^ **Function:** Set the Classic Bluetooth tx power. **Command:** :: AT+BTPOWER=, **Response:** :: OK Parameters ^^^^^^^^^^ - ****: The minimum power level. Range: [0,7]. - ****: The maximum power level. Range: [0,7]. Example ^^^^^^^^ :: AT+BTPOWER=5,6 // set Classic Bluetooth tx power.