feat(bt/bluedroid): Added API to get local device name
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "esp_gatts_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "esp_gattc_api.h"
|
||||
#include "esp_gatt_defs.h"
|
||||
#include "esp_gatt_common_api.h"
|
||||
@@ -331,7 +332,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
switch (event) {
|
||||
case ESP_GATTC_REG_EVT:
|
||||
ESP_LOGI(BLE_ANCS_TAG, "REG_EVT");
|
||||
esp_ble_gap_set_device_name(EXAMPLE_DEVICE_NAME);
|
||||
esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME);
|
||||
esp_ble_gap_config_local_icon (ESP_BLE_APPEARANCE_GENERIC_WATCH);
|
||||
//generate a resolvable random address
|
||||
esp_ble_gap_config_local_privacy(true);
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@
|
||||
#include "esp_gap_ble_api.h"
|
||||
#include "esp_gatts_api.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "ble_compatibility_test.h"
|
||||
#include "esp_gatt_common_api.h"
|
||||
|
||||
@@ -464,7 +465,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
|
||||
{
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:{
|
||||
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME);
|
||||
esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(SAMPLE_DEVICE_NAME);
|
||||
if (set_dev_name_ret){
|
||||
ESP_LOGE(EXAMPLE_TAG, "set device name failed, error code = %x", set_dev_name_ret);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ static void hidd_event_callback(esp_hidd_cb_event_t event, esp_hidd_cb_param_t *
|
||||
case ESP_HIDD_EVENT_REG_FINISH: {
|
||||
if (param->init_finish.state == ESP_HIDD_INIT_OK) {
|
||||
//esp_bd_addr_t rand_addr = {0x04,0x11,0x11,0x11,0x11,0x05};
|
||||
esp_ble_gap_set_device_name(HIDD_DEVICE_NAME);
|
||||
esp_bt_dev_set_device_name(HIDD_DEVICE_NAME);
|
||||
esp_ble_gap_config_adv_data(&hidd_adv_data);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "esp_gatts_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "ble_spp_server_demo.h"
|
||||
|
||||
#define GATTS_TABLE_TAG "GATTS_SPP_DEMO"
|
||||
@@ -498,7 +499,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "%s %d", __func__, __LINE__);
|
||||
esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME);
|
||||
esp_bt_dev_set_device_name(SAMPLE_DEVICE_NAME);
|
||||
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "%s %d", __func__, __LINE__);
|
||||
esp_ble_gap_config_adv_data_raw((uint8_t *)spp_adv_data, sizeof(spp_adv_data));
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@
|
||||
#include "esp_gatts_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "esp_gatt_common_api.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
@@ -348,7 +349,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].gatts_if = gatts_if;
|
||||
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(TEST_DEVICE_NAME);
|
||||
esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(TEST_DEVICE_NAME);
|
||||
if (set_dev_name_ret){
|
||||
ESP_LOGE(GATTS_TAG, "set device name failed, error code = %x", set_dev_name_ret);
|
||||
}
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@
|
||||
#include "esp_gatts_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "example_ble_sec_gatts_demo.h"
|
||||
|
||||
#define GATTS_TABLE_TAG "SEC_GATTS_DEMO"
|
||||
@@ -407,7 +408,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
|
||||
ESP_LOGV(GATTS_TABLE_TAG, "event = %x",event);
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
esp_ble_gap_set_device_name(EXAMPLE_DEVICE_NAME);
|
||||
esp_bt_dev_set_device_name(EXAMPLE_DEVICE_NAME);
|
||||
//generate a resolvable random address
|
||||
esp_ble_gap_config_local_privacy(true);
|
||||
esp_ble_gatts_create_attr_tab(heart_rate_gatt_db, gatts_if,
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "esp_gatts_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "esp_gatt_common_api.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
@@ -310,7 +311,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A;
|
||||
|
||||
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(TEST_DEVICE_NAME);
|
||||
esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(TEST_DEVICE_NAME);
|
||||
if (set_dev_name_ret){
|
||||
ESP_LOGE(GATTS_TAG, "set device name failed, error code = %x", set_dev_name_ret);
|
||||
}
|
||||
|
||||
+2
-2
@@ -254,7 +254,7 @@ An advertising payload can be up to 31 bytes of data. It is possible the paramet
|
||||
It is possible to also advertise customized raw data using the `esp_ble_gap_config_adv_data_raw()`
|
||||
and `esp_ble_gap_config_scan_rsp_data_raw()` functions, which require to create and pass a buffer for both advertising data and scanning response data. In this example, the raw data is represented by the `raw_adv_data[]` and `raw_scan_rsp_data[]` arrays.
|
||||
|
||||
Finally, to set the device name, the `esp_ble_gap_set_device_name()` function is used. The registering event handler is shown as follows:
|
||||
Finally, to set the device name, the `esp_bt_dev_set_device_name()` function is used. The registering event handler is shown as follows:
|
||||
|
||||
```c
|
||||
static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) {
|
||||
@@ -266,7 +266,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
|
||||
gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A;
|
||||
|
||||
esp_ble_gap_set_device_name(TEST_DEVICE_NAME);
|
||||
esp_bt_dev_set_device_name(TEST_DEVICE_NAME);
|
||||
#ifdef CONFIG_SET_RAW_ADV_DATA
|
||||
esp_err_t raw_adv_ret = esp_ble_gap_config_adv_data_raw(raw_adv_data, sizeof(raw_adv_data));
|
||||
if (raw_adv_ret){
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@
|
||||
#include "esp_gap_ble_api.h"
|
||||
#include "esp_gatts_api.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "gatts_table_creat_demo.h"
|
||||
#include "esp_gatt_common_api.h"
|
||||
|
||||
@@ -341,7 +342,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
|
||||
{
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:{
|
||||
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME);
|
||||
esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(SAMPLE_DEVICE_NAME);
|
||||
if (set_dev_name_ret){
|
||||
ESP_LOGE(GATTS_TABLE_TAG, "set device name failed, error code = %x", set_dev_name_ret);
|
||||
}
|
||||
|
||||
+3
-3
@@ -165,7 +165,7 @@ The ``ESP_HEART_RATE_APP_ID`` serves as an application ID, distinguishing betwee
|
||||
|
||||
The register application event is the first one that is triggered during the lifetime of the program. This example uses this event to configure advertising parameters upon registration in the profile event handler. The functions used to achieve this are:
|
||||
|
||||
* ``esp_ble_gap_set_device_name()``: used to set the advertised device name.
|
||||
* ``esp_bt_dev_set_device_name()``: used to set the advertised device name.
|
||||
* ``esp_ble_gap_config_adv_data()``: used to configure standard advertising data.
|
||||
|
||||
The function used to configure standard Bluetooth Specification advertisement parameters is ``esp_ble_gap_config_adv_data()`` which takes a pointer to an ``esp_ble_adv_data_t`` structure. The ``esp_ble_adv_data_t`` data structure for advertising data has the following definition:
|
||||
@@ -210,7 +210,7 @@ static esp_ble_adv_data_t heart_rate_adv_config = {
|
||||
|
||||
The minimum and maximum slave preferred connection intervals are set in units of 1.25 ms. In this example, the minimum slave preferred connection interval is defined as 0x0006 * 1.25 ms = 7.5 ms and the maximum slave preferred connection interval is initialized as 0x0010 * 1.25 ms = 20 ms.
|
||||
|
||||
An advertising payload can be up to 31 bytes of data. It is possible that some of the parameters surpass the 31-byte advertisement packet limit which causes the stack to cut the message and leave some of the parameters out. To solve this, usually the longer parameters are stored in the scan response, which can be configured using the same ``esp_ble_gap_config_adv_data()`` function and an additional esp_ble_adv_data_t type structure with the .set_scan_rsp parameter is set to true. Finally, to set the device name the ``esp_ble_gap_set_device_name()`` function is used. The registering event handler is shown as follows:
|
||||
An advertising payload can be up to 31 bytes of data. It is possible that some of the parameters surpass the 31-byte advertisement packet limit which causes the stack to cut the message and leave some of the parameters out. To solve this, usually the longer parameters are stored in the scan response, which can be configured using the same ``esp_ble_gap_config_adv_data()`` function and an additional esp_ble_adv_data_t type structure with the .set_scan_rsp parameter is set to true. Finally, to set the device name the ``esp_bt_dev_set_device_name()`` function is used. The registering event handler is shown as follows:
|
||||
|
||||
```c
|
||||
static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
|
||||
@@ -220,7 +220,7 @@ esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
|
||||
switch (event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "%s %d", __func__, __LINE__);
|
||||
esp_ble_gap_set_device_name(SAMPLE_DEVICE_NAME);
|
||||
esp_bt_dev_set_device_name(SAMPLE_DEVICE_NAME);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "%s %d", __func__, __LINE__);
|
||||
esp_ble_gap_config_adv_data(&heart_rate_adv_config);
|
||||
ESP_LOGI(GATTS_TABLE_TAG, "%s %d", __func__, __LINE__);
|
||||
|
||||
@@ -37,6 +37,8 @@ enum {
|
||||
* STATIC FUNCTION DECLARATIONS
|
||||
*******************************/
|
||||
|
||||
/* Device callback function */
|
||||
static void bt_app_dev_cb(esp_bt_dev_cb_event_t event, esp_bt_dev_cb_param_t *param);
|
||||
/* GAP callback function */
|
||||
static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param);
|
||||
/* handler for bluetooth stack enabled events */
|
||||
@@ -46,6 +48,24 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param);
|
||||
* STATIC FUNCTION DEFINITIONS
|
||||
******************************/
|
||||
|
||||
static void bt_app_dev_cb(esp_bt_dev_cb_event_t event, esp_bt_dev_cb_param_t *param)
|
||||
{
|
||||
switch (event) {
|
||||
case ESP_BT_DEV_NAME_RES_EVT: {
|
||||
if (param->name_res.status == ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGI(BT_AV_TAG, "Get local device name success: %s", param->name_res.name);
|
||||
} else {
|
||||
ESP_LOGE(BT_AV_TAG, "Get local device name failed, status: %d", param->name_res.status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ESP_LOGI(BT_AV_TAG, "event: %d", event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
|
||||
{
|
||||
uint8_t *bda = NULL;
|
||||
@@ -110,6 +130,7 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
|
||||
/* when do the stack up, this event comes */
|
||||
case BT_APP_EVT_STACK_UP: {
|
||||
esp_bt_dev_set_device_name(LOCAL_DEVICE_NAME);
|
||||
esp_bt_dev_register_callback(bt_app_dev_cb);
|
||||
esp_bt_gap_register_callback(bt_app_gap_cb);
|
||||
|
||||
assert(esp_avrc_ct_init() == ESP_OK);
|
||||
@@ -127,6 +148,8 @@ static void bt_av_hdl_stack_evt(uint16_t event, void *p_param)
|
||||
|
||||
/* Get the default value of the delay value */
|
||||
esp_a2d_sink_get_delay_value();
|
||||
/* Get local device name */
|
||||
esp_bt_dev_get_device_name();
|
||||
|
||||
/* set discoverable and connectable mode, wait to be connected */
|
||||
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "esp_gattc_api.h"
|
||||
#include "esp_gatt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "esp_gatt_common_api.h"
|
||||
#include "esp_gatts_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
@@ -602,7 +603,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
gatts_profile_tab[GATTS_PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16;
|
||||
gatts_profile_tab[GATTS_PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A;
|
||||
|
||||
esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(GATTS_ADV_NAME);
|
||||
esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(GATTS_ADV_NAME);
|
||||
if (set_dev_name_ret) {
|
||||
ESP_LOGE(COEX_TAG, "set device name failed, error code = %x", set_dev_name_ret);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "esp_bt_device.h"
|
||||
#include "esp_hid_gap.h"
|
||||
|
||||
static const char *TAG = "ESP_HID_GAP";
|
||||
@@ -681,7 +682,7 @@ esp_err_t esp_hid_ble_gap_adv_init(uint16_t appearance, const char *device_name)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = esp_ble_gap_set_device_name(device_name)) != ESP_OK) {
|
||||
if ((ret = esp_bt_dev_set_device_name(device_name)) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "GAP set_device_name failed: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "esp_bt_device.h"
|
||||
#include "esp_hid_gap.h"
|
||||
|
||||
static const char *TAG = "ESP_HID_GAP";
|
||||
@@ -677,7 +678,7 @@ esp_err_t esp_hid_ble_gap_adv_init(uint16_t appearance, const char *device_name)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = esp_ble_gap_set_device_name(device_name)) != ESP_OK) {
|
||||
if ((ret = esp_bt_dev_set_device_name(device_name)) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "GAP set_device_name failed: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user