diff --git a/components/bt/common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c b/components/bt/common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c index f0c0aa4a03..744c0df83a 100644 --- a/components/bt/common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c +++ b/components/bt/common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c @@ -381,7 +381,15 @@ void esp_blufi_deinit(void) void esp_blufi_adv_start(void) { - esp_ble_gap_set_device_name(BLUFI_DEVICE_NAME); + esp_ble_gap_config_adv_data(&blufi_adv_data); +} + +void esp_blufi_adv_start_with_name(const char *name) +{ + if (name != NULL) { + esp_ble_gap_set_device_name(name); + } + esp_ble_gap_config_adv_data(&blufi_adv_data); } diff --git a/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h b/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h index 862f7bf02f..8dc9a674ba 100644 --- a/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h +++ b/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h @@ -85,6 +85,9 @@ void esp_blufi_adv_stop(void); /* Start advertisement */ void esp_blufi_adv_start(void); +/* Start advertisement with specified name. if the name is NULL just start advertisement */ +void esp_blufi_adv_start_with_name(const char *name); + void esp_blufi_send_encap(void *arg); #ifdef CONFIG_BT_NIMBLE_ENABLED diff --git a/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c b/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c index bf0c2b7ab0..0f26b9aa94 100644 --- a/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c +++ b/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c @@ -468,6 +468,15 @@ void esp_blufi_adv_start(void) } } +void esp_blufi_adv_start_with_name(const char *name) +{ + if (name != NULL) { + ble_svc_gap_device_name_set(name); + } + + esp_blufi_adv_start(); +} + uint8_t esp_blufi_init(void) { blufi_env.enabled = true; diff --git a/examples/bluetooth/blufi/main/blufi_init.c b/examples/bluetooth/blufi/main/blufi_init.c index d3882a1393..ea998657e9 100644 --- a/examples/bluetooth/blufi/main/blufi_init.c +++ b/examples/bluetooth/blufi/main/blufi_init.c @@ -45,6 +45,13 @@ esp_err_t esp_blufi_host_init(void) } BLUFI_INFO("BD ADDR: "ESP_BD_ADDR_STR"\n", ESP_BD_ADDR_HEX(esp_bt_dev_get_address())); + /* Set the default device name */ + ret = esp_ble_gap_set_device_name(BLUFI_DEVICE_NAME); + if (ret) { + BLUFI_ERROR("%s set device name failed: %s\n", __func__, esp_err_to_name(ret)); + return ESP_FAIL; + } + return ESP_OK; }