在使用esp-idf中bluedroid/ble/gatt_client时接口esp_ble_gap_stop_scanning不返回,似乎是卡死在里面了,是什么原因??

Coopersu
Posts: 4
Joined: Fri Apr 08, 2022 6:38 am

在使用esp-idf中bluedroid/ble/gatt_client时接口esp_ble_gap_stop_scanning不返回,似乎是卡死在里面了,是什么原因??

Postby Coopersu » Mon Apr 11, 2022 3:24 am

esp-idf branch: release/v4.3 commit:06ce378142f91b90f6c0673fa9363e526664eada
example: bluetooth/bluedroid/ble/gatt_client

我的修改:
在esp_gap_cb中ESP_GAP_BLE_SCAN_START_COMPLETE_EVT事件 添加了resp adv中解析蓝牙设备名称的代码,其他无改动

Code: Select all

    case ESP_GAP_BLE_SCAN_RESULT_EVT: {
        esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;
        switch (scan_result->scan_rst.search_evt) {
        case ESP_GAP_SEARCH_INQ_RES_EVT:
            ESP_LOGI(GATTC_TAG, "----------Device Found-----mac addr-----");
            esp_log_buffer_hex(GATTC_TAG, scan_result->scan_rst.bda, 6);
            ESP_LOGI(GATTC_TAG, "searched Adv Data Len %d, Scan Response Len %d", scan_result->scan_rst.adv_data_len, scan_result->scan_rst.scan_rsp_len);
            adv_name = esp_ble_resolve_adv_data(scan_result->scan_rst.ble_adv,
                                                ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len);
            ESP_LOGI(GATTC_TAG, "searched Device Name Len %d", adv_name_len);
            ESP_LOGI(GATTC_TAG, "ble name:");
            esp_log_buffer_char(GATTC_TAG, adv_name, adv_name_len);

#if CONFIG_EXAMPLE_DUMP_ADV_DATA_AND_SCAN_RESP
            if (scan_result->scan_rst.adv_data_len > 0) {
                ESP_LOGI(GATTC_TAG, "adv data:");
                esp_log_buffer_hex(GATTC_TAG, &scan_result->scan_rst.ble_adv[0], scan_result->scan_rst.adv_data_len);
            }
            if (scan_result->scan_rst.scan_rsp_len > 0) {
                ESP_LOGI(GATTC_TAG, "scan resp:");
                esp_log_buffer_hex(GATTC_TAG, &scan_result->scan_rst.ble_adv[scan_result->scan_rst.adv_data_len], scan_result->scan_rst.scan_rsp_len);
		/* add by aaa*/
                adv_name = esp_ble_resolve_adv_data(&scan_result->scan_rst.ble_adv[scan_result->scan_rst.adv_data_len],
                            ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len);
                ESP_LOGI(GATTC_TAG, "11searched Device Name Len %d", adv_name_len);
                ESP_LOGI(GATTC_TAG, "11ble name:");
                esp_log_buffer_char(GATTC_TAG, adv_name, adv_name_len);
                /* end add by aaa*/
            }
#endif
            ESP_LOGI(GATTC_TAG, "\n");

            if (adv_name != NULL) {
                if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) {
                    ESP_LOGI(GATTC_TAG, "searched device %s\n", remote_device_name);
                    if (connect == false) {
                        connect = true;
                        ESP_LOGI(GATTC_TAG, "connect to the remote device.1\n");
                        uint8_t ret = esp_ble_gap_stop_scanning();
                        ESP_LOGI(GATTC_TAG, "esp_ble_gap_stop_scanning ret = %d\n",ret);
                        //esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
                    }
                }
            }
            ESP_LOGI(GATTC_TAG, "vz end ESP_GAP_BLE_SCAN_RESULT_EVT\n");
            break;

ESP_XuLZ
Posts: 173
Joined: Fri Mar 26, 2021 6:04 am

Re: 在使用esp-idf中bluedroid/ble/gatt_client时接口esp_ble_gap_stop_scanning不返回,似乎是卡死在里面了,是什么原因??

Postby ESP_XuLZ » Thu Apr 21, 2022 11:25 am

感觉你是把 esp_ble_gattc_open 屏蔽掉了,停止了 扫描,又不进行下一步连接的动作,程序就停在这里了

Who is online

Users browsing this forum: No registered users and 96 guests