hfp ag初始化失败问题求助
Posted: Mon Sep 04, 2023 9:20 am
esf-idf版本:V5.0.2
开发板型号:ESP32-WROOM-32UE、ESP32-WROVER-E
问题描述:结合蓝牙扫描与hfp ag例程时,使用esp32开发板作为hfp ag端,在ESP32-WROVER-E运行正常,但是程序烧到ESP32-WROOM-32UE后,发现ESP32-WROOM-32UE扫描到蓝牙耳机后,蓝牙耳机无法连接开发板。
连接耳机代码如下:
log如下:
主要是出现“BT_BTIF: CHECK_HF_INIT: connect_init: HF AG not initialized”这个log,之前全部运行正常,但是程序烧到ESP32-WROOM-32UE后就出现这个log,然后就无法连接了,希望各位帮忙。
开发板型号:ESP32-WROOM-32UE、ESP32-WROVER-E
问题描述:结合蓝牙扫描与hfp ag例程时,使用esp32开发板作为hfp ag端,在ESP32-WROVER-E运行正常,但是程序烧到ESP32-WROOM-32UE后,发现ESP32-WROOM-32UE扫描到蓝牙耳机后,蓝牙耳机无法连接开发板。
连接耳机代码如下:
Code: Select all
static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
switch (event)
{
/* when device discovered a result, this event comes */
case ESP_BT_GAP_DISC_RES_EVT:
{
/* 扫描到 bt 设备, 开始检查设备是否是希望连接的 bt */
if (bt_hfp_ag_status == BT_STATUS_DISCOVERING)
{
filter_inquiry_scan_result(param);
}
break;
}
/* when discovery state changed, this event comes */
/* 扫描状态变化 */
case ESP_BT_GAP_DISC_STATE_CHANGED_EVT:
{
/* 扫描变为停止状态 */
if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STOPPED)
{
/* 停止扫描,并且找到期望设备,开始连接 */
if (bt_hfp_ag_status == BT_STATUS_DISCOVERED)
{
ESP_LOGI(BT_SCAN_TAG, "Device discovery stopped.");
ESP_LOGI(BT_SCAN_TAG, "hfp hf connecting to peer: %s", BtHfpAg.s_peer_bdname);
bt_hfp_ag_status = BT_STATUS_CONNECTING;
/* connect source to peer device specificed by Bluetooth Device Address */
esp_hf_ag_slc_connect(BtHfpAg.s_peer_bda);
}
/* 停止扫描,但仍然希望扫描(自定义的 bt_hfp_ag_status 处于扫描状态),重启扫描 */
else if (bt_hfp_ag_status == BT_STATUS_DISCOVERING)
{
// /* not discovered, continue to discover */
ESP_LOGW(BT_SCAN_TAG, "Device discovery failed, continue to discover...");
esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, 10, 0);
}
}
else if (param->disc_st_chg.state == ESP_BT_GAP_DISCOVERY_STARTED)
{
ESP_LOGI(BT_SCAN_TAG, "Discovery started.");
}
break;
}
/* when authentication completed, this event comes */
case ESP_BT_GAP_AUTH_CMPL_EVT:
{
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS)
{
ESP_LOGI(BT_SCAN_TAG, "authentication success: %s", param->auth_cmpl.device_name);
esp_log_buffer_hex(BT_SCAN_TAG, param->auth_cmpl.bda, ESP_BD_ADDR_LEN);
}
else
{
ESP_LOGE(BT_SCAN_TAG, "authentication failed, status: %d", param->auth_cmpl.stat);
}
break;
}
/* when Legacy Pairing pin code requested, this event comes */
case ESP_BT_GAP_PIN_REQ_EVT:
{
ESP_LOGI(BT_SCAN_TAG, "ESP_BT_GAP_PIN_REQ_EVT min_16_digit: %d", param->pin_req.min_16_digit);
if (param->pin_req.min_16_digit)
{
ESP_LOGI(BT_SCAN_TAG, "Input pin code: 0000 0000 0000 0000");
esp_bt_pin_code_t pin_code = {0};
esp_bt_gap_pin_reply(param->pin_req.bda, true, 16, pin_code);
}
else
{
ESP_LOGI(BT_SCAN_TAG, "Input pin code: 1234");
esp_bt_pin_code_t pin_code;
pin_code[0] = '1';
pin_code[1] = '2';
pin_code[2] = '3';
pin_code[3] = '4';
esp_bt_gap_pin_reply(param->pin_req.bda, true, 4, pin_code);
}
break;
}
/* when GAP mode changed, this event comes */
case ESP_BT_GAP_MODE_CHG_EVT:
{
ESP_LOGI(BT_SCAN_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode: %d", param->mode_chg.mode);
break;
}
/* other */
default:
{
ESP_LOGI(BT_SCAN_TAG, "event: %d", event);
break;
}
}
return;
}
Code: Select all
I (900) MY_BT_SCAN: Starting device discovery...
I (2587) MY_BT_SCAN: event: 10
E (2587) BT_BTC: btc_hf_cb_handler: Invalid index 56523
I (2587) MY_BT_SCAN: event: 10
I (2597) MY_BT_SCAN: event: 10
I (2597) MY_BT_SCAN: Discovery started.
I (2877) MY_BT_SCAN: Scanned device: 38:00:25:0c:11:37
I (3097) MY_BT_SCAN: Scanned device: 38:00:25:0c:11:37
filter_inquiry_scan_result(389) device address d8:aa:59:56:c3:6a, name OPPO Enco Free2i
I (20237) MY_BT_SCAN: Found a target device, address d8:aa:59:56:c3:6a, name OPPO Enco Free2i
I (20247) MY_BT_SCAN: Cancel device discovery ...
I (20257) MY_BT_SCAN: Device discovery stopped.
I (20257) MY_BT_SCAN: hfp hf connecting to peer: OPPO Enco Free2i
W (20267) BT_BTIF: CHECK_HF_INIT: connect_init: HF AG not initialized