data
stringlengths
512
2.99k
ICMP Echo Overview ICMP (Internet Control Message Protocol) is used for diagnostic or control purposes or generated in response to errors in IP operations. The common network util ping is implemented based on the ICMP packets with the type field value of 0, also called Echo Reply. During a ping session, the source host firstly sends out an ICMP echo request packet and wait for an ICMP echo reply with specific times. In this way, it also measures the round-trip time for the messages. After receiving a valid ICMP echo reply, the source host will generate statistics about the IP link layer (e.g., packet loss, elapsed time, etc). It is common that IoT device needs to check whether a remote server is alive or not. The device should show the warnings to users when it got offline. It can be achieved by creating a ping session and sending or parsing ICMP echo packets periodically. To make this internal procedure much easier for users, ESP-IDF provides some out-of-box APIs. Create a New Ping Session To create a ping session, you need to fill in the esp_ping_config_t configuration structure firstly, specifying target IP address, interval times, and etc. Optionally, you can also register some callback functions with the esp_ping_callbacks_t structure.
Mbed TLS Mbed TLS is a C library that implements cryptographic primitives, X.509 certificate manipulation and the SSL/TLS and DTLS protocols. Its small code footprint makes it suitable for embedded systems. Note ESP-IDF uses a fork of Mbed TLS which includes a few patches (related to hardware routines of certain modules like bignum (MPI) and ECC) over vanilla Mbed TLS. Mbed TLS supports SSL 3.0 up to TLS 1.3 and DTLS 1.0 to 1.2 communication by providing the following: TCP/IP communication functions: listen, connect, accept, read/write. SSL/TLS communication functions: init, handshake, read/write. X.509 functions: CRT, CRL and key handling Random number generation Hashing Encryption/decryption Supported TLS versions include SSL 3.0, TLS 1.0, TLS 1.1, TLS 1.2, and TLS 1.3, but on the latest ESP-IDF, SSL 3.0, TLS 1.0, and TLS 1.1 have been removed from Mbed TLS. Supported DTLS versions include DTLS 1.0, DTLS 1.1, and DTLS 1.2, but on the latest ESP-IDF, DTLS 1.0 has been removed from Mbed TLS. Mbed TLS Documentation For Mbed TLS documentation please refer to the following (upstream) pointers: Mbed TLS Support in ESP-IDF Please find the information about the Mbed TLS versions presented in different branches of ESP-IDF here. Note Please refer the Mbed TLS to migrate from Mbed TLS version 2.x to version 3.0 or greater. Application Examples Examples in ESP-IDF use ESP-TLS which provides a simplified API interface for accessing the commonly used TLS functionality. Refer to the examples protocols/https_server/simple (Simple HTTPS server) and protocols/https_request (Make HTTPS requests) for more information. If the Mbed TLS API is to be used directly, refer to the example protocols/https_mbedtls. Alternatives ESP-TLS acts as an abstraction layer over the underlying SSL/TLS library and thus has an option to use Mbed TLS or wolfSSL as the underlying library. By default, only Mbed TLS is available and used in ESP-IDF whereas wolfSSL is available publicly at <https://github.com/espressif/esp-wolfSSL> with the upstream submodule pointer. Please refer to ESP-TLS: Underlying SSL/TLS Library Options docs for more information on this and comparison of Mbed TLS and wolfSSL. Important Config Options Following is a brief list of important config options accessible at Component Config -> mbedTLS. The full list of config options can be found here.
CONFIG_MBEDTLS_SSL_PROTO_TLS1_2: Support for TLS 1.2 CONFIG_MBEDTLS_SSL_PROTO_TLS1_3: Support for TLS 1.3 CONFIG_MBEDTLS_CERTIFICATE_BUNDLE: Support for trusted root certificate bundle (more about this: ESP x509 Certificate Bundle) CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS: Support for TLS Session Resumption: Client session tickets CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS: Support for TLS Session Resumption: Server session tickets CONFIG_MBEDTLS_HARDWARE_SHA: Support for hardware SHA acceleration CONFIG_MBEDTLS_HARDWARE_AES: Support for hardware AES acceleration CONFIG_MBEDTLS_HARDWARE_MPI: Support for hardware MPI (bignum) acceleration Note Mbed TLS v3.0.0 and later support only TLS 1.2 and TLS 1.3 (SSL 3.0, TLS 1.0, TLS 1.1, and DTLS 1.0 are not supported). The support for TLS 1.3 is experimental and only supports the client-side. More information about this can be found out here. Performance and Memory Tweaks Reducing Heap Usage The following table shows typical memory usage with different configs when the protocols/https_request example (with Server Validation enabled) was run with Mbed TLS as the SSL/TLS library. | Mbed TLS Test | Related Configs | Heap Usage (approx.) | Default | NA | 42196 B | Enable SSL Variable Length | 42120 B | Disable Keep Peer Certificate | 38533 B | Enable Dynamic TX/RX Buffer | CONFIG_MBEDTLS_DYNAMIC_BUFFER CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA
Bluetooth® Generic Defines API Reference Header File This header file can be included with: #include "esp_bt_defs.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Structures - struct esp_bt_uuid_t UUID type. Macros - ESP_BLUEDROID_STATUS_CHECK(status) - ESP_BT_STATUS_BASE_FOR_HCI_ERR - ESP_BT_OCTET16_LEN - ESP_BT_OCTET8_LEN - ESP_DEFAULT_GATT_IF Default GATT interface id. - ESP_BLE_PRIM_ADV_INT_MIN Minimum advertising interval for undirected and low duty cycle directed advertising - ESP_BLE_PRIM_ADV_INT_MAX Maximum advertising interval for undirected and low duty cycle directed advertising - ESP_BLE_CONN_INT_MIN relate to BTM_BLE_CONN_INT_MIN in stack/btm_ble_api.h - ESP_BLE_CONN_INT_MAX relate to BTM_BLE_CONN_INT_MAX in stack/btm_ble_api.h - ESP_BLE_CONN_LATENCY_MAX relate to ESP_BLE_CONN_LATENCY_MAX in stack/btm_ble_api.h - ESP_BLE_CONN_SUP_TOUT_MIN relate to BTM_BLE_CONN_SUP_TOUT_MIN in stack/btm_ble_api.h - ESP_BLE_CONN_SUP_TOUT_MAX relate to ESP_BLE_CONN_SUP_TOUT_MAX in stack/btm_ble_api.h - ESP_BLE_IS_VALID_PARAM(x, min, max) Check the param is valid or not. - ESP_UUID_LEN_16 - ESP_UUID_LEN_32 - ESP_UUID_LEN_128 - ESP_BD_ADDR_LEN Bluetooth address length. - ESP_BLE_ENC_KEY_MASK Used to exchange the encryption key in the init key & response key. - ESP_BLE_ID_KEY_MASK Used to exchange the IRK key in the init key & response key. - ESP_BLE_CSR_KEY_MASK Used to exchange the CSRK key in the init key & response key. - ESP_BLE_LINK_KEY_MASK Used to exchange the link key(this key just used in the BLE & BR/EDR coexist mode) in the init key & response key. - ESP_APP_ID_MIN Minimum of the application id. - ESP_APP_ID_MAX Maximum of the application id. - ESP_BD_ADDR_STR - ESP_BD_ADDR_HEX(addr) Type Definitions - typedef uint8_t esp_bt_octet16_t[ESP_BT_OCTET16_LEN] - typedef uint8_t esp_bt_octet8_t[ESP_BT_OCTET8_LEN] - typedef uint8_t
Bluetooth® Main API API Reference Header File This header file can be included with: #include "esp_bt_main.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_bluedroid_status_t esp_bluedroid_get_status(void) Get bluetooth stack status. - Returns Bluetooth stack status - esp_err_t esp_bluedroid_enable(void) Enable bluetooth, must after esp_bluedroid_init()/esp_bluedroid_init_with_cfg(). - Returns ESP_OK : Succeed Other : Failed - - esp_err_t esp_bluedroid_disable(void) Disable bluetooth, must prior to esp_bluedroid_deinit(). - Returns ESP_OK : Succeed Other : Failed - - esp_err_t esp_bluedroid_init(void) Init and alloc the resource for bluetooth, must be prior to every bluetooth stuff. - Returns ESP_OK : Succeed Other : Failed - - esp_err_t esp_bluedroid_init_with_cfg(esp_bluedroid_config_t *cfg) Init and alloc the resource for bluetooth, must be prior to every bluetooth stuff. - Parameters cfg -- Initial configuration of ESP Bluedroid stack. - Returns ESP_OK : Succeed Other : Failed - Structures Macros - BT_BLUEDROID_INIT_CONFIG_DEFAULT() Enumerations - enum esp_bluedroid_status_t Bluetooth stack status type, to indicate whether the bluetooth stack is ready. Values: - enumerator ESP_BLUEDROID_STATUS_UNINITIALIZED Bluetooth not initialized - enumerator ESP_BLUEDROID_STATUS_INITIALIZED Bluetooth initialized but not enabled - enumerator ESP_BLUEDROID_STATUS_ENABLED Bluetooth initialized and enabled - enumerator ESP_BLUEDROID_STATUS_UNINITIALIZED
Bluetooth® Device APIs Overview Bluetooth device reference APIs. API Reference Header File components/bt/host/bluedroid/api/include/api/esp_bt_device.h This header file can be included with: #include "esp_bt_device.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - const uint8_t *esp_bt_dev_get_address(void) Get bluetooth device address. Must use after "esp_bluedroid_enable". - Returns bluetooth device address (six bytes), or NULL if bluetooth stack is not enabled - esp_err_t esp_bt_dev_set_device_name(const char *name) Set bluetooth device name. This function should be called after esp_bluedroid_enable() completes successfully. A BR/EDR/LE device type shall have a single Bluetooth device name which shall be identical irrespective of the physical channel used to perform the name discovery procedure. - Parameters name -- [in] : device name to be set - Returns ESP_OK : Succeed ESP_ERR_INVALID_ARG : if name is NULL pointer or empty, or string length out of limit ESP_ERR_INVALID_STATE : if bluetooth stack is not yet enabled ESP_FAIL : others - - esp_err_t esp_bt_dev_coex_status_config(esp_bt_dev_coex_type_t type, esp_bt_dev_coex_op_t op, uint8_t status) Config bluetooth device coexis status. This function should be called after esp_bluedroid_enable() completes successfully. - Parameters type -- [in] : coexist type to operate on op -- [in] : clear or set coexist status status -- [in] : coexist status to be configured - - Returns ESP_OK : Succeed ESP_ERR_INVALID_ARG : if name is NULL pointer or empty, or string length out of limit ESP_ERR_INVALID_STATE : if bluetooth stack is not yet enabled ESP_FAIL : others - - esp_err_t esp_bt_config_file_path_update(const char *file_path) This function is used to update the path name of bluetooth bond keys saved in the NVS module and need to be called before esp_bluedroid_init(). - Parameters file_path -- [in] the name of config file path, the length of file_path should be less than NVS_NS_NAME_MAX_SIZE - Returns ESP_OK: success other: failed - Macros - ESP_BT_DEV_COEX_BLE_ST_MESH_CONFIG - ESP_BT_DEV_COEX_BLE_ST_MESH_TRAFFIC - ESP_BT_DEV_COEX_BLE_ST_MESH_STANDBY - ESP_BT_DEV_COEX_BT_ST_A2DP_STREAMING - ESP_BT_DEV_COEX_BT_ST_A2DP_PAUSED - ESP_BT_DEV_COEX_OP_CLEAR - ESP_BT_DEV_COEX_OP_SET Type Definitions - typedef uint8_t esp_bt_dev_coex_op_t
GAP API Application Example Check the bluetooth/bluedroid/ble folder in ESP-IDF examples, which contains the following demos and their tutorials: The following shows an SMP security client demo with its tutorial. This demo initiates its security parameters and acts as a GATT client, which can send a security request to the peer device and then complete the encryption procedure. The following shows an SMP security server demo with its tutorial. This demo initiates its security parameters and acts as a GATT server, which can send a pair request to the peer device and then complete the encryption procedure.
API Reference Header File components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h This header file can be included with: #include "esp_gap_ble_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback) This function is called to occur gap event, such as scan result. - Parameters callback --
[in] callback function - Returns ESP_OK : success other : failed - - esp_gap_ble_cb_t esp_ble_gap_get_callback(void) This function is called to get the current gap callback. - Returns esp_gap_ble_cb_t : callback function - - esp_err_t esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data) This function is called to override the BTA default ADV parameters. - Parameters adv_data -- [in] Pointer to User defined ADV data structure. This memory space can not be freed until callback of config_adv_data is received. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params) This function is called to set scan parameters. - Parameters scan_params -- [in] Pointer to User defined scan_params data structure. This memory space can not be freed until callback of set_scan_params - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_start_scanning(uint32_t duration) This procedure keep the device scanning the peer device which advertising on the air. - Parameters duration -- [in] Keeping the scanning time, the unit is second. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_stop_scanning(void) This function call to stop the device scanning the peer device which advertising on the air. - Returns ESP_OK : success other : failed - - - esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params) This function is called to start advertising. -
[in] pointer to User defined adv_params data structure. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_stop_advertising(void) This function is called to stop advertising. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params) Update connection parameters, can only be used when connection is up. - Parameters params -- [in] - connection update parameters - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length) This function is to set maximum LE data packet size. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr) This function allows configuring either a Non-Resolvable Private Address or a Static Random Address. - Parameters rand_addr --
Refer to the table below for possible address subtypes: | address [47:46] | Address Type | |-----------------|--------------------------| | 0b00 | Non-Resolvable Private | | | Address | |-----------------|--------------------------| | 0b11 | Static Random Address | |-----------------|--------------------------| - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_clear_rand_addr(void) This function clears the random address for the application. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_config_local_privacy(bool privacy_enable) Enable/disable privacy (including address resolution) on the local device. - Parameters privacy_enable -- [in] - enable/disable privacy on remote device. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_config_local_icon(uint16_t icon) set local gap appearance icon - Parameters icon -- [in] - External appearance value, these values are defined by the Bluetooth SIG, please refer to https://www.bluetooth.com/specifications/assigned-numbers/ - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda, esp_ble_wl_addr_type_t wl_addr_type) Add or remove device from white list. - Parameters add_remove -- [in] the value is true if added the ble device to the white list, and false remove to the white list.
[in] whitelist address type - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_clear_whitelist(void) Clear all white list. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_get_whitelist_size(uint16_t *length) Get the whitelist size in the controller. - Parameters length -- [out] the white list length. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr, uint16_t min_conn_int, uint16_t max_conn_int, uint16_t slave_latency, uint16_t supervision_tout) This function is called to set the preferred connection parameters when default connection parameter is not desired before connecting. This API can only be used in the master role. - Parameters bd_addr -- [in] BD address of the peripheral min_conn_int -- [in] minimum preferred connection interval max_conn_int -- [in] maximum preferred connection interval slave_latency -- [in] preferred slave latency supervision_tout -- [in] preferred supervision timeout - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_set_device_name(const char *name) Set device name to the local device Note: This API don't affect the advertising data. - Parameters name -- [in] - device name. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_get_device_name(void) Get device name of the local device. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_get_local_used_addr(esp_bd_addr_t local_used_addr, uint8_t *addr_type) This function is called to get local used address and address type. uint8_t *esp_bt_dev_get_address(void) get the public address.
- Parameters local_used_addr -- [in] - current local used ble address (six bytes) addr_type -- [in] - ble address type - - Returns - ESP_OK : success other : failed - - uint8_t *esp_ble_resolve_adv_data(uint8_t *adv_data, uint8_t type, uint8_t *length) This function is called to get ADV data for a specific type. - Parameters adv_data -- [in] - pointer of ADV data which to be resolved type -- [in] - finding ADV data type length -- [out] - return the length of ADV data not including type - - Returns pointer of ADV data - esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len) This function is called to set raw advertising data. User need to fill ADV data by self. - Parameters raw_data -- [in] : raw advertising data with the format: [Length 1][Data Type 1][Data 1][Length 2][Data Type 2][Data 2] ... raw_data_len -- [in] : raw advertising data length , less than 31 bytes - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len) This function is called to set raw scan response data. User need to fill scan response data by self. - Parameters raw_data -- [in] : raw scan response data raw_data_len -- [in] : raw scan response data length , less than 31 bytes - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr) This function is called to read the RSSI of remote device. The address of link policy results are returned in the gap callback function with ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT event.
- Parameters remote_addr -- [in] : The remote connection device address. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_add_duplicate_scan_exceptional_device(esp_ble_duplicate_exceptional_info_type_t type, esp_duplicate_info_t device_info) This function is called to add a device info into the duplicate scan exceptional list. - Parameters type -- [in] device info type, it is defined in esp_ble_duplicate_exceptional_info_type_t when type is MESH_BEACON_TYPE, MESH_PROV_SRV_ADV or MESH_PROXY_SRV_ADV , device_info is invalid.
[in] the device information. - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_remove_duplicate_scan_exceptional_device(esp_ble_duplicate_exceptional_info_type_t type, esp_duplicate_info_t device_info) This function is called to remove a device info from the duplicate scan exceptional list. - Parameters type -- [in] device info type, it is defined in esp_ble_duplicate_exceptional_info_type_t when type is MESH_BEACON_TYPE, MESH_PROV_SRV_ADV or MESH_PROXY_SRV_ADV , device_info is invalid.
[in] the device information. - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_clean_duplicate_scan_exceptional_list(esp_duplicate_scan_exceptional_list_type_t list_type) This function is called to clean the duplicate scan exceptional list. This API will delete all device information in the duplicate scan exceptional list. - Parameters list_type -- [in] duplicate scan exceptional list type, the value can be one or more of esp_duplicate_scan_exceptional_list_type_t. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gap_set_security_param(esp_ble_sm_param_t param_type, void *value, uint8_t len) Set a GAP security parameter value. Overrides the default value. Secure connection is highly recommended to avoid some major vulnerabilities like 'Impersonation in the Pin Pairing Protocol' (CVE-2020-26555) and 'Authentication of the LE Legacy Pairing Protocol'. To accept only `secure connection mode`, it is necessary do as following: 1. Set bit `ESP_LE_AUTH_REQ_SC_ONLY` (`param_type` is `ESP_BLE_SM_AUTHEN_REQ_MODE`), bit `ESP_LE_AUTH_BOND` and bit `ESP_LE_AUTH_REQ_MITM` is optional as required. 2. Set to `ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_ENABLE` (`param_type` is `ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH`). - Parameters param_type -- [in] : the type of the param which to be set value -- [in] : the param value len -- [in] : the length of the param value - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_security_rsp(esp_bd_addr_t bd_addr, bool accept) Grant security request access. - Parameters bd_addr -- [in] : BD address of the peer accept -- [in] : accept the security request or not - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_set_encryption(esp_bd_addr_t bd_addr, esp_ble_sec_act_t sec_act) Set a gap parameter value. Use this function to change the default GAP parameter values. - Parameters bd_addr -- [in] : the address of the peer device need to encryption sec_act -- [in] : This is the security action to indicate what kind of BLE security level is required for the BLE link if the BLE is supported - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint32_t passkey) Reply the key value to the peer device in the legacy connection stage. - Parameters bd_addr -- [in] : BD address of the peer accept -- [in] : passkey entry successful or declined.
[in] : passkey value, must be a 6 digit number, can be lead by 0. - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept) Reply the confirm value to the peer device in the secure connection stage. - Parameters bd_addr -- [in] : BD address of the peer device accept -- [in] : numbers to compare are the same or different. - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr) Removes a device from the security database list of peer device. It manages unpairing event while connected. - Parameters bd_addr -- [in] : BD address of the peer device - Returns - ESP_OK : success other : failed - - int esp_ble_get_bond_device_num(void) Get the device number from the security database list of peer device. It will return the device bonded number immediately. - Returns - >= 0 : bonded devices number. ESP_FAIL : failed - - esp_err_t esp_ble_get_bond_device_list(int * dev_num, esp_ble_bond_dev_t *dev_list) Get the device from the security database list of peer device. It will return the device bonded information immediately. - Parameters dev_num -- [inout] Indicate the dev_list array(buffer) size as input. If dev_num is large enough, it means the actual number as output. Suggest that dev_num value equal to esp_ble_get_bond_device_num().
[out] an array(buffer) of esp_ble_bond_dev_ttype. Use for storing the bonded devices address. The dev_list should be allocated by who call this API. - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_oob_req_reply(esp_bd_addr_t bd_addr, uint8_t *TK, uint8_t len) This function is called to provide the OOB data for SMP in response to ESP_GAP_BLE_OOB_REQ_EVT. - Parameters bd_addr -- [in] BD address of the peer device. TK -- [in] Temporary Key value, the TK value shall be a 128-bit random number len -- [in] length of temporary key, should always be 128-bit - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_sc_oob_req_reply(esp_bd_addr_t bd_addr, uint8_t p_c[16], uint8_t p_r[16]) This function is called to provide the OOB data for SMP in response to ESP_GAP_BLE_SC_OOB_REQ_EVT. - Parameters bd_addr -- [in] BD address of the peer device. p_c -- [in] Confirmation value, it shall be a 128-bit random number p_r -- [in] Randomizer value, it should be a 128-bit random number - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_create_sc_oob_data(void) This function is called to create the OOB data for SMP when secure connection. - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device) This function is to disconnect the physical connection of the peer device gattc may have multiple virtual GATT server connections when multiple app_id registered. esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id) only close one virtual GATT server connection. if there exist other virtual GATT server connections, it does not disconnect the physical connection. esp_ble_gap_disconnect(esp_bd_addr_t remote_device) disconnect the physical connection directly. - Parameters remote_device -- [in] : BD address of the peer device - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_get_current_conn_params(esp_bd_addr_t bd_addr, esp_gap_conn_params_t *conn_params) This function is called to read the connection parameters information of the device. - Parameters bd_addr -- [in] BD address of the peer device.
[out] the connection parameters information - - Returns - ESP_OK : success other : failed - - esp_err_t esp_gap_ble_set_channels(esp_gap_ble_channels channels) BLE set channels. - Parameters channels -- [in] : The n th such field (in the range 0 to 36) contains the value for the link layer channel index n. 0 means channel n is bad. 1 means channel n is unknown. The most significant bits are reserved and shall be set to 0. At least one channel shall be marked as unknown. - Returns - ESP_OK : success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled other : failed - This function is called to authorized a link after Authentication(MITM protection) - Parameters bd_addr -- [in] BD address of the peer device. authorize -- [out] Authorized the link or not. - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_read_phy(esp_bd_addr_t bd_addr) This function is used to read the current transmitter PHY and receiver PHY on the connection identified by remote address. - Parameters bd_addr -- [in] : BD address of the peer device - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_set_preferred_default_phy(esp_ble_gap_phy_mask_t tx_phy_mask, esp_ble_gap_phy_mask_t rx_phy_mask) This function is used to allows the Host to specify its preferred values for the transmitter PHY and receiver PHY to be used for all subsequent connections over the LE transport. - Parameters tx_phy_mask -- [in] : indicates the transmitter PHYs that the Host prefers the Controller to use rx_phy_mask -- [in] : indicates the receiver PHYs that the Host prefers the Controller to use - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_set_preferred_phy(esp_bd_addr_t bd_addr, esp_ble_gap_all_phys_t all_phys_mask, esp_ble_gap_phy_mask_t tx_phy_mask, esp_ble_gap_phy_mask_t rx_phy_mask, esp_ble_gap_prefer_phy_options_t phy_options) This function is used to set the PHY preferences for the connection identified by the remote address. The Controller might not be able to make the change (e.g. because the peer does not support the requested PHY) or may decide that the current PHY is preferable. - Parameters bd_addr --
[in] : remote address all_phys_mask -- [in] : a bit field that allows the Host to specify tx_phy_mask -- [in] : a bit field that indicates the transmitter PHYs that the Host prefers the Controller to use rx_phy_mask -- [in] : a bit field that indicates the receiver PHYs that the Host prefers the Controller to use phy_options -- [in] : a bit field that allows the Host to specify options for PHYs - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_ext_adv_set_rand_addr(uint8_t instance, esp_bd_addr_t rand_addr) This function is used by the Host to set the random device address specified by the Random_Address parameter. - Parameters instance -- [in] : Used to identify an advertising set rand_addr -- [in] : Random Device Address - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_ext_adv_set_params(uint8_t instance, const esp_ble_gap_ext_adv_params_t *params) This function is used by the Host to set the advertising parameters. - Parameters instance -- [in] : identifies the advertising set whose parameters are being configured.
[in] : advertising parameters - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_config_ext_adv_data_raw(uint8_t instance, uint16_t length, const uint8_t *data) This function is used to set the data used in advertising PDUs that have a data field. - Parameters instance -- [in] : identifies the advertising set whose data are being configured length -- [in] : data length data -- [in] : data information - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_config_ext_scan_rsp_data_raw(uint8_t instance, uint16_t length, const uint8_t *scan_rsp_data) This function is used to provide scan response data used in scanning response PDUs. - Parameters instance -- [in] : identifies the advertising set whose response data are being configured.
length -- [in] : responsedata length scan_rsp_data -- [in] : response data information - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_ext_adv_start(uint8_t num_adv, const esp_ble_gap_ext_adv_t *ext_adv) This function is used to request the Controller to enable one or more advertising sets using the advertising sets identified by the instance parameter. - Parameters num_adv -- [in] : Number of advertising sets to enable or disable ext_adv -- [in] : adv parameters - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_ext_adv_stop(uint8_t num_adv, const uint8_t *ext_adv_inst) This function is used to request the Controller to disable one or more advertising sets using the advertising sets identified by the instance parameter. - Parameters num_adv -- [in] : Number of advertising sets to enable or disable ext_adv_inst -- [in] : ext adv instance - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_ext_adv_set_remove(uint8_t instance) This function is used to remove an advertising set from the Controller. - Parameters instance -- [in] : Used to identify an advertising set - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_ext_adv_set_clear(void) This function is used to remove all existing advertising sets from the Controller . - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_periodic_adv_set_params(uint8_t instance, const esp_ble_gap_periodic_adv_params_t *params) This function is used by the Host to set the parameters for periodic advertising. - Parameters instance -- [in] : identifies the advertising set whose periodic advertising parameters are being configured.
[in] : the length of periodic data data -- [in] : periodic data information - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_periodic_adv_start(uint8_t instance) This function is used to request the Controller to enable the periodic advertising for the advertising set specified. - Parameters instance -- [in] : Used to identify an advertising set - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_periodic_adv_stop(uint8_t instance) This function is used to request the Controller to disable the periodic advertising for the advertising set specified. - Parameters instance -- [in] : Used to identify an advertising set - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_set_ext_scan_params(const esp_ble_ext_scan_params_t *params) This function is used to set the extended scan parameters to be used on the advertising channels. - Parameters params -- [in] : scan parameters - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_start_ext_scan(uint32_t duration, uint16_t period) This function is used to enable scanning. - Parameters duration -- [in] Scan duration time, where Time = N * 10 ms. Range: 0x0001 to 0xFFFF. period -- [in] Time interval from when the Controller started its last Scan Duration until it begins the subsequent Scan Duration. Time = N * 1.28 sec. Range: 0x0001 to 0xFFFF. - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_stop_ext_scan(void) This function is used to disable scanning. - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_periodic_adv_create_sync(const esp_ble_gap_periodic_adv_sync_params_t *params) This function is used to synchronize with periodic advertising from an advertiser and begin receiving periodic advertising packets. - Parameters params -- [in] : sync parameters - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_periodic_adv_sync_cancel(void) This function is used to cancel the LE_Periodic_Advertising_Create_Sync command while it is pending. - Returns - ESP_OK : success other : failed - - esp_err_t
This function is used to stop reception of the periodic advertising identified by the Sync Handle parameter. - Parameters sync_handle -- [in] : identify the periodic advertiser - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_periodic_adv_add_dev_to_list(esp_ble_addr_type_t addr_type, esp_bd_addr_t addr, uint8_t sid) This function is used to add a single device to the Periodic Advertiser list stored in the Controller. - Parameters addr_type -- [in] : address type addr -- [in] : Device Address sid -- [in] : Advertising SID subfield in the ADI field used to identify the Periodic Advertising - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_periodic_adv_remove_dev_from_list(esp_ble_addr_type_t addr_type, esp_bd_addr_t addr, uint8_t sid) This function is used to remove one device from the list of Periodic Advertisers stored in the Controller. Removals from the Periodic Advertisers List take effect immediately. - Parameters addr_type -- [in] : address type addr -- [in] : Device Address sid -- [in] : Advertising SID subfield in the ADI field used to identify the Periodic Advertising - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_periodic_adv_clear_dev(void) This function is used to remove all devices from the list of Periodic Advertisers in the Controller. - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_prefer_ext_connect_params_set(esp_bd_addr_t addr, esp_ble_gap_phy_mask_t phy_mask, const esp_ble_gap_conn_params_t *phy_1m_conn_params, const esp_ble_gap_conn_params_t *phy_2m_conn_params, const esp_ble_gap_conn_params_t *phy_coded_conn_params) This function is used to set aux connection parameters. - Parameters addr -- [in] : device address phy_mask -- [in] : indicates the PHY(s) on which the advertising packets should be received on the primary advertising channel and the PHYs for which connection parameters have been specified.
[in] : Peer device address service_data -- [in] : Service data used by Host sync_handle -- [in] : Handle of periodic advertising sync - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_periodic_adv_set_info_trans(esp_bd_addr_t addr, uint16_t service_data, uint8_t adv_handle) This function is used to transfer periodic advertising set info. - Parameters addr -- [in] : Peer device address service_data -- [in] : Service data used by Host adv_handle -- [in] : Handle of advertising set - - Returns - ESP_OK : success other : failed - - esp_err_t esp_ble_gap_set_periodic_adv_sync_trans_params(esp_bd_addr_t addr, const esp_ble_gap_past_params_t *params) This function is used to set periodic advertising sync transfer params. - Parameters addr -- [in] : Peer device address params -- [in] : Params of periodic advertising sync transfer - - Returns - ESP_OK : success other : failed - - esp_err_t
Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec - esp_bt_status_t status - struct ble_update_duplicate_exceptional_list_cmpl_evt_param - #include <esp_gap_ble_api.h> ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT. Public Members - esp_bt_status_t status Indicate update duplicate scan exceptional list operation success status - uint8_t subcode Define in esp_bt_duplicate_exceptional_subcode_type_t - uint16_t length The length of device_info - esp_duplicate_info_t device_info device information, when subcode is ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_CLEAN, the value is invalid - esp_bt_status_t status - struct ble_update_whitelist_cmpl_evt_param - #include <esp_gap_ble_api.h> ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT. Public Members - esp_bt_status_t status Indicate the add or remove whitelist operation success status - esp_ble_wl_operation_t wl_operation The value is ESP_BLE_WHITELIST_ADD if add address to whitelist operation success, ESP_BLE_WHITELIST_REMOVE if remove address from the whitelist operation success - esp_bt_status_t status - struct esp_ble_gap_cb_param_t::ble_get_dev_name_cmpl_evt_param get_dev_name_cmpl Structures - struct esp_ble_dtm_tx_t DTM TX parameters. Public Members - uint8_t tx_channel channel for sending test data, tx_channel = (Frequency -2402)/2, tx_channel range:0x00-0x27, Frequency range: 2402 MHz to 2480 MHz - uint8_t len_of_data length in bytes of payload data in each packet - esp_ble_dtm_pkt_payload_t pkt_payload packet payload type. value range: 0x00-0x07 - uint8_t tx_channel - struct esp_ble_dtm_rx_t DTM RX parameters. Public Members - uint8_t rx_channel channel for test data reception, rx_channel = (Frequency -2402)/2, tx_channel range:0x00-0x27, Frequency range: 2402 MHz to 2480 MHz - uint8_t rx_channel - struct esp_ble_adv_params_t Advertising parameters. Public Members - uint16_t adv_int_min Minimum advertising interval for undirected and low duty cycle directed advertising. Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second) Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec - uint16_t adv_int_max Maximum advertising interval for undirected and low duty cycle directed advertising. Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second) Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec
Advertising max interval - esp_ble_adv_type_t adv_type Advertising type - esp_ble_addr_type_t own_addr_type Owner bluetooth device address type - esp_bd_addr_t peer_addr Peer device bluetooth device address - esp_ble_addr_type_t peer_addr_type Peer device bluetooth device address type, only support public address type and random address type - esp_ble_adv_channel_t channel_map Advertising channel map - esp_ble_adv_filter_t adv_filter_policy Advertising filter policy - uint16_t adv_int_min - struct esp_ble_adv_data_t Advertising data content, according to "Supplement to the Bluetooth Core Specification". Public Members - bool set_scan_rsp Set this advertising data as scan response or not - bool include_name Advertising data include device name or not - bool include_txpower Advertising data include TX power - int min_interval Advertising data show slave preferred connection min interval. The connection interval in the following manner: connIntervalmin = Conn_Interval_Min * 1.25 ms Conn_Interval_Min range: 0x0006 to 0x0C80 Value of 0xFFFF indicates no specific minimum. Values not defined above are reserved for future use. - int max_interval Advertising data show slave preferred connection max interval. The connection interval in the following manner: connIntervalmax =
Conn_Interval_Max * 1.25 ms Conn_Interval_Max range: 0x0006 to 0x0C80 Conn_Interval_Max shall be equal to or greater than the Conn_Interval_Min. Value of 0xFFFF indicates no specific maximum. Values not defined above are reserved for future use. - int appearance External appearance of device - uint16_t manufacturer_len Manufacturer data length - uint8_t *p_manufacturer_data Manufacturer data point - uint16_t service_data_len Service data length - uint8_t *p_service_data Service data point - uint16_t service_uuid_len Service uuid length - uint8_t *p_service_uuid Service uuid array point - uint8_t flag Advertising flag of discovery mode, see BLE_ADV_DATA_FLAG detail - bool set_scan_rsp - struct esp_ble_scan_params_t Ble scan parameters. Public Members - esp_ble_scan_type_t scan_type Scan type - esp_ble_addr_type_t own_addr_type Owner address type - esp_ble_scan_filter_t scan_filter_policy Scan filter policy - uint16_t scan_interval Scan interval.
Values: - enumerator ESP_BLE_EVT_CONN_ADV Connectable undirected advertising (ADV_IND) - enumerator ESP_BLE_EVT_CONN_DIR_ADV Connectable directed advertising (ADV_DIRECT_IND) - enumerator ESP_BLE_EVT_DISC_ADV Scannable undirected advertising (ADV_SCAN_IND) - enumerator ESP_BLE_EVT_NON_CONN_ADV Non connectable undirected advertising (ADV_NONCONN_IND) - enumerator ESP_BLE_EVT_SCAN_RSP Scan Response (SCAN_RSP) - enumerator ESP_BLE_EVT_CONN_ADV - enum esp_ble_wl_operation_t Values: - enumerator ESP_BLE_WHITELIST_REMOVE remove mac from whitelist - enumerator ESP_BLE_WHITELIST_ADD add address to whitelist - enumerator ESP_BLE_WHITELIST_CLEAR clear all device in whitelist - enumerator ESP_BLE_WHITELIST_REMOVE - enum esp_bt_duplicate_exceptional_subcode_type_t Values: - enumerator ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_ADD Add device info into duplicate scan exceptional list - enumerator ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_REMOVE Remove device info from duplicate scan exceptional list - enumerator ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_CLEAN Clean duplicate scan exceptional list - enumerator ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_ADD - enum esp_ble_duplicate_exceptional_info_type_t Values: - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_ADV_ADDR BLE advertising address , device info will be added into ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_ADDR_LIST - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_LINK_ID BLE mesh link ID, it is for BLE mesh, device info will be added into ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_LINK_ID_LIST - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_BEACON_TYPE BLE mesh beacon AD type, the format is | Len | 0x2B
| Beacon Type | Beacon Data | - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROV_SRV_ADV BLE mesh provisioning service uuid, the format is | 0x02 | 0x01 | flags | 0x03 | 0x03 | 0x1827 | .... |` - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROXY_SRV_ADV BLE mesh adv with proxy service uuid, the format is | 0x02 | 0x01 | flags | 0x03 | 0x03 | 0x1828 | .... |` - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROXY_SOLIC_ADV BLE mesh adv with proxy service uuid, the format is | 0x02 | 0x01 | flags | 0x03 | 0x03 | 0x1859 |
.... |` - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_URI_ADV BLE mesh URI adv, the format is ...| Len | 0x24 | data |... - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_ADV_ADDR - enum esp_duplicate_scan_exceptional_list_type_t Values: - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_ADDR_LIST duplicate scan exceptional addr list - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_LINK_ID_LIST duplicate scan exceptional mesh link ID list - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_BEACON_TYPE_LIST duplicate scan exceptional mesh beacon type list - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_PROV_SRV_ADV_LIST duplicate scan exceptional mesh adv with provisioning service uuid - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_PROXY_SRV_ADV_LIST duplicate scan exceptional mesh adv with proxy service uuid - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_PROXY_SOLIC_ADV_LIST duplicate scan exceptional mesh adv with proxy solicitation PDU uuid - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_URI_ADV_LIST duplicate scan exceptional URI list - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_ALL_LIST duplicate scan exceptional all list - enumerator ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_ADDR_LIST
GATT Defines API Reference Header File components/bt/host/bluedroid/api/include/api/esp_gatt_defs.h This header file can be included with: #include "esp_gatt_defs.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Unions - union esp_gatt_rsp_t - #include <esp_gatt_defs.h> GATT remote read request response type. Public Members - esp_gatt_value_t attr_value Gatt attribute structure - uint16_t handle Gatt attribute handle - esp_gatt_value_t attr_value Structures - struct esp_gatt_id_t Gatt id, include uuid and instance id. Public Members - esp_bt_uuid_t uuid UUID - uint8_t inst_id Instance id - esp_bt_uuid_t uuid - struct esp_gatt_srvc_id_t Gatt service id, include id (uuid and instance id) and primary flag. Public Members - esp_gatt_id_t id Gatt id, include uuid and instance - bool is_primary This service is primary or not - esp_gatt_id_t id - struct esp_attr_desc_t Attribute description (used to create database) - struct esp_attr_control_t attribute auto response flag Public Members - uint8_t auto_rsp if auto_rsp set to ESP_GATT_RSP_BY_APP, means the response of Write/Read operation will by replied by application. if auto_rsp set to ESP_GATT_AUTO_RSP, means the response of Write/Read operation will be replied by GATT stack automatically. - uint8_t auto_rsp - struct esp_gatts_attr_db_t attribute type added to the gatt server database Public Members - esp_attr_control_t attr_control The attribute control type - esp_attr_desc_t att_desc The attribute type - esp_attr_control_t attr_control - struct esp_attr_value_t set the attribute value type - struct esp_gatts_incl_svc_desc_t Gatt include service entry element. - struct esp_gatts_incl128_svc_desc_t Gatt include 128 bit service entry element. - struct esp_gatt_value_t Gatt attribute value. - struct esp_gatt_conn_params_t Connection parameters information. Public Members - uint16_t interval connection interval - uint16_t latency Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 - uint16_t timeout Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
GATT Server API Application Examples Check bluetooth/bluedroid/ble folder in ESP-IDF examples, which contains the following demos and their tutorials: This is a GATT server demo and its tutorial. This demo creates a GATT service with an attribute table, which releases the user from the operation of adding attributes one by one. This is the recommended method of adding attributes (officially recommended). This is a GATT server demo and its tutorial. This demo creates a GATT service by adding attributes one by one as defined by Bluedroid. The recommended method of adding attributes is presented in the example below. This is a demo similar to Bluetooth® Low Energy (Bluetooth LE) SPP. In this demo, GATT server can receive data from UART and then send the data to the peer device automatically. API Reference Header File components/bt/host/bluedroid/api/include/api/esp_gatts_api.h This header file can be included with: #include "esp_gatts_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback) This function is called to register application callbacks with BTA GATTS module. - Returns ESP_OK : success other : failed - - esp_gatts_cb_t esp_ble_gatts_get_callback(void) This function is called to get the current application callbacks with BTA GATTS module. - Returns esp_gatts_cb_t : current callback - - esp_err_t esp_ble_gatts_app_register(uint16_t app_id) This function is called to register application identifier. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatts_if) unregister with GATT Server. - Parameters gatts_if -- [in] GATT server access interface - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if, esp_gatt_srvc_id_t *service_id, uint16_t num_handle) Create a service. When service creation is done, a callback event ESP_GATTS_CREATE_EVT is called to report status and service ID to the profile. The service ID obtained in the callback function needs to be used when adding included service and characteristics/descriptors into the service.
gatts_attr_db, esp_gatt_if_t gatts_if, uint16_t max_nb_attr, uint8_t srvc_inst_id) Create a service attribute tab. - Parameters gatts_attr_db -- [in] the pointer to the service attr tab gatts_if -- [in] GATT server access interface max_nb_attr -- [in] the number of attribute to be added to the service database. srvc_inst_id -- [in] the instance id of the service - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_add_included_service(uint16_t service_handle, uint16_t included_service_handle) This function is called to add an included service. This function have to be called between 'esp_ble_gatts_create_service' and 'esp_ble_gatts_add_char'. After included service is included, a callback event ESP_GATTS_ADD_INCL_SRVC_EVT is reported the included service ID. - Parameters service_handle -- [in] service handle to which this included service is to be added.
char_uuid -- [in] : Characteristic UUID. perm -- [in] : Characteristic value declaration attribute permission. property -- [in] : Characteristic Properties char_val -- [in] : Characteristic value control -- [in] : attribute response control byte - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_add_char_descr(uint16_t service_handle, esp_bt_uuid_t *descr_uuid, esp_gatt_perm_t perm, esp_attr_value_t *char_descr_val, esp_attr_control_t *control) This function is called to add characteristic descriptor. When it's done, a callback event ESP_GATTS_ADD_DESCR_EVT is called to report the status and an ID number for this descriptor. - Parameters service_handle -- [in] service handle to which this characteristic descriptor is to be added. perm -- [in] descriptor access permission.
descr_uuid -- [in] descriptor UUID. char_descr_val -- [in] : Characteristic descriptor value control -- [in] : attribute response control byte - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle) This function is called to delete a service. When this is done, a callback event ESP_GATTS_DELETE_EVT is report with the status. - Parameters service_handle -- [in] service_handle to be deleted. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_start_service(uint16_t service_handle) This function is called to start a service. - Parameters service_handle -- [in] the service handle to be started. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle) This function is called to stop a service. - Parameters service_handle -- [in] - service to be topped. - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_send_indicate(esp_gatt_if_t gatts_if, uint16_t conn_id, uint16_t attr_handle, uint16_t value_len, uint8_t *value, bool need_confirm) Send indicate or notify to GATT client. Set param need_confirm as false will send notification, otherwise indication. Note: the size of indicate or notify data need less than MTU size,see "esp_ble_gattc_send_mtu_req". - Parameters gatts_if -- [in] GATT server access interface conn_id -- [in] - connection id to indicate.
[in] - indicate value length. value -- [in] value to indicate. need_confirm -- [in] - Whether a confirmation is required. false sends a GATT notification, true sends a GATT indication. - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_send_response(esp_gatt_if_t gatts_if, uint16_t conn_id, uint32_t trans_id, esp_gatt_status_t status, esp_gatt_rsp_t *rsp) This function is called to send a response to a request. - Parameters gatts_if -- [in] GATT server access interface conn_id -- [in] - connection identifier. trans_id -- [in] - transfer id status -- [in] - response status rsp -- [in] - response data. - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_set_attr_value(uint16_t attr_handle, uint16_t length, const uint8_t *value) This function is called to set the attribute value by the application. - Parameters attr_handle -- [in] the attribute handle which to be set length -- [in] the value length value -- [in] the pointer to the attribute value - - Returns ESP_OK : success other : failed - - esp_gatt_status_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value) Retrieve attribute value. - Parameters attr_handle -- [in] Attribute handle.
length -- [out] pointer to the attribute value length value -- [out] Pointer to attribute value payload, the value cannot be modified by user - - Returns ESP_GATT_OK : success other : failed - - esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct) Open a direct open connection or add a background auto connection. - Parameters gatts_if -- [in] GATT server access interface remote_bda -- [in] remote device bluetooth device address. is_direct -- [in] direct connection or background auto connection - - Returns ESP_OK : success other : failed - - esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id) Close a connection a remote device.
Transfer id - esp_bd_addr_t bda The bluetooth device address which been read - uint16_t handle The attribute handle - uint16_t offset Offset of the value, if the value is too long - bool is_long The value is too long or not - bool need_rsp The read operation need to do response - uint16_t conn_id - struct gatts_reg_evt_param - #include <esp_gatts_api.h> ESP_GATTS_REG_EVT. Public Members - esp_gatt_status_t status Operation status - uint16_t app_id Application id which input in register API - esp_gatt_status_t status - struct gatts_rsp_evt_param - #include <esp_gatts_api.h> ESP_GATTS_RESPONSE_EVT. Public Members - esp_gatt_status_t status Operation status - uint16_t handle Attribute handle which send response - esp_gatt_status_t status - struct gatts_send_service_change_evt_param - #include <esp_gatts_api.h> ESP_GATTS_SEND_SERVICE_CHANGE_EVT. - struct gatts_set_attr_val_evt_param - #include <esp_gatts_api.h> ESP_GATTS_SET_ATTR_VAL_EVT. Public Members - uint16_t srvc_handle The service handle - uint16_t attr_handle The attribute handle - esp_gatt_status_t status Operation status - uint16_t srvc_handle - struct gatts_start_evt_param - #include <esp_gatts_api.h> ESP_GATTS_START_EVT. Public Members - esp_gatt_status_t status Operation status - uint16_t service_handle Service attribute handle - esp_gatt_status_t status - struct gatts_stop_evt_param - #include <esp_gatts_api.h> ESP_GATTS_STOP_EVT. Public Members - esp_gatt_status_t status Operation status - uint16_t service_handle Service attribute handle - esp_gatt_status_t status - struct gatts_write_evt_param - #include <esp_gatts_api.h> ESP_GATTS_WRITE_EVT. Public Members - uint16_t conn_id Connection id - uint32_t trans_id Transfer id - esp_bd_addr_t bda The bluetooth device address which been written - uint16_t handle The attribute handle - uint16_t offset Offset of the value, if the value is too long - bool need_rsp The write operation need to do response - bool is_prep This write operation is prepare write - uint16_t len The write attribute value length - uint8_t *value The write attribute value - uint16_t conn_id - struct esp_ble_gatts_cb_param_t::gatts_reg_evt_param reg Macros - ESP_GATT_PREP_WRITE_CANCEL Prepare write flag to indicate cancel prepare write - ESP_GATT_PREP_WRITE_EXEC Prepare write flag to indicate execute prepare write Type Definitions - typedef void
(*esp_gatts_cb_t)(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) GATT Server callback function type. - Param event : Event type - Param gatts_if : GATT server access interface, normally different gatts_if correspond to different profile - Param param : Point to callback parameter, currently is union type Enumerations - enum esp_gatts_cb_event_t GATT Server callback function events. Values: - enumerator ESP_GATTS_REG_EVT When register application id, the event comes - enumerator ESP_GATTS_READ_EVT When gatt client request read operation, the event comes - enumerator ESP_GATTS_WRITE_EVT When gatt client request write operation, the event comes - enumerator ESP_GATTS_EXEC_WRITE_EVT When gatt client request execute write, the event comes - enumerator ESP_GATTS_MTU_EVT When set mtu complete, the event comes - enumerator ESP_GATTS_CONF_EVT When receive confirm, the event comes - enumerator ESP_GATTS_UNREG_EVT When unregister application id, the event comes - enumerator ESP_GATTS_CREATE_EVT When create service complete, the event comes - enumerator ESP_GATTS_ADD_INCL_SRVC_EVT When add included service complete, the event comes - enumerator ESP_GATTS_ADD_CHAR_EVT When add characteristic complete, the event comes - enumerator ESP_GATTS_ADD_CHAR_DESCR_EVT When add descriptor complete, the event comes - enumerator ESP_GATTS_DELETE_EVT When delete service complete, the event comes - enumerator ESP_GATTS_START_EVT When start service complete, the event comes - enumerator ESP_GATTS_STOP_EVT When stop service complete, the event comes - enumerator ESP_GATTS_CONNECT_EVT When gatt client connect, the event comes - enumerator ESP_GATTS_DISCONNECT_EVT When gatt client disconnect, the event comes - enumerator ESP_GATTS_OPEN_EVT When connect to peer, the event comes - enumerator ESP_GATTS_CANCEL_OPEN_EVT When disconnect from peer, the event comes - enumerator ESP_GATTS_CLOSE_EVT When gatt server close, the event comes - enumerator ESP_GATTS_LISTEN_EVT When gatt listen to be connected the event comes - enumerator ESP_GATTS_CONGEST_EVT When congest happen, the event comes - enumerator ESP_GATTS_RESPONSE_EVT When gatt send response complete, the event comes - enumerator ESP_GATTS_CREAT_ATTR_TAB_EVT When gatt create table complete, the event comes - enumerator ESP_GATTS_SET_ATTR_VAL_EVT When gatt set attr value complete, the event comes - enumerator ESP_GATTS_SEND_SERVICE_CHANGE_EVT When gatt send service change indication complete, the event comes - enumerator ESP_GATTS_REG_EVT
GATT Client API Application Example Check bluetooth/bluedroid/ble folder in ESP-IDF examples, which contains the following demos and their tutorials: This is a GATT client demo and its tutorial. This demo can scan for devices, connect to the GATT server and discover its services. This is a multiple connection demo and its tutorial. This demo can connect to multiple GATT server devices and discover their services. This is a demo similar to Bluetooth® Low Energy (Bluetooth LE) SPP. This demo, which acts as a GATT client, can receive data from UART and then send the data to the peer device automatically. API Reference Header File components/bt/host/bluedroid/api/include/api/esp_gattc_api.h This header file can be included with: #include "esp_gattc_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback) This function is called to register application callbacks with GATTC module. - Parameters callback -- [in] : pointer to the application callback function. - Returns ESP_OK: success other: failed - - esp_gattc_cb_t
This function is called to get the current application callbacks with BTA GATTC module. - Returns esp_gattC_cb_t : current callback - - esp_err_t esp_ble_gattc_app_register(uint16_t app_id) This function is called to register application callbacks with GATTC module. - Parameters app_id -- [in] : Application Identify (UUID), for different application - Returns ESP_OK: success other: failed - - esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if) This function is called to unregister an application from GATTC module. - Parameters gattc_if -- [in] Gatt client access interface. - Returns ESP_OK: success other: failed - - esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct) Open a direct connection or add a background auto connection. - Parameters gattc_if -- [in] Gatt client access interface.
Close the virtual connection to the GATT server. gattc may have multiple virtual GATT server connections when multiple app_id registered, this API only close one virtual GATT server connection. if there exist other virtual GATT server connections, it does not disconnect the physical connection. if you want to disconnect the physical connection directly, you can use esp_ble_gap_disconnect(esp_bd_addr_t remote_device). - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID to be closed. - - Returns ESP_OK: success other: failed - - esp_err_t esp_ble_gattc_send_mtu_req(esp_gatt_if_t gattc_if, uint16_t conn_id) Configure the MTU size in the GATT channel. This can be done only once per connection. Before using, use esp_ble_gatt_set_local_mtu() to configure the local MTU size. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID. - - Returns ESP_OK: success other: failed - - esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *filter_uuid) This function is called to get service from local cache. This function report service search result by a callback event, and followed by a service search complete event. Note: 128-bit base UUID will automatically be converted to a 16-bit UUID in the search results. Other types of UUID remain unchanged. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID.
[in] a UUID of the service application is interested in. If Null, discover for all services. - - Returns ESP_OK: success other: failed - - esp_gatt_status_t esp_ble_gattc_get_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *svc_uuid, esp_gattc_service_elem_t *result, uint16_t *count, uint16_t offset) Find all the service with the given service uuid in the gattc cache, if the svc_uuid is NULL, find all the service. Note: It just get service from local cache, won't get from remote devices. If want to get it from remote device, need to used the esp_ble_gattc_cache_refresh, then call esp_ble_gattc_get_service again. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID which identify the server.
[in] the pointer to the service uuid. result -- [out] The pointer to the service which has been found in the gattc cache. count -- [inout] input the number of service want to find, it will output the number of service has been found in the gattc cache with the given service uuid. offset -- [in] Offset of the service position to get. - - Returns ESP_OK: success other: failed - - esp_gatt_status_t esp_ble_gattc_get_all_char(esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, esp_gattc_char_elem_t *result, uint16_t *count, uint16_t offset) Find all the characteristic with the given service in the gattc cache Note: It just get characteristic from local cache, won't get from remote devices. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID which identify the server.
[in] Offset of the characteristic position to get. - - Returns ESP_OK: success other: failed - - esp_gatt_status_t esp_ble_gattc_get_all_descr(esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t char_handle, esp_gattc_descr_elem_t *result, uint16_t *count, uint16_t offset) Find all the descriptor with the given characteristic in the gattc cache Note: It just get descriptor from local cache, won't get from remote devices. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID which identify the server. char_handle -- [in] the given characteristic handle result -- [out] The pointer to the descriptor in the characteristic. count -- [inout] input the number of descriptor want to find, it will output the number of descriptor has been found in the gattc cache with the given characteristic. offset -- [in] Offset of the descriptor position to get. - - Returns ESP_OK: success other: failed - - esp_gatt_status_t esp_ble_gattc_get_char_by_uuid(esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, esp_bt_uuid_t char_uuid, esp_gattc_char_elem_t *result, uint16_t *count) Find the characteristic with the given characteristic uuid in the gattc cache Note: It just get characteristic from local cache, won't get from remote devices. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID which identify the server.
start_handle -- [in] the attribute start handle end_handle -- [in] the attribute end handle char_uuid -- [in] the characteristic uuid result -- [out] The pointer to the characteristic in the service. count -- [inout] input the number of characteristic want to find, it will output the number of characteristic has been found in the gattc cache with the given service. - - Returns ESP_OK: success other: failed - - esp_gatt_status_t esp_ble_gattc_get_descr_by_uuid(esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, esp_bt_uuid_t char_uuid, esp_bt_uuid_t descr_uuid, esp_gattc_descr_elem_t *result, uint16_t *count) Find the descriptor with the given characteristic uuid in the gattc cache Note: It just get descriptor from local cache, won't get from remote devices. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID which identify the server.
start_handle -- [in] the attribute start handle end_handle -- [in] the attribute end handle char_uuid -- [in] the characteristic uuid. descr_uuid -- [in] the descriptor uuid. result -- [out] The pointer to the descriptor in the given characteristic. count -- [inout] input the number of descriptor want to find, it will output the number of descriptor has been found in the gattc cache with the given characteristic. - - Returns ESP_OK: success other: failed - - esp_gatt_status_t esp_ble_gattc_get_descr_by_char_handle(esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t char_handle, esp_bt_uuid_t descr_uuid, esp_gattc_descr_elem_t *result, uint16_t *count) Find the descriptor with the given characteristic handle in the gattc cache Note: It just get descriptor from local cache, won't get from remote devices. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID which identify the server. char_handle -- [in] the characteristic handle.
[in] the descriptor uuid. result -- [out] The pointer to the descriptor in the given characteristic. count -- [inout] input the number of descriptor want to find, it will output the number of descriptor has been found in the gattc cache with the given characteristic. - - Returns ESP_OK: success other: failed - - esp_gatt_status_t esp_ble_gattc_get_include_service(esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, esp_bt_uuid_t *incl_uuid, esp_gattc_incl_svc_elem_t *result, uint16_t *count) Find the include service with the given service handle in the gattc cache Note: It just get include service from local cache, won't get from remote devices. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID which identify the server.
start_handle -- [in] the attribute start handle end_handle -- [in] the attribute end handle incl_uuid -- [in] the include service uuid result -- [out] The pointer to the include service in the given service. count -- [inout] input the number of include service want to find, it will output the number of include service has been found in the gattc cache with the given service. - - Returns ESP_OK: success other: failed - - esp_gatt_status_t esp_ble_gattc_get_attr_count(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_gatt_db_attr_type_t type, uint16_t start_handle, uint16_t end_handle, uint16_t char_handle, uint16_t *count) Find the attribute count with the given service or characteristic in the gattc cache. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] connection ID which identify the server. type -- [in] the attribute type.
[in] the attribute start handle, if the type is ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore end_handle -- [in] the attribute end handle, if the type is ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore char_handle -- [in] the characteristic handle, this parameter valid when the type is ESP_GATT_DB_DESCRIPTOR. If the type isn't ESP_GATT_DB_DESCRIPTOR, this parameter should be ignore. count -- [out] output the number of attribute has been found in the gattc cache with the given attribute type. - - Returns ESP_OK: success other: failed - - esp_gatt_status_t esp_ble_gattc_get_db(esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t start_handle, uint16_t end_handle, esp_gattc_db_elem_t *db, uint16_t *count) This function is called to get the GATT database. Note: It just get attribute data base from local cache, won't get from remote devices. - Parameters gattc_if -- [in] Gatt client access interface.
start_handle -- [in] the attribute start handle end_handle -- [in] the attribute end handle conn_id -- [in] connection ID which identify the server. db -- [in] output parameter which will contain the GATT database copy. Caller is responsible for freeing it. count -- [in] number of elements in database. - - Returns ESP_OK: success other: failed - - esp_err_t esp_ble_gattc_read_char(esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t handle, esp_gatt_auth_req_t auth_req) This function is called to read a service's characteristics of the given characteristic handle. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] : connection ID. handle -- [in] : characteritic handle to read.
end_handle -- [in] : the attribute end handle uuid -- [in] : The UUID of attribute which will be read. auth_req -- [in] : authenticate request type - - Returns ESP_OK: success other: failed - - esp_err_t esp_ble_gattc_read_multiple(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_gattc_multi_t *read_multi, esp_gatt_auth_req_t auth_req) This function is called to read multiple characteristic or characteristic descriptors. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] : connection ID. read_multi -- [in] : pointer to the read multiple parameter.
[in] : authentication request. - - Returns ESP_OK: success other: failed - - esp_err_t esp_ble_gattc_execute_write(esp_gatt_if_t gattc_if, uint16_t conn_id, bool is_execute) This function is called to execute write a prepare write sequence. - Parameters gattc_if -- [in] Gatt client access interface. conn_id -- [in] : connection ID. is_execute -- [in] : execute or cancel. - - Returns ESP_OK: success other: failed - - esp_err_t esp_ble_gattc_register_for_notify(esp_gatt_if_t gattc_if, esp_bd_addr_t server_bda, uint16_t handle) This function is called to register for notification of a service. - Parameters gattc_if -- [in] Gatt client access interface.
- Parameters remote_bda -- [in] remote device BD address. - Returns ESP_OK: success other: failed - - esp_err_t esp_ble_gattc_cache_assoc(esp_gatt_if_t gattc_if, esp_bd_addr_t src_addr, esp_bd_addr_t assoc_addr, bool is_assoc) Add or delete the associated address with the source address. Note: The role of this API is mainly when the client side has stored a server-side database, when it needs to connect another device, but the device's attribute database is the same as the server database stored on the client-side, calling this API can use the database that the device has stored used as the peer server database to reduce the attribute database search and discovery process and speed up the connection time. The associated address mains that device want to used the database has stored in the local cache. The source address mains that device want to share the database to the associated address device. - Parameters gattc_if -- [in] Gatt client access interface.
Security reference. You can write your own Security functions such as symmetrical encryption/decryption and checksum functions. Even you can define the "Key Exchange/Negotiation" procedure. Application Example Check bluetooth folder in ESP-IDF examples, which contains the following application: This is the BluFi demo. This demo can set ESP32's Wi-Fi to softap/station/softap&station mode and config Wi-Fi connections - bluetooth/blufi API Reference Header File This header file can be included with: #include "esp_blufi_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_err_t esp_blufi_register_callbacks(esp_blufi_callbacks_t *callbacks) This function is called to receive blufi callback event. - Parameters callbacks -- [in] callback functions - Returns ESP_OK - success, other - failed - esp_err_t esp_blufi_profile_init(void) This function is called to initialize blufi_profile. - Returns ESP_OK - success, other - failed - esp_err_t esp_blufi_profile_deinit(void) This function is called to de-initialize blufi_profile. - Returns ESP_OK - success, other - failed - esp_err_t esp_blufi_send_wifi_conn_report(wifi_mode_t opmode, esp_blufi_sta_conn_state_t sta_conn_state, uint8_t softap_conn_num, esp_blufi_extra_info_t *extra_info) This function is called to send wifi connection report. - Parameters opmode -- : wifi opmode sta_conn_state -- : station is already in connection or not softap_conn_num -- : softap connection number extra_info -- : extra information, such as sta_ssid, softap_ssid and etc. - - Returns ESP_OK - success, other - failed - esp_err_t esp_blufi_send_wifi_list(uint16_t apCount, esp_blufi_ap_record_t *list) This function is called to send wifi list. - Parameters apCount -- : wifi list count list -- : wifi list - - Returns ESP_OK - success, other - failed - uint16_t esp_blufi_get_version(void) Get BLUFI profile version. - Returns Most 8bit significant is Great version, Least 8bit is Sub version - esp_err_t esp_blufi_send_error_info(esp_blufi_error_state_t state) This function is called to send blufi error information. - Parameters state -- : error state - Returns ESP_OK - success, other - failed Unions - union esp_blufi_cb_param_t -
Classic Bluetooth® GAP API API Reference Header File components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h This header file can be included with: #include "esp_gap_bt_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - static inline uint32_t esp_bt_gap_get_cod_srvc(uint32_t cod) get major service field of COD - Parameters cod -- [in] Class of Device - Returns major service bits - static inline uint32_t esp_bt_gap_get_cod_major_dev(uint32_t cod) get major device field of COD - Parameters cod -- [in] Class of Device - Returns major device bits - static inline uint32_t esp_bt_gap_get_cod_minor_dev(uint32_t cod) get minor service field of COD - Parameters cod -- [in] Class of Device - Returns minor service bits - static inline uint32_t esp_bt_gap_get_cod_format_type(uint32_t cod) get format type of COD - Parameters cod -- [in] Class of Device - Returns format type - static inline bool esp_bt_gap_is_valid_cod(uint32_t cod) decide the integrity of COD - Parameters cod -- [in] Class of Device - Returns true if cod is valid false otherise - - esp_err_t esp_bt_gap_register_callback(esp_bt_gap_cb_t callback) register callback function. This function should be called after esp_bluedroid_enable() completes successfully - Returns ESP_OK : Succeed ESP_FAIL: others - - esp_err_t esp_bt_gap_set_scan_mode(esp_bt_connection_mode_t c_mode, esp_bt_discovery_mode_t d_mode) Set discoverability and connectability mode for legacy bluetooth. This function should be called after esp_bluedroid_enable() completes successfully. - Parameters c_mode --
[in] : one of the enums of esp_bt_connection_mode_t d_mode -- [in] : one of the enums of esp_bt_discovery_mode_t - - Returns ESP_OK : Succeed ESP_ERR_INVALID_ARG: if argument invalid ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_bt_gap_start_discovery(esp_bt_inq_mode_t mode, uint8_t inq_len, uint8_t num_rsps) This function starts Inquiry and Name Discovery. This function should be called after esp_bluedroid_enable() completes successfully. When Inquiry is halted and cached results do not contain device name, then Name Discovery will connect to the peer target to get the device name. esp_bt_gap_cb_t will be called with ESP_BT_GAP_DISC_STATE_CHANGED_EVT when Inquiry is started or Name Discovery is completed. esp_bt_gap_cb_t will be called with ESP_BT_GAP_DISC_RES_EVT each time the two types of discovery results are got. - Parameters mode --
[in] - Inquiry mode inq_len -- [in] - Inquiry duration in 1.28 sec units, ranging from 0x01 to 0x30. This parameter only specifies the total duration of the Inquiry process, when this time expires, Inquiry will be halted. - num_rsps -- [in] - Number of responses that can be received before the Inquiry is halted, value 0 indicates an unlimited number of responses. - - Returns ESP_OK : Succeed ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_ERR_INVALID_ARG: if invalid parameters are provided ESP_FAIL: others - - esp_err_t esp_bt_gap_cancel_discovery(void) Cancel Inquiry and Name Discovery. This function should be called after esp_bluedroid_enable() completes successfully. esp_bt_gap_cb_t will be called with ESP_BT_GAP_DISC_STATE_CHANGED_EVT if Inquiry or Name Discovery is cancelled by calling this function. - Returns ESP_OK : Succeed ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_bt_gap_get_remote_services(esp_bd_addr_t remote_bda) Start SDP to get remote services. This function should be called after esp_bluedroid_enable() completes successfully. esp_bt_gap_cb_t will be called with ESP_BT_GAP_RMT_SRVCS_EVT after service discovery ends. - Returns ESP_OK : Succeed ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_bt_gap_get_remote_service_record(esp_bd_addr_t remote_bda, esp_bt_uuid_t *uuid) Start SDP to look up the service matching uuid on the remote device. This function should be called after esp_bluedroid_enable() completes successfully. esp_bt_gap_cb_t will be called with ESP_BT_GAP_RMT_SRVC_REC_EVT after service discovery ends - Returns ESP_OK : Succeed ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - uint8_t *esp_bt_gap_resolve_eir_data(uint8_t *eir, esp_bt_eir_type_t type, uint8_t *length) This function is called to get EIR data for a specific type. - Parameters eir -- [in] - pointer of raw eir data to be resolved type -- [in] - specific EIR data type length -- [out] - return the length of EIR data excluding fields of length and data type - - Returns pointer of starting position of eir data excluding eir data type, NULL if not found - esp_err_t
This function is called to config EIR data. esp_bt_gap_cb_t will be called with ESP_BT_GAP_CONFIG_EIR_DATA_EVT after config EIR ends. - Parameters eir_data -- [in] - pointer of EIR data content - Returns ESP_OK : Succeed ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_ERR_INVALID_ARG: if param is invalid ESP_FAIL: others - - esp_err_t esp_bt_gap_set_cod(esp_bt_cod_t cod, esp_bt_cod_mode_t mode) This function is called to set class of device. The structure esp_bt_gap_cb_t will be called with ESP_BT_GAP_SET_COD_EVT after set COD ends. This function should be called after Bluetooth profiles are initialized, otherwise the user configured class of device can be overwritten. Some profiles have special restrictions on class of device, and changes may make these profiles unable to work.
- Parameters cod -- [in] - class of device mode -- [in] - setting mode - - Returns ESP_OK : Succeed ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_ERR_INVALID_ARG: if param is invalid ESP_FAIL: others - - esp_err_t esp_bt_gap_get_cod(esp_bt_cod_t *cod) This function is called to get class of device. - Parameters cod -- [out] - class of device - Returns ESP_OK : Succeed ESP_FAIL: others - - esp_err_t esp_bt_gap_read_rssi_delta(esp_bd_addr_t remote_addr) This function is called to read RSSI delta by address after connected. The RSSI value returned by ESP_BT_GAP_READ_RSSI_DELTA_EVT. - Parameters remote_addr -- [in] - remote device address, corresponding to a certain connection handle - Returns ESP_OK : Succeed ESP_FAIL: others - - esp_err_t esp_bt_gap_remove_bond_device(esp_bd_addr_t bd_addr) Removes a device from the security database list of peer device. - Parameters bd_addr -- [in] : BD address of the peer device - Returns - ESP_OK : success ESP_FAIL : failed - - int esp_bt_gap_get_bond_device_num(void) Get the device number from the security database list of peer device. It will return the device bonded number immediately. - Returns - >= 0 : bonded devices number ESP_FAIL : failed - - esp_err_t esp_bt_gap_get_bond_device_list(int * dev_num, esp_bd_addr_t *dev_list)
[out] an array(buffer) of esp_bd_addr_ttype. Use for storing the bonded devices address. The dev_list should be allocated by who call this API. - - Returns ESP_OK : Succeed ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_bt_gap_set_pin(esp_bt_pin_type_t pin_type, uint8_t pin_code_len, esp_bt_pin_code_t pin_code) Set pin type and default pin code for legacy pairing. - Parameters pin_type -- [in] Use variable or fixed pin. If pin_type is ESP_BT_PIN_TYPE_VARIABLE, pin_code and pin_code_len will be ignored, and ESP_BT_GAP_PIN_REQ_EVT will come when control requests for pin code. Else, will use fixed pin code and not callback to users.
[in] Length of pin_code pin_code -- [in] Pin_code - - Returns - ESP_OK : success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled other : failed - - esp_err_t esp_bt_gap_set_security_param(esp_bt_sp_param_t param_type, void *value, uint8_t len) Set a GAP security parameter value. Overrides the default value. - Parameters param_type -- [in] : the type of the param which is to be set value -- [in] : the param value len -- [in] : the length of the param value - - Returns - ESP_OK : success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled other : failed - - esp_err_t esp_bt_gap_ssp_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint32_t passkey) Reply the key value to the peer device in the legacy connection stage. - Parameters bd_addr -- [in] : BD address of the peer accept -- [in] : passkey entry successful or declined.
[in] : passkey value, must be a 6 digit number, can be lead by 0. - - Returns - ESP_OK : success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled other : failed - - esp_err_t esp_bt_gap_ssp_confirm_reply(esp_bd_addr_t bd_addr, bool accept) Reply the confirm value to the peer device in the legacy connection stage. - Parameters bd_addr -- [in] : BD address of the peer device accept -- [in] : numbers to compare are the same or different - - Returns - ESP_OK : success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled other : failed - - esp_err_t esp_bt_gap_set_afh_channels(esp_bt_gap_afh_channels channels) Set the AFH channels. - Parameters channels -- [in] : The n th such field (in the range 0 to 78) contains the value for channel n : 0 means channel n is bad. 1 means channel n is unknown. The most significant bit is reserved and shall be set to 0. At least 20 channels shall be marked as unknown. - Returns - ESP_OK : success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled other : failed - - esp_err_t esp_bt_gap_read_remote_name(esp_bd_addr_t remote_bda) Read the remote device name.
- Parameters remote_bda -- [in] The remote device's address - Returns - ESP_OK : success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled other : failed - - esp_err_t esp_bt_gap_set_qos(esp_bd_addr_t remote_bda, uint32_t t_poll) Config Quality of service. - Parameters remote_bda -- [in] The remote device's address t_poll -- [in] Poll interval, the maximum time between transmissions which from the master to a particular slave on the ACL logical transport. unit is 0.625ms - - Returns - ESP_OK : success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled other : failed - - esp_err_t esp_bt_gap_set_page_timeout(uint16_t page_to) Set the page timeout esp_bt_gap_cb_t will be called with ESP_BT_GAP_SET_PAGE_TO_EVT after set page timeout ends. The value to be set will not be effective util the next page procedure, it's suggested to set the page timeout before initiating a connection.
Bluetooth® A2DP API Application Example Check bluetooth/bluedroid/classic_bt folder in ESP-IDF examples, which contains the following application: This is a A2DP sink client demo. This demo can be discovered and connected by A2DP source device and receive the audio stream from remote device - bluetooth/bluedroid/classic_bt/a2dp_sink API Reference Header File This header file can be included with: #include "esp_a2dp_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_err_t esp_a2d_register_callback(esp_a2d_cb_t callback) Register application callback function to A2DP module. This function should be called only after esp_bluedroid_enable() completes successfully, used by both A2DP source and sink. - Parameters callback -- [in] A2DP event callback function - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: if callback is a NULL function pointer - - esp_err_t esp_a2d_sink_register_data_callback(esp_a2d_sink_data_cb_t callback) Register A2DP sink data output function; For now the output is PCM data stream decoded from SBC format. This function should be called only after esp_bluedroid_enable() completes successfully, used only by A2DP sink. The callback is invoked in the context of A2DP sink task whose stack size is configurable through menuconfig. - Parameters callback -- [in] A2DP sink data callback function - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: if callback is a NULL function pointer - - esp_err_t esp_a2d_sink_init(void) Initialize the bluetooth A2DP sink module. This function should be called after esp_bluedroid_enable() completes successfully, and ESP_A2D_PROF_STATE_EVT with ESP_A2D_INIT_SUCCESS will reported to the APP layer. Note: A2DP can work independently.
This function should be called after esp_bluedroid_enable() completes successfully. - Returns ESP_OK: if the initialization request is sent successfully ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_a2d_sink_deinit(void) De-initialize for A2DP sink module. This function should be called only after esp_bluedroid_enable() completes successfully, and ESP_A2D_PROF_STATE_EVT with ESP_A2D_DEINIT_SUCCESS will reported to APP layer. - Returns ESP_OK: if the deinitialization request is sent successfully ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_a2d_sink_connect(esp_bd_addr_t remote_bda) Connect to remote bluetooth A2DP source device. This API must be called after esp_a2d_sink_init() and before esp_a2d_sink_deinit(). - Parameters remote_bda -- [in] remote bluetooth device address - Returns ESP_OK: connect request is sent to lower layer successfully ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_a2d_sink_disconnect(esp_bd_addr_t remote_bda) Disconnect from the remote A2DP source device. This API must be called after esp_a2d_sink_init() and before esp_a2d_sink_deinit(). - Parameters remote_bda -- [in] remote bluetooth device address - Returns ESP_OK: disconnect request is sent to lower layer successfully ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_a2d_sink_set_delay_value(uint16_t delay_value) Set delay reporting value. The delay value of sink is caused by buffering (including protocol stack and application layer), decoding and rendering. The default delay value is 120ms, if the set value is less than 120ms, the setting will fail.
Delay Report - ESP_A2D_CIE_LEN_SBC - ESP_A2D_CIE_LEN_M12 - ESP_A2D_CIE_LEN_M24 - ESP_A2D_CIE_LEN_ATRAC Type Definitions - typedef uint8_t esp_a2d_mct_t - typedef uint16_t esp_a2d_psc_t - typedef void (*esp_a2d_cb_t)(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param) A2DP profile callback function type. - Param event : Event type - Param param : Pointer to callback parameter - typedef void (*esp_a2d_sink_data_cb_t)(const uint8_t *buf, uint32_t len) A2DP sink data callback function. - Param buf [in] : pointer to the data received from A2DP source device and is PCM format decoded from SBC decoder; buf references to a static memory block and can be overwritten by upcoming data - Param len
API Reference Header File This header file can be included with: #include "esp_avrc_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_err_t esp_avrc_ct_register_callback(esp_avrc_ct_cb_t callback) Register application callbacks to AVRCP module. This function should be called after esp_bluedroid_enable() completes successfully. - Parameters callback -- [in] AVRCP controller callback function - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_avrc_ct_init(void) Initialize the bluetooth AVRCP controller module, This function should be called after esp_bluedroid_enable() completes successfully. Note: AVRC cannot work independently, AVRC should be used along with A2DP and AVRC should be initialized before A2DP. - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_avrc_ct_deinit(void) De-initialize AVRCP controller module. This function should be called after after esp_bluedroid_enable() completes successfully. Note: AVRC cannot work independently, AVRC should be used along with A2DP and AVRC should be deinitialized before A2DP. - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_avrc_ct_send_set_player_value_cmd(uint8_t tl, uint8_t attr_id, uint8_t value_id) Send player application settings command to AVRCP target. This function should be called after ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established. - Parameters tl --
[in] : transaction label, 0 to 15, consecutive commands should use different values attr_id -- [in] : player application setting attribute IDs from one of esp_avrc_ps_attr_ids_t value_id -- [in] : attribute value defined for the specific player application setting attribute - - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_avrc_ct_send_get_rn_capabilities_cmd(uint8_t tl) Send GetCapabilities PDU to AVRCP target to retrieve remote device's supported notification event_ids. This function should be called after ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established. - Parameters tl -- [in] : transaction label, 0 to 15, consecutive commands should use different values - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_avrc_ct_send_register_notification_cmd(uint8_t tl, uint8_t event_id, uint32_t event_parameter) Send register notification command to AVRCP target. This function should be called after ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established. - Parameters tl --
[in] : playback interval for ESP_AVRC_RN_PLAY_POS_CHANGED; For other events , value of this parameter is ignored. - - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_ERR_NOT_SUPPORTED: if the event_id is not supported in current implementation ESP_FAIL: others - - esp_err_t esp_avrc_ct_send_set_absolute_volume_cmd(uint8_t tl, uint8_t volume) Send set absolute volume command to AVRCP target. This function should be called after ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established. - Parameters tl -- [in] : transaction label, 0 to 15, consecutive commands should use different values volume -- [in] : volume, 0 to 0x7f, means 0% to 100% - - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_ERR_NOT_SUPPORTED: if the event_id is not supported in current implementation ESP_FAIL: others - - esp_err_t esp_avrc_ct_send_metadata_cmd(uint8_t tl, uint8_t
[in] : mask of attributes, e.g. ESP_AVRC_MD_ATTR_ID_TITLE | ESP_AVRC_MD_ATTR_ID_ARTIST. - - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state) Send passthrough command to AVRCP target. This function should be called after ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established. - Parameters tl -- [in] : transaction label, 0 to 15, consecutive commands should use different values.
[in] operation requested on the bit mask field psth -- [in] pointer to passthrough command bit mask structure cmd -- [in] passthrough command code - - Returns For operation ESP_AVRC_BIT_MASK_OP_SET or ESP_AVRC_BIT_MASK_OP_CLEAR, return true for a successful operation, otherwise return false. For operation ESP_AVRC_BIT_MASK_OP_TEST, return true if the corresponding bit is set, otherwise false. - esp_err_t esp_avrc_tg_get_rn_evt_cap(esp_avrc_rn_evt_cap_t cap, esp_avrc_rn_evt_cap_mask_t *evt_set) Get the requested event notification capabilies on local AVRC target. The capability is returned in a bit mask representation in evt_set.
SPP API Application Example Check bluetooth/bluedroid/classic_bt folder in ESP-IDF examples, which contains the following application: This is a SPP demo. This demo can discover the service, connect, send and recive SPP data bluetooth/bluedroid/classic_bt/bt_spp_acceptor, bluetooth/bluedroid/classic_bt/bt_spp_initiator API Reference Header File This header file can be included with: #include "esp_spp_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_err_t esp_spp_register_callback(esp_spp_cb_t callback) This function is called to init callbacks with SPP module. - Parameters callback -- [in] pointer to the init callback function. - Returns ESP_OK: success other: failed - - esp_err_t esp_spp_init(esp_spp_mode_t mode) This function is called to init SPP module. When the operation is completed, the callback function will be called with ESP_SPP_INIT_EVT. This function should be called after esp_bluedroid_enable() completes successfully. - Parameters mode -- [in] Choose the mode of SPP, ESP_SPP_MODE_CB or ESP_SPP_MODE_VFS. - Returns ESP_OK: success other: failed - - esp_err_t esp_spp_enhanced_init(const esp_spp_cfg_t *cfg) This function is called to init SPP module. When the operation is completed, the callback function will be called with ESP_SPP_INIT_EVT. This function should be called after esp_bluedroid_enable() completes successfully. Note The member variable enable_l2cap_etrm in esp_spp_cfg_t can affect all L2CAP channel configurations of the upper layer RFCOMM protocol. - Parameters cfg -- [in] SPP configuration. - Returns ESP_OK: success other: failed - - esp_err_t esp_spp_deinit(void)
This function is called to uninit SPP module. The operation will close all active SPP connection first, then the callback function will be called with ESP_SPP_CLOSE_EVT, and the number of ESP_SPP_CLOSE_EVT is equal to the number of connection. When the operation is completed, the callback function will be called with ESP_SPP_UNINIT_EVT. This function should be called after esp_spp_init()/esp_spp_enhanced_init() completes successfully. - Returns ESP_OK: success other: failed - - esp_err_t esp_spp_start_discovery(esp_bd_addr_t bd_addr) This function is called to performs service discovery for the services provided by the given peer device. When the operation is completed, the callback function will be called with ESP_SPP_DISCOVERY_COMP_EVT. This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit(). - Parameters bd_addr -- [in] Remote device bluetooth device address. - Returns ESP_OK: success other: failed - - esp_err_t esp_spp_connect(esp_spp_sec_t sec_mask, esp_spp_role_t role, uint8_t remote_scn, esp_bd_addr_t peer_bd_addr) This function makes an SPP connection to a remote BD Address. When the connection is initiated or failed to initiate, the callback is called with ESP_SPP_CL_INIT_EVT. When the connection is established or failed, the callback is called with ESP_SPP_OPEN_EVT. This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit(). - Parameters sec_mask -- [in] Security Setting Mask.
[in] Remote device bluetooth device address. - - Returns ESP_OK: success other: failed - - esp_err_t esp_spp_disconnect(uint32_t handle) This function closes an SPP connection. When the operation is completed, the callback function will be called with ESP_SPP_CLOSE_EVT. This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit(). - Parameters handle -- [in] The connection handle. - Returns ESP_OK: success other: failed - - esp_err_t esp_spp_start_srv(esp_spp_sec_t sec_mask, esp_spp_role_t role, uint8_t local_scn, const char *name) This function create a SPP server and starts listening for an SPP connection request from a remote Bluetooth device. When the server is started successfully, the callback is called with ESP_SPP_START_EVT. When the connection is established, the callback is called with ESP_SPP_SRV_OPEN_EVT. This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit(). - Parameters sec_mask -- [in] Security Setting Mask.
[in] Server's name. - - Returns ESP_OK: success other: failed - - esp_err_t esp_spp_stop_srv(void) This function stops all SPP servers. The operation will close all active SPP connection first, then the callback function will be called with ESP_SPP_CLOSE_EVT, and the number of ESP_SPP_CLOSE_EVT is equal to the number of connection. When the operation is completed, the callback is called with ESP_SPP_SRV_STOP_EVT. This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit(). - Returns ESP_OK: success other: failed - - esp_err_t esp_spp_stop_srv_scn(uint8_t scn) This function stops a specific SPP server. The operation will close all active SPP connection first on the specific SPP server, then the callback function will be called with ESP_SPP_CLOSE_EVT, and the number of ESP_SPP_CLOSE_EVT is equal to the number of connection. When the operation is completed, the callback is called with ESP_SPP_SRV_STOP_EVT. This function must be called after esp_spp_init()/esp_spp_enhanced_init() successful and before esp_spp_deinit(). - Parameters scn -- [in] Server channel number. - Returns ESP_OK: success other: failed - - esp_err_t esp_spp_write(uint32_t handle, int len, uint8_t *p_data) This function is used to write data, only for ESP_SPP_MODE_CB. When this function need to be called repeatedly, it is strongly recommended to call this function again after the previous event ESP_SPP_WRITE_EVT is received and the parameter 'cong' is equal to false. If the previous event ESP_SPP_WRITE_EVT with parameter 'cong' is equal to true, the function can only be called again when the event ESP_SPP_CONG_EVT with parameter 'cong' equal to false is received. This function must be called after an connection between initiator and acceptor has been established. - Parameters handle -- [in] The connection handle.
relate to BTA_SEC_NONE in bta/bta_api.h - ESP_SPP_SEC_AUTHORIZE Authorization required (only needed for out going connection ) relate to BTA_SEC_AUTHORIZE in bta/bta_api.h - ESP_SPP_SEC_AUTHENTICATE Authentication required. relate to BTA_SEC_AUTHENTICATE in bta/bta_api.h - ESP_SPP_SEC_ENCRYPT Encryption required. relate to BTA_SEC_ENCRYPT in bta/bta_api.h - ESP_SPP_SEC_MODE4_LEVEL4 Mode 4 level 4 service, i.e. incoming/outgoing MITM and P-256 encryption relate to BTA_SEC_MODE4_LEVEL4 in bta/bta_api.h - ESP_SPP_SEC_MITM Man-In-The_Middle protection relate to BTA_SEC_MITM in bta/bta_api.h - ESP_SPP_SEC_IN_16_DIGITS Min 16 digit for pin code relate to BTA_SEC_IN_16_DIGITS in bta/bta_api.h Type Definitions - typedef uint16_t esp_spp_sec_t - typedef void
When handle ESP_SPP_DATA_IND_EVT, it is strongly recommended to cache incoming data, and process them in other lower priority application task rather than in this callback directly. - Param event Event type - Param param Point to callback parameter, currently is union type Enumerations - enum esp_spp_status_t Values: - enumerator ESP_SPP_SUCCESS Successful operation. - enumerator ESP_SPP_FAILURE Generic failure. - enumerator ESP_SPP_BUSY Temporarily can not handle this request. - enumerator ESP_SPP_NO_DATA No data - enumerator ESP_SPP_NO_RESOURCE No more resource - enumerator ESP_SPP_NEED_INIT SPP module shall init first - enumerator ESP_SPP_NEED_DEINIT SPP module shall deinit first - enumerator ESP_SPP_NO_CONNECTION Connection may have been closed - enumerator ESP_SPP_NO_SERVER No SPP server - enumerator ESP_SPP_SUCCESS - enum esp_spp_role_t Values: - enumerator ESP_SPP_ROLE_MASTER Role: master - enumerator ESP_SPP_ROLE_SLAVE Role: slave - enumerator ESP_SPP_ROLE_MASTER - enum esp_spp_mode_t Values: - enumerator ESP_SPP_MODE_CB When data is coming, a callback will come with data - enumerator ESP_SPP_MODE_VFS Use VFS to write/read data - enumerator ESP_SPP_MODE_CB - enum esp_spp_cb_event_t SPP callback function events. Values: - enumerator ESP_SPP_INIT_EVT When SPP is initialized, the event comes - enumerator ESP_SPP_UNINIT_EVT When SPP is deinitialized, the event comes - enumerator ESP_SPP_DISCOVERY_COMP_EVT When SDP discovery complete, the event comes - enumerator ESP_SPP_OPEN_EVT When SPP Client connection open, the event comes - enumerator ESP_SPP_CLOSE_EVT When SPP connection closed, the event comes - enumerator ESP_SPP_START_EVT When SPP server started, the event comes - enumerator ESP_SPP_CL_INIT_EVT When SPP client initiated a connection, the event comes - enumerator ESP_SPP_DATA_IND_EVT When SPP connection received data, the event comes, only for ESP_SPP_MODE_CB - enumerator ESP_SPP_CONG_EVT When SPP connection congestion status changed, the event comes, only for ESP_SPP_MODE_CB - enumerator ESP_SPP_WRITE_EVT When SPP write operation completes, the event comes, only for ESP_SPP_MODE_CB - enumerator ESP_SPP_SRV_OPEN_EVT When SPP Server connection open, the event comes - enumerator ESP_SPP_SRV_STOP_EVT When SPP server stopped, the event comes - enumerator ESP_SPP_VFS_REGISTER_EVT When SPP VFS register, the event comes - enumerator ESP_SPP_VFS_UNREGISTER_EVT When SPP VFS unregister, the event comes - enumerator ESP_SPP_INIT_EVT
HFP Client API API Reference Header File components/bt/host/bluedroid/api/include/api/esp_hf_client_api.h This header file can be included with: #include "esp_hf_client_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_err_t esp_hf_client_register_callback(esp_hf_client_cb_t callback) Register application callback function to HFP client module. This function should be called only after esp_bluedroid_enable() completes successfully. - Parameters callback -- [in] HFP client event callback function - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: if callback is a NULL function pointer - - esp_err_t esp_hf_client_init(void) Initialize the bluetooth HFP client module. This function should be called after esp_bluedroid_enable() completes successfully. - Returns ESP_OK: if the initialization request is sent successfully ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_deinit(void) De-initialize for HFP client module. This function should be called only after esp_bluedroid_enable() completes successfully. - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_connect(esp_bd_addr_t remote_bda) Establish a Service Level Connection to remote bluetooth HFP audio gateway(AG) device. This function must be called after esp_hf_client_init() and before esp_hf_client_deinit(). - Parameters remote_bda -- [in] remote bluetooth device address - Returns ESP_OK: connect request is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_disconnect(esp_bd_addr_t remote_bda) Disconnect from the remote HFP audio gateway. This function must be called after esp_hf_client_init() and before esp_hf_client_deinit(). - Parameters remote_bda --
remote_bda) Create audio connection with remote HFP AG. As a precondition to use this API, Service Level Connection shall exist with AG. - Parameters remote_bda -- [in] remote bluetooth device address - Returns ESP_OK: connect audio request is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_disconnect_audio(esp_bd_addr_t remote_bda) Release the established audio connection with remote HFP AG. As a precondition to use this API, Service Level Connection shall exist with AG. - Parameters remote_bda -- [in] remote bluetooth device address - Returns ESP_OK: disconnect audio request is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_start_voice_recognition(void) Enable voice recognition in the AG. As a precondition to use this API, Service Level Connection shall exist with AG. - Returns ESP_OK: starting voice recognition is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_stop_voice_recognition(void) Disable voice recognition in the AG. As a precondition to use this API, Service Level Connection shall exist with AG. - Returns ESP_OK: stoping voice recognition is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_volume_update(esp_hf_volume_control_target_t type, int volume) Volume synchronization with AG. As a precondition to use this API, Service Level Connection shall exist with AG. - Parameters type -- [in] volume control target, speaker or microphone volume -- [in] gain of the speaker of microphone, ranges 0 to 15 - - Returns ESP_OK: volume update is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_dial(const char *number) Place a call with a specified number, if number is NULL, last called number is called. As a precondition to use this API, Service Level Connection shall exist with AG. - Parameters number --
If NULL, the last number is called(aka re-dial) - Returns ESP_OK: a call placing is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_dial_memory(int location) Place a call with number specified by location(speed dial). As a precondition to use this API, Service Level Connection shall exist with AG. - Parameters location -- [in] location of the number in the memory - Returns ESP_OK: a memory call placing is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_send_chld_cmd(esp_hf_chld_type_t chld, int idx) Send call hold and multiparty commands, or enhanced call control commands(Use AT+CHLD). As a precondition to use this API, Service Level Connection shall exist with AG. - Parameters chld --
[in] Battery Level: value between 0 and 9 docked -- [in] Dock State: false = undocked, true = docked - - Returns ESP_OK: battery level is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_request_last_voice_tag_number(void) Request a phone number from AG corresponding to last voice tag recorded (send AT+BINP command). As a precondition to use this API, Service Level Connection shall exist with AG. - Returns ESP_OK: the phone number request corresponding to last voice tag recorded is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_send_nrec(void) Disable echo cancellation and noise reduction in the AG (use AT+NREC=0 command). As a precondition to use this API, Service Level Connection shall exist with AG. - Returns ESP_OK: NREC=0 request is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_client_register_data_callback(esp_hf_client_incoming_data_cb_t recv, esp_hf_client_outgoing_data_cb_t send) Register HFP client data output function; the callback is only used in the case that Voice Over HCI is enabled. - Parameters recv -- [in] HFP client incoming data callback function send -- [in] HFP client outgoing data callback function - - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: if callback is a NULL function pointer - - esp_err_t esp_hf_client_pkt_stat_nums_get(uint16_t sync_conn_handle) Get the number of packets received and sent This function is only used in the case that Voice Over HCI is enabled and the audio state is connected. When the operation is completed, the callback function will be called with ESP_HF_CLIENT_PKT_STAT_NUMS_GET_EVT. - Parameters sync_conn_handle -- [in] the (e)SCO connection handle - Returns ESP_OK: if the request is sent successfully ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - void esp_hf_client_outgoing_data_ready(void) Trigger the lower-layer to fetch and send audio data. This function is only only used in the case that Voice Over HCI is enabled. After this function is called, lower layer will invoke esp_hf_client_outgoing_data_cb_t to fetch data. As a precondition to use this API, Service Level Connection shall exist with AG. - void esp_hf_client_pcm_resample_init(uint32_t src_sps, uint32_t bits, uint32_t channels) Initialize the down sampling converter. This is a utility function that can only be used in the case that Voice Over HCI is enabled. - Parameters src_sps --
HFP AG API API Reference Header File components/bt/host/bluedroid/api/include/api/esp_hf_ag_api.h This header file can be included with: #include "esp_hf_ag_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_err_t esp_hf_ag_register_callback(esp_hf_cb_t callback) Register application callback function to HFP AG module. This function should be called only after esp_bluedroid_enable() completes successfully. - Parameters callback -- [in] HFP AG event callback function - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: if callback is a NULL function pointer - - esp_err_t esp_hf_ag_init(void) Initialize the bluetooth HF AG module. This function should be called after esp_bluedroid_enable() completes successfully. - Returns ESP_OK: if the initialization request is sent successfully ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_deinit(void) De-initialize for HF AG module. This function should be called only after esp_bluedroid_enable() completes successfully. - Returns ESP_OK: success ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_slc_connect(esp_bd_addr_t remote_bda) To establish a Service Level Connection to remote bluetooth HFP client device. This function must be called after esp_hf_ag_init() and before esp_hf_ag_deinit(). - Parameters remote_bda -- [in] remote bluetooth HFP client device address - Returns ESP_OK: connect request is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_slc_disconnect(esp_bd_addr_t remote_bda) Disconnect from the remote HFP client. This function must be called after esp_hf_ag_init() and before esp_hf_ag_deinit(). - Parameters remote_bda -- [in] remote bluetooth device address - Returns ESP_OK: disconnect request is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_audio_connect(esp_bd_addr_t remote_bda) Create audio connection with remote HFP client. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_bda -- [in] the device address of voice recognition initiator value -- [in] 0 - voice recognition disabled, 1- voice recognition enabled - - Returns ESP_OK: response of volume recognition is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_volume_control(esp_bd_addr_t remote_bda, esp_hf_volume_control_target_t type, int volume) Volume synchronization with HFP client. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_bda -- [in] remote bluetooth device address type -- [in] volume control target, speaker or microphone volume -- [in] gain of the speaker of microphone, ranges 0 to 15 - - Returns ESP_OK: volume synchronization control is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_ERR_INVALID_ARG: if arguments are invalid ESP_FAIL: others - - esp_err_t esp_hf_ag_unknown_at_send(esp_bd_addr_t remote_addr, char *unat) Handle Unknown AT command from HFP Client. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_addr -- [in] remote bluetooth device address unat -- [in] User AT command response to HF Client. It will response "ERROR" by default if unat is NULL. - - Returns ESP_OK: response of unknown AT command is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_cmee_send(esp_bd_addr_t remote_bda, esp_hf_at_response_code_t response_code, esp_hf_cme_err_t error_code) Unsolicited send extend AT error code to HFP Client. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_bda -- [in] remote bluetooth device address response_code -- [in] AT command response code error_code -- [in] CME error code - - Returns ESP_OK: extend error code is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_devices_status_indchange(esp_bd_addr_t remote_addr, esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state, esp_hf_network_state_t ntk_state, int signal) Unsolicited send device status notification to HFP Client. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_addr -- [in] remote bluetooth device address call_state -- [in] call state call_setup_state -- [in] call setup state ntk_state -- [in] network service state signal -- [in] signal strength from 0 to 5 - - Returns ESP_OK: device status notification is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_ERR_INVALID_ARG: if arguments are invalid ESP_FAIL: others - - esp_err_t esp_hf_ag_ciev_report(esp_bd_addr_t remote_addr, esp_hf_ciev_report_type_t ind_type, int value) Send indicator report "+CIEV: <ind> <value>" to HFP Client. "CIEV" means “indicator events reporting", and all indicator types can be sent one type at a time. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_addr -- [in] remote bluetooth device address ind_type -- [in] indicator type value -- [in] indicator value - - Returns ESP_OK: indicator report is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_cind_response(esp_bd_addr_t remote_addr, esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state, esp_hf_network_state_t ntk_state, int signal, esp_hf_roaming_status_t roam, int batt_lev, esp_hf_call_held_status_t call_held_status) Response to device individual indicators to HFP Client. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_addr -- [in] remote bluetooth device address call_state -- [in] call state call_setup_state -- [in] call setup state ntk_state -- [in] network service state signal -- [in] signal strength from 0 to 5 roam -- [in] roam state batt_lev -- [in] battery level from 0 to 5 call_held_status -- [in] call held status - - Returns ESP_OK: response to device individual indicators is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_ERR_INVALID_ARG: if the arguments are invalid ESP_FAIL: others - - esp_err_t esp_hf_ag_cops_response(esp_bd_addr_t remote_addr, char *name) Reponse for AT+COPS command from HF Client. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_addr -- [in] remote bluetooth device address name -- [in] current operator name - - Returns ESP_OK: reponse for AT+COPS command is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_clcc_response(esp_bd_addr_t remote_addr, int index, esp_hf_current_call_direction_t dir, esp_hf_current_call_status_t current_call_state, esp_hf_current_call_mode_t mode, esp_hf_current_call_mpty_type_t mpty, char *number, esp_hf_call_addr_type_t type) Response to AT+CLCC command from HFP Client. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_addr -- [in] remote bluetooth device address index -- [in] the index of current call, starting with 1, finishing response with 0 (send OK) dir -- [in] call direction (incoming/outgoing) current_call_state -- [in] current call state mode -- [in] current call mode (voice/data/fax) mpty -- [in] single or multi type number -- [in] current call number type -- [in] international type or unknow - - Returns ESP_OK: response to AT+CLCC command is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_cnum_response(esp_bd_addr_t remote_addr, char *number, int number_type, esp_hf_subscriber_service_type_t service_type) Response for AT+CNUM command from HF Client. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_addr -- [in] remote bluetooth device address number -- [in] registration number number_type -- [in] value of number type from 128-143: national or international, may contain prefix and/or escape digits 144-159: international, includes country code prefix, add "+" if needed 160-175: national, but no prefix nor escape digits service_type -- [in] service type (unknown/voice/fax) - - Returns ESP_OK: response for AT+CNUM command is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_bsir(esp_bd_addr_t remote_addr, esp_hf_in_band_ring_state_t state) Inform HF Client that AG Provided in-band ring tone or not. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_addr -- [in] remote bluetooth device address state -- [in] in-band ring tone state - - Returns ESP_OK: information of in-band ring tone is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_ERR_INVALID_ARG: if arguments are invalid ESP_FAIL: others - - esp_err_t esp_hf_ag_answer_call(esp_bd_addr_t remote_addr, int num_active, int num_held, esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state, char *number, esp_hf_call_addr_type_t call_addr_type) Answer Incoming Call from AG. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_addr -- [in] remote bluetooth device address num_active -- [in] the number of active call num_held -- [in] the number of held call call_state -- [in] call state call_setup_state -- [in] call setup state number -- [in] number of the incoming call call_addr_type -- [in] call address type - - Returns ESP_OK: answer incoming call is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_reject_call(esp_bd_addr_t remote_addr, int num_active, int num_held, esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state, char *number, esp_hf_call_addr_type_t call_addr_type) Reject Incoming Call from AG. As a precondition to use this API, Service Level Connection shall exist with HFP client.
- Parameters remote_addr -- [in] remote bluetooth device address num_active -- [in] the number of active call num_held -- [in] the number of held call call_state -- [in] call state call_setup_state -- [in] call setup state number -- [in] number of the incoming call call_addr_type -- [in] call address type - - Returns ESP_OK: reject incoming call is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_out_call(esp_bd_addr_t remote_addr, int num_active, int num_held, esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state, char *number, esp_hf_call_addr_type_t call_addr_type) Initiate a call from AG. As a precondition to use this API, Service Level Connection shall exist with HFP client. If the AG is driven by the HF to call esp_hf_ag_out_call, it needs to response an OK or ERROR to HF. But if the AG is actively calling esp_hf_ag_out_call, it does not need to take a response to HF. - Parameters remote_addr -- [in] remote bluetooth device address num_active -- [in] the number of active call num_held -- [in] the number of held call call_state -- [in] call state call_setup_state -- [in] call setup state number -- [in] number of the outgoing call call_addr_type -- [in] call address type - - Returns ESP_OK: a call initiation is sent to lower layer ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled ESP_FAIL: others - - esp_err_t esp_hf_ag_end_call(esp_bd_addr_t remote_addr, int num_active, int num_held, esp_hf_call_status_t call_state, esp_hf_call_setup_status_t call_setup_state, char *number, esp_hf_call_addr_type_t call_addr_type) End an ongoing call. As a precondition to use this API, Service Level Connection shall exist with HFP client.
[in] : size(in bytes) in buf - Return length of data successfully read - typedef void (*esp_hf_cb_t)(esp_hf_cb_event_t event, esp_hf_cb_param_t *param) HF AG callback function type. - Param event : Event type - Param param : Pointer to callback parameter Enumerations - enum esp_hf_cb_event_t HF callback events. Values: - enumerator ESP_HF_CONNECTION_STATE_EVT Connection state changed event - enumerator ESP_HF_AUDIO_STATE_EVT Audio connection state change event - enumerator ESP_HF_BVRA_RESPONSE_EVT Voice recognition state change event - enumerator ESP_HF_VOLUME_CONTROL_EVT Audio volume control command from HF Client, provided by +VGM or +VGS message - enumerator ESP_HF_UNAT_RESPONSE_EVT Unknown AT cmd Response - enumerator ESP_HF_IND_UPDATE_EVT Indicator Update Event - enumerator ESP_HF_CIND_RESPONSE_EVT Call And Device Indicator Response - enumerator ESP_HF_COPS_RESPONSE_EVT Current operator information - enumerator ESP_HF_CLCC_RESPONSE_EVT List of current calls notification - enumerator ESP_HF_CNUM_RESPONSE_EVT Subscriber information response from HF Client - enumerator ESP_HF_VTS_RESPONSE_EVT Enable or not DTMF - enumerator ESP_HF_NREC_RESPONSE_EVT Enable or not NREC - enumerator ESP_HF_ATA_RESPONSE_EVT Answer an Incoming Call - enumerator ESP_HF_CHUP_RESPONSE_EVT Reject an Incoming Call - enumerator ESP_HF_DIAL_EVT Origin an outgoing call with specific number or the dial the last number - enumerator ESP_HF_WBS_RESPONSE_EVT Codec Status - enumerator ESP_HF_BCS_RESPONSE_EVT Final Codec Choice - enumerator ESP_HF_PKT_STAT_NUMS_GET_EVT Request number of packet different status - enumerator ESP_HF_CONNECTION_STATE_EVT
Bluetooth® HID Device API Overview A Bluetooth HID device is a device providing the service of human or other data input and output to and from a Bluetooth HID Host. Users can use the Bluetooth HID Device APIs to make devices like keyboards, mice, joysticks and so on. Application Example Check bluetooth/bluedroid/classic_bt folder in ESP-IDF examples, which contains the following application: This is an example of Bluetooth HID mouse device. The device running this example can be discovered and connected by a Bluetooth HID Host device such as a PC, and the pointer will move left and right after HID connection is established - bluetooth/bluedroid/classic_bt/bt_hid_mouse_device API Reference Header File This header file can be included with: #include "esp_hidd_api.h" This header file is a part of the API provided by the btcomponent. To declare that your component depends on bt, add the following to your CMakeLists.txt: REQUIRES bt or PRIV_REQUIRES bt Functions - esp_err_t esp_bt_hid_device_register_callback(esp_hd_cb_t callback) This function is called to init callbacks with HID device module. - Parameters callback -- [in] pointer to the init callback function. - Returns ESP_OK: success other: failed - - esp_err_t esp_bt_hid_device_init(void) Initializes HIDD interface. This function should be called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_register_callback. When the operation is complete, the callback function will be called with ESP_HIDD_INIT_EVT. - Returns ESP_OK: success other: failed - - esp_err_t esp_bt_hid_device_deinit(void) De-initializes HIDD interface. This function should be called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). When the operation is complete, the callback function will be called with ESP_HIDD_DEINIT_EVT. - Returns ESP_OK: success other: failed - - esp_err_t esp_bt_hid_device_register_app(esp_hidd_app_param_t *app_param, esp_hidd_qos_param_t *in_qos, esp_hidd_qos_param_t *out_qos) Registers HIDD parameters with SDP and sets l2cap Quality of Service. This function should be called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). When the operation is complete, the callback function will be called with ESP_HIDD_REGISTER_APP_EVT. - Parameters app_param --
This function should be called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). When the operation is complete, the callback function will be called with ESP_HIDD_UNREGISTER_APP_EVT. - Returns ESP_OK: success other: failed - - esp_err_t esp_bt_hid_device_connect(esp_bd_addr_t bd_addr) Connects to the peer HID Host with virtual cable. This function should be called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init().