.. _BLE-AT:
[ESP32 Only] Bluetooth® Low Energy AT Commands
=====================================================
:link_to_translation:`zh_CN:[中文]`
ESP32 AT firmware supports `Bluetooth® Core Specification Version 5.0 `_.
- [ESP32 Only] :ref:`AT+BLEINIT `: Bluetooth LE initialization.
- [ESP32 Only] :ref:`AT+BLEADDR `: Query/Set Bluetooth LE device address.
- [ESP32 Only] :ref:`AT+BLENAME `: Query/Set Bluetooth LE device name.
- [ESP32 Only] :ref:`AT+BLESCANPARAM `: Query/Set parameters of Bluetooth LE scanning.
- [ESP32 Only] :ref:`AT+BLESCAN `: Enable Bluetooth LE scanning.
- [ESP32 Only] :ref:`AT+BLESCANRSPDATA `: Set Bluetooth LE scan response.
- [ESP32 Only] :ref:`AT+BLEADVPARAM `: Query/Set parameters of Bluetooth LE advertising.
- [ESP32 Only] :ref:`AT+BLEADVDATA `: Set Bluetooth LE advertising data.
- [ESP32 Only] :ref:`AT+BLEADVDATAEX `: Automatically set Bluetooth LE advertising data.
- [ESP32 Only] :ref:`AT+BLEADVSTART `: Start Bluetooth LE advertising.
- [ESP32 Only] :ref:`AT+BLEADVSTOP `: Stop Bluetooth LE advertising.
- [ESP32 Only] :ref:`AT+BLECONN `: Establish Bluetooth LE connection.
- [ESP32 Only] :ref:`AT+BLECONNPARAM `: Query/Update parameters of Bluetooth LE connection.
- [ESP32 Only] :ref:`AT+BLEDISCONN `: End Bluetooth LE connection.
- [ESP32 Only] :ref:`AT+BLEDATALEN `: Set Bluetooth LE data packet length.
- [ESP32 Only] :ref:`AT+BLECFGMTU `: Set Bluetooth LE MTU length.
- [ESP32 Only] :ref:`AT+BLEGATTSSRVCRE `: Generic Attributes Server (GATTS) creates services.
- [ESP32 Only] :ref:`AT+BLEGATTSSRVSTART `: GATTS starts services.
- [ESP32 Only] :ref:`AT+BLEGATTSSRVSTOP `: GATTS Stops Services.
- [ESP32 Only] :ref:`AT+BLEGATTSSRV `: GATTS discovers services.
- [ESP32 Only] :ref:`AT+BLEGATTSCHAR `: GATTS discovers characteristics.
- [ESP32 Only] :ref:`AT+BLEGATTSNTFY `: Notify a client of the value of a characteristic value from the server.
- [ESP32 Only] :ref:`AT+BLEGATTSIND `: Indicate the characteristic value from the server to a client.
- [ESP32 Only] :ref:`AT+BLEGATTSSETATTR `: GATTS sets characteristics.
- [ESP32 Only] :ref:`AT+BLEGATTCPRIMSRV `: Generic Attributes Client (GATTC) discovers primary services.
- [ESP32 Only] :ref:`AT+BLEGATTCINCLSRV `: GATTC discovers included services.
- [ESP32 Only] :ref:`AT+BLEGATTCCHAR `: GATTC discovers characteristics.
- [ESP32 Only] :ref:`AT+BLEGATTCRD `: GATTC reads characteristics.
- [ESP32 Only] :ref:`AT+BLEGATTCWR `: GATTC writes characteristics.
- [ESP32 Only] :ref:`AT+BLESPPCFG `: Query/Set Bluetooth LE SPP parameters.
- [ESP32 Only] :ref:`AT+BLESPP `: Enter Bluetooth LE SPP mode.
- [ESP32 Only] :ref:`AT+BLESECPARAM `: Query/Set Bluetooth LE encryption parameters.
- [ESP32 Only] :ref:`AT+BLEENC `: Initiate Bluetooth LE encryption request.
- [ESP32 Only] :ref:`AT+BLEENCRSP `: Respond to the pairing request from the peer device.
- [ESP32 Only] :ref:`AT+BLEKEYREPLY `: Reply the key value to the peer device in the legacy connection stage.
- [ESP32 Only] :ref:`AT+BLECONFREPLY `: Reply the confirm value to the peer device in the legacy connection stage.
- [ESP32 Only] :ref:`AT+BLEENCDEV `: Query bonded Bluetooth LE encryption device list.
- [ESP32 Only] :ref:`AT+BLEENCCLEAR `: Clear Bluetooth LE encryption device list.
- [ESP32 Only] :ref:`AT+BLESETKEY `: Set Bluetooth LE static pair key.
- [ESP32 Only] :ref:`AT+BLEHIDINIT `: Bluetooth LE Human Interface Device (HID) profile initialization.
- [ESP32 Only] :ref:`AT+BLEHIDKB `: Send Bluetooth LE HID keyboard information.
- [ESP32 Only] :ref:`AT+BLEHIDMUS `: Send Bluetooth LE HID mouse information.
- [ESP32 Only] :ref:`AT+BLEHIDCONSUMER `: Send Bluetooth LE HID consumer information.
- [ESP32 Only] :ref:`AT+BLUFI `: Start or Stop BluFi.
- [ESP32 Only] :ref:`AT+BLUFINAME `: Query/Set BluFi device name.
.. _cmd-BINIT:
[ESP32 Only] :ref:`AT+BLEINIT `: Bluetooth LE Initialization
----------------------------------------------------------------------------
Query Command
^^^^^^^^^^^^^
**Function:**
Check the initialization status of Bluetooth LE.
**Command:**
::
AT+BLEINIT?
**Response:**
If Bluetooth LE is initialized, AT will return:
::
+BLEINIT:
OK
If Bluetooth LE is not initialized, AT will return:
::
+BLEINIT:0
OK
Set Command
^^^^^^^^^^^
**Function:**
Initialize the role of Bluetooth LE.
**Command:**
::
AT+BLEINIT=
**Response:**
::
OK
Parameter
^^^^^^^^^^
- ****:
- 0: deinit Bluetooth LE
- 1: client role
- 2: server role
Notes
^^^^^
- The file "at_customize.bin" has to be downloaded, so that the relevant commands can be used. Please refer to :doc:`../Compile_and_Develop/How_to_customize_BLE_services` for more details.
- Before using other Bluetooth LE AT commands, you should run this command first to trigger the initialization process.
- After the initialization, the Bluetooth LE role cannot be changed unless you run :ref:`AT+RST ` to restart the system first and then re-initialize the Bluetooth LE role.
- If you use an ESP device as a Bluetooth LE server, a service bin should be downloaded into flash.
- To learn how to generate a service bin, please refer to esp-at/tools/readme.md.
- The download address of the service bin is the "ble_data" address in esp-at/module_config/module_${platform}_default/at_customize.csv.
Example
^^^^^^^^
::
AT+BLEINIT=1
.. _cmd-BADDR:
[ESP32 Only] :ref:`AT+BLEADDR `: Query/Set Bluetooth LE Device Address
-------------------------------------------------------------------------------------
Query Command
^^^^^^^^^^^^^
**Function:**
Query the Bluetooth LE Public Address.
**Command:**
::
AT+BLEADDR?
**Response:**
::
+BLEADDR:
OK
Set Command
^^^^^^^^^^^
**Function:**
Set the Bluetooth LE address type.
**Command:**
::
AT+BLEADDR=[,]
**Response:**
::
OK
Parameter
^^^^^^^^^^
- ****:
- 0: Public Address
- 1: Random Address
Note
^^^^^
- A Static Address should meet the following requirements:
- The two most significant bits of the address should be equal to 1.
- At least one bit of the random part of the address should be 0.
- At least one bit of the random part of the address should be 1.
Example
^^^^^^^^
::
AT+BLEADDR=1,"f8:7f:24:87:1c:7b" // Set Random Device Address, Static Address
AT+BLEADDR=1 // Set Random Device Address, Private Address
AT+BLEADDR=0 // Set Public Device Address
.. _cmd-BNAME:
[ESP32 Only] :ref:`AT+BLENAME `: Query/Set Bluetooth LE Device Name
----------------------------------------------------------------------------------
Query Command
^^^^^^^^^^^^^
**Function:**
Query the Bluetooth LE device name.
**Command:**
::
AT+BLENAME?
**Response:**
::
+BLENAME:
OK
Set Command
^^^^^^^^^^^
**Function:**
Set the Bluetooth LE device name.
**Command:**
::
AT+BLENAME=
**Response:**
::
OK
Parameter
^^^^^^^^^^
- ****: the Bluetooth LE device name. The maximum length is 32. Default: "BLE_AT".
Note
^^^^^
- The configuration changes will be saved in the NVS area if :ref:`AT+SYSSTORE=1 `.
Example
^^^^^^^^
::
AT+BLENAME="esp_demo"
.. _cmd-BSCANP:
[ESP32 Only] :ref:`AT+BLESCANPARAM `: Query/Set Parameters of Bluetooth LE Scanning
--------------------------------------------------------------------------------------------------
Query Command
^^^^^^^^^^^^^
**Function:**
Query the parameters of Bluetooth LE scanning.
**Command:**
::
AT+BLESCANPARAM?
**Response:**
::
+BLESCANPARAM:,,,,
OK
Set Command
^^^^^^^^^^^
**Function:**
Set the parameters of Bluetooth LE scanning.
**Command:**
::
AT+BLESCANPARAM=,,,,
**Response:**
::
OK
Parameters
^^^^^^^^^^
- ****:
- 0: passive scan
- 1: active scan
- ****:
- 0: Public Address
- 1: Random Address
- 2: RPA Public Address
- 3: RPA Random Address
- ****:
- 0: BLE_SCAN_FILTER_ALLOW_ALL
- 1: BLE_SCAN_FILTER_ALLOW_ONLY_WLST
- 2: BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR
- 3: BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR
- ****: scan interval
- ****: scan window
Note
^^^^^
- The parameter ```` CANNOT be larger than ````.
Example
^^^^^^^^
::
AT+BLEINIT=1 // role: client
AT+BLESCANPARAM=0,0,0,100,50
.. _cmd-BSCAN:
[ESP32 Only] :ref:`AT+BLESCAN `: Enable Bluetooth LE Scanning
----------------------------------------------------------------------------
Set Command
^^^^^^^^^^^
**Function:**
Enable/disable scanning.
**Command:**
::
AT+BLESCAN=[,][,,]
**Response:**
::
+BLESCAN:,,,,
OK
Parameters
^^^^^^^^^^
- ****:
- 1: enable continuous scanning.
- 0: disable continuous scanning.
- **[]**: optional parameter. Unit: second.
- If you want to disable the scanning, this parameter should be omitted.
- If you want to enable the scanning, set a value for this parameter:
- When you set it to 0, it means that scanning is continuous.
- When set it to a value other than 0, for example, ``AT+BLESCAN=1,3``, it means that scanning will last for 3 seconds and then stop automatically. The scanning results will be returned.
- **[]**: filtering option.
- 1: "MAC".
- 2: "NAME".
- ****: filtering parameter showing the remote device MAC address or remote device name.
- ****: Bluetooth LE address.
- ****: signal strength.
- ****: advertising data.
- ****: scan response data.
- ****: the address type of broadcasters.
Notes
^^^^^
- The response ``OK`` does not necessarily come before the response ``+BLESCAN:,,,,``. It may be output before ``+BLESCAN:,,,,`` or after it.
Example
^^^^^^^^
::
AT+BLEINIT=1 // role: client
AT+BLESCAN=1 // start scanning
AT+BLESCAN=0 // stop scanning
AT+BLESCAN=1,3,1,"24:0A:C4:96:E6:88" // start scanning, filter type is MAC address
AT+BLESCAN=1,3,2,"ESP-AT" // start scanning, filter type is device name
.. _cmd-BSCANR:
[ESP32 Only] :ref:`AT+BLESCANRSPDATA `: Set Bluetooth LE Scan Response
-------------------------------------------------------------------------------------
Set Command
^^^^^^^^^^^
**Function:**
Set scan response.
**Command:**
::
AT+BLESCANRSPDATA=
**Response:**
::
OK
Parameter
^^^^^^^^^^
- ****: scan response data is a HEX string. For example, if you want to set the response data to "0x11 0x22 0x33 0x44 0x55", the command should be ``AT+BLESCANRSPDATA="1122334455"``.
Example
^^^^^^^^
::
AT+BLEINIT=2 // role: server
AT+BLESCANRSPDATA="1122334455"
.. _cmd-BADVP:
[ESP32 Only] :ref:`AT+BLEADVPARAM `: Query/Set Parameters of Bluetooth LE Advertising
----------------------------------------------------------------------------------------------------
Query Command
^^^^^^^^^^^^^
**Function:**
Query the parameters of advertising.
**Command:**
::
AT+BLEADVPARAM?
**Response:**
::
+BLEADVPARAM:,,,,,,,
OK
Set Command
^^^^^^^^^^^
**Function:**
Set the parameters of advertising.
**Command:**
::
AT+BLEADVPARAM=,, ,,[,][,] [,]
**Response:**
::
OK
Parameters
^^^^^^^^^^
- ****: minimum advertising interval. It should be less than the value of ````. Range: 0x0020 ~ 0x4000.
- ****: maximum advertising interval. It should be more than the value of ````. Range: 0x0020 ~ 0x4000.
- ****:
- 0: ADV_TYPE_IND
- 2: ADV_TYPE_SCAN_IND
- 3: ADV_TYPE_NONCONN_IND
- ****: own Bluetooth LE address type.
- 0: BLE_ADDR_TYPE_PUBLIC
- 1: BLE_ADDR_TYPE_RANDOM
- ****: channel of advertising.
- 1: ADV_CHNL_37
- 2: ADV_CHNL_38
- 4: ADV_CHNL_39
- 7: ADV_CHNL_ALL
- **[]**: filter policy of advertising.
- 0: ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY
- 1: ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY
- 2: ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST
- 3: ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST
- **[]**: remote Bluetooth LE address type.
- 0: PUBLIC
- 1: RANDOM
- **[]**: remote Bluetooth LE address.
Example
^^^^^^^^
::
AT+BLEINIT=2 // role: server
AT+BLEADVPARAM=50,50,0,0,4,0,0,"12:34:45:78:66:88"
.. _cmd-BADVD:
[ESP32 Only] :ref:`AT+BLEADVDATA `: Set Bluetooth LE Advertising Data
------------------------------------------------------------------------------------
Set Command
^^^^^^^^^^^
**Function:**
Set advertising data.
**Command:**
::
AT+BLEADVDATA=
**Response:**
::
OK
Parameter
^^^^^^^^^^
- ****: advertising data in HEX string. For example, to set the advertising data to "0x11 0x22 0x33 0x44 0x55", the command should be ``AT+BLEADVDATA="1122334455"``.
Note
^^^^^
- If advertising data is preset by command :ref:`AT+BLEADVDATAEX `\=,,,, it will be overwritten by this command.
Example
^^^^^^^^
::
AT+BLEINIT=2 // role: server
AT+BLEADVDATA="1122334455"
.. _cmd-BADVDEX:
[ESP32 Only] :ref:`AT+BLEADVDATAEX `: Automatically Set Bluetooth LE Advertising Data
----------------------------------------------------------------------------------------------------
Query Command
^^^^^^^^^^^^^
**Function:**
Query the parameters of advertising data.
**Command:**
::
AT+BLEADVDATAEX?
**Response:**
::
+BLEADVDATAEX:,,,
OK
Set Command
^^^^^^^^^^^
**Function:**
Set the advertising data and start advertising.
**Command:**
::
AT+BLEADVDATAEX=,,,
**Response:**
::
OK
Parameters
^^^^^^^^^^
- ****: string parameter showing a device name. For example, if you want to set the device name to "just-test", the command should be ``AT+BLEADVSTARTEX="just-test",,,``.
- ****: string parameter. For example, if you want to set the UUID to "0xA002", the command should be ``AT+BLEADVSTARTEX=,"A002",,``.
- ****: manufacturer data in HEX string. For example, if you set the manufacturer data to "0x11 0x22 0x33 0x44 0x55", the command should be ``AT+BLEADVSTARTEX=,,"1122334455",``.
- ****: If you need to include the TX power in the advertising data, you should set the parameter to ``1``. Otherwise, set it to ``0``.
Note
^^^^^
- If advertising data is preset by command :ref:`AT+BLEADVDATA `\=, it will be overwritten by this command.
Example
^^^^^^^^
::
AT+BLEINIT=2 // role: server
AT+BLEADVDATAEX="ESP-AT","A002","0102030405",1
.. _cmd-BADVSTART:
[ESP32 Only] :ref:`AT+BLEADVSTART `: Start Bluetooth LE Advertising
----------------------------------------------------------------------------------
Execute Command
^^^^^^^^^^^^^^^
**Function:**
Start advertising.
**Command:**
::
AT+BLEADVSTART
**Response:**
::
OK
Notes
^^^^^
- If advertising parameters are NOT set by command :ref:`AT+BLEADVPARAM `\=, the default parameters will be used.
- If advertising data is NOT set by command :ref:`AT+BLEADVDATA `\=, the advertising playload will be empty.
- If advertising data is preset by command :ref:`AT+BLEADVDATA `\=, it will be overwritten by :ref:`AT+BLEADVDATAEX `\=,,, and vice versa.
Example
^^^^^^^^
::
AT+BLEINIT=2 // role: server
AT+BLEADVSTART
.. _cmd-BADVSTOP:
[ESP32 Only] :ref:`AT+BLEADVSTOP `: Stop Bluetooth LE Advertising
--------------------------------------------------------------------------------
Execute Command
^^^^^^^^^^^^^^^
**Function:**
Stop advertising.
**Command:**
::
AT+BLEADVSTOP
**Response:**
::
OK
Note
^^^^^
- After the start of advertising, if the Bluetooth LE connection is established successfully, it will stop advertising automatically. In such a case, this command does NOT need to be called.
Example
^^^^^^^^
::
AT+BLEINIT=2 // role: server
AT+BLEADVSTART
AT+BLEADVSTOP
.. _cmd-BCONN:
[ESP32 Only] :ref:`AT+BLECONN `: Establish Bluetooth LE Connection
---------------------------------------------------------------------------------
Query Command
^^^^^^^^^^^^^
**Function:**
Query the Bluetooth LE connection.
**Command:**
::
AT+BLECONN?
**Response:**
::
+BLECONN:,
OK
If the connection has not been established, there will be no and in the response.
Set Command
^^^^^^^^^^^
**Function:**
Establish the Bluetooth LE connection.
**Command:**
::
AT+BLECONN=,[,,]
**Response:**
::
OK
If the connection is established successfully, it will prompt:
::
+BLECONN:,
Otherwise, it will prompt:
::
+BLECONN:,-1
Parameters
^^^^^^^^^^
- ****: index of Bluetooth LE connection. Range: [0,2].
- ****: remote Bluetooth LE address.
- **[]**: the address type of broadcasters.
- **[]**: the timeout for the connection command. Unit: second. Range: [3,30].
Notes
^^^^^
- It is recommended to scan devices by running :ref:`AT+BLESCAN ` before initiating a new connection to ensure that the target device is in the broadcast state.
- The maximum timeout for connection is 30 seconds.
- If the Bluetooth LE server is initialized and the connection is established successfully, you can use this command to discover the services in the peer device (GATTC). The following GATTC commands can also be used:
- :ref:`AT+BLEGATTCPRIMSRV `
- :ref:`AT+BLEGATTCINCLSRV `
- :ref:`AT+BLEGATTCCHAR `
- :ref:`AT+BLEGATTCRD `
- :ref:`AT+BLEGATTCWR `
- :ref:`AT+BLEGATTSIND `
Example
^^^^^^^^
::
AT+BLEINIT=1 // role: client
AT+BLECONN=0,"24:0a:c4:09:34:23",0,10
.. _cmd-BCONNP:
[ESP32 Only] :ref:`AT+BLECONNPARAM `: Query/Update Parameters of Bluetooth LE Connection
-------------------------------------------------------------------------------------------------------
Query Command
^^^^^^^^^^^^^
**Function:**
Query the parameters of Bluetooth LE connection.
**Command:**
::
AT+BLECONNPARAM?
**Response:**
::
+BLECONNPARAM:,,,,,
OK
Set Command
^^^^^^^^^^^
**Function:**
Update the parameters of Bluetooth LE connection.
**Command:**
::
AT+BLECONNPARAM=,,,,
**Response:**
::
OK
If the setting fails, it will prompt the message below:
::
+BLECONNPARAM: ,-1
Parameters
^^^^^^^^^^
- ****: index of Bluetooth LE connection. Range: [0,2].
- ****: minimum connecting interval. Range: 0x0006 ~ 0x0C80.
- ****: maximum connecting interval. Range: 0x0006 ~ 0x0C80.
- ****: current connecting interval.
- ****: latency. Range: 0x0000 ~ 0x01F3.
- ****: timeout. Range: 0x000A ~ 0x0C80.
Note
^^^^^
- This command only supports the client role when updating its connection parameters. Of course, the connection has to be established first.
Example
^^^^^^^^
::
AT+BLEINIT=1 // role: client
AT+BLECONN=0,"24:0a:c4:09:34:23"
AT+BLECONNPARAM=0,12,14,1,500
.. _cmd-BDISC:
[ESP32 Only] :ref:`AT+BLEDISCONN `: End Bluetooth LE Connection
------------------------------------------------------------------------------
Execute Command
^^^^^^^^^^^^^^^
**Function:**
End the Bluetooth LE connection.
**Command:**
::
AT+BLEDISCONN=
**Response:**
::
OK // The AT+BLEDISCONN command is received.
+BLEDISCONN:, // The command is successful.
Parameters
^^^^^^^^^^
- ****: index of Bluetooth LE connection. Range: [0,2].
- ****: remote Bluetooth LE address.
Note
^^^^^
- Only clients can call this command to terminate the connection.
Example
^^^^^^^^
::
AT+BLEINIT=1 // role: client
AT+BLECONN=0,"24:0a:c4:09:34:23"
AT+BLEDISCONN=0
.. _cmd-BDLEN:
[ESP32 Only] :ref:`AT+BLEDATALEN `: Set Bluetooth LE Data Packet Length
---------------------------------------------------------------------------------------
Set Command
^^^^^^^^^^^
**Function:**
Set the length of Bluetooth LE data packet.
**Command:**
::
AT+BLEDATALEN=,
**Response:**
::
OK
Parameters
^^^^^^^^^^
- ****: index of Bluetooth LE connection. Range: [0,2].
- ****: data packet's length. Range: 0x001b ~ 0x00fb.
Note
^^^^^
- The Bluetooth LE connection has to be established first.
Example
^^^^^^^^
::
AT+BLEINIT=1 // role: client
AT+BLECONN=0,"24:0a:c4:09:34:23"
AT+BLEDATALEN=0,30
.. _cmd-BMTU:
[ESP32 Only] :ref:`AT+BLECFGMTU `: Set Bluetooth LE MTU Length
-----------------------------------------------------------------------------
Query Command
^^^^^^^^^^^^^
**Function:**
Query the length of the maximum transmission unit (MTU).
**Command:**
::
AT+BLECFGMTU?
**Response:**
::
+BLECFGMTU:,
OK
Set Command
^^^^^^^^^^^
**Function:**
Set the length of the maximum transmission unit (MTU).
**Command:**
::
AT+BLECFGMTU=,
**Response:**
::
OK // The command is received.
Parameters
^^^^^^^^^^
- ****: index of Bluetooth LE connection. Range: [0,2].
- ****: MTU length.
Notes
^^^^^
- Bluetooth LE connection has to be established first.
- Only the client can call this command to set the length of MTU.
- The actual length of MTU needs to be negotiated. The ``OK`` response only indicates an attempt to negotiate the length. The actual length may not be the value you set. Therefore, it is recommended to run command :ref:`AT+BLECFGMTU? ` to query the actual length.
Example
^^^^^^^^
::
AT+BLEINIT=1 // role: client
AT+BLECONN=0,"24:0a:c4:09:34:23"
AT+BLECFGMTU=0,300
.. _cmd-GSSRVCRE:
[ESP32 Only] :ref:`AT+BLEGATTSSRVCRE `: GATTS Creates Services
------------------------------------------------------------------------------
Execute Command
^^^^^^^^^^^^^^^
**Function:**
The Generic Attributes Server (GATTS) creates Bluetooth LE services.
**Command:**
::
AT+BLEGATTSSRVCRE
**Response:**
::
OK
Notes
^^^^^
- If you are using an ESP device as a Bluetooth LE 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 esp-at/tools/readme.md.
- The download address of the service bin is the "ble_data" address in esp-at/module_config/module_${platform}_default/at_customize.csv.
- This command should be called immediately to create services, right after the Bluetooth LE server is initialized; If a Bluetooth LE connection is established first, the service creation will fail.
- If the Bluetooth LE client is initialized, you can use this command to create local services. Some GATTS commands can also be used, such as those to start and stop services, set attribute values, and send notifications/indications. See the list below for the specific commands.
- :ref:`AT+BLEGATTSSRVCRE ` (It is recommended to execute this command before the connection is established)
- :ref:`AT+BLEGATTSSRVSTART ` (It is recommended to execute this command before the connection is established)
- :ref:`AT+BLEGATTSSRV `
- :ref:`AT+BLEGATTSCHAR `
- :ref:`AT+BLEGATTSNTFY `
- :ref:`AT+BLEGATTSIND `
- :ref:`AT+BLEGATTSSETATTR `
Example
^^^^^^^^
::
AT+BLEINIT=2 // role: server
AT+BLEGATTSSRVCRE
.. _cmd-GSSRVSTART:
[ESP32 Only] :ref:`AT+BLEGATTSSRVSTART `: GATTS Starts Services
------------------------------------------------------------------------------
Execute Command
^^^^^^^^^^^^^^^
**Function:**
GATTS starts all services.
**Command:**
::
AT+BLEGATTSSRVSTART
Set Command
^^^^^^^^^^^
**Function:**
GATTS starts a specific service.
**Command:**
::
AT+BLEGATTSSRVSTART=
**Response:**
::
OK
Parameter
^^^^^^^^^^
- ****: service's index starting from 1.
Example
^^^^^^^^
::
AT+BLEINIT=2 // role: server
AT+BLEGATTSSRVCRE
AT+BLEGATTSSRVSTART
.. _cmd-GSSRVSTOP:
[ESP32 Only] :ref:`AT+BLEGATTSSRVSTOP