BLE注销GATT客户端报错的问题

某某ESP32友
Posts: 25
Joined: Fri May 07, 2021 4:10 pm

BLE注销GATT客户端报错的问题

Postby 某某ESP32友 » Thu Dec 28, 2023 10:56 am

IDF版本5.1.2,GATTC注册代码根据gattc_gatts_coex例程生成:

Code: Select all

esp_err_t register_gattc(void)
{
    esp_err_t ret;

    ret = esp_ble_gattc_register_callback(esp_gattc_cb);
    if (ret)
    {
        ESP_LOGE(COEX_TAG, "%s gattc register failed, error code = %x\n", __func__, ret);
        return ret;
    }

    ret = esp_ble_gattc_app_register(GATTC_PROFILE_C_APP_ID);
    if (ret)
    {
        ESP_LOGE(COEX_TAG, "%s gattc app register failed, error code = %x\n", __func__, ret);
        return ret;
    }

    esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
    if (local_mtu_ret)
    {
        ESP_LOGE(COEX_TAG, "set local  MTU failed, error code = %x", local_mtu_ret);
        return local_mtu_ret;
    }

    return ESP_OK;
}
正常运行,根据代码写的注销函数:

Code: Select all

static esp_err_t unregister_gattc(void)
{
    esp_err_t ret;

    // 注销GATT客户端应用
    ret = esp_ble_gattc_app_unregister(GATTC_PROFILE_C_APP_ID);
    if (ret)
    {
        ESP_LOGE(COEX_TAG, "%s gattc app unregister failed, error code = %x\n", __func__, ret);
        return ret;
    }

    // 注销GATT客户端回调函数
    ret = esp_ble_gattc_register_callback(NULL);
    if (ret)
    {
        ESP_LOGE(COEX_TAG, "%s gattc unregister failed, error code = %x\n", __func__, ret);
        return ret;
    }

    return ESP_OK;
}
每次运行都会报错:

Code: Select all

I (14276) GATTC_GATTS_COEX: GATTC unregisted.
E (14276) BT_APPL: Deregister Failed unknown client cif
E (14276) GATTC_GATTS_COEX: unregister_gattc gattc unregister failed, error code = ffffffff

I (14286) GATTC_GATTS_COEX: BLE closed.
W (14296) BT_APPL: bta_dm_disable BTA_DISABLE_DELAY set to 200 ms
请问是什么原因?

ESP_MacChu
Posts: 47
Joined: Tue Nov 21, 2023 7:53 am

Re: BLE注销GATT客户端报错的问题

Postby ESP_MacChu » Tue Jan 02, 2024 12:12 pm

使用函数时,形参用错了,下面是注销代码的一个示例:

static esp_err_t unregister_gattc(void)
{
esp_err_t ret;

// 注销GATT客户端应用
ret = esp_ble_gattc_app_unregister(gattc_profile_tab[GATTC_PROFILE_C_APP_ID].gattc_if);
if (ret)
{
ESP_LOGE(COEX_TAG, "%s gattc app unregister failed, error code = %x\n", __func__, ret);
return ret;
}

// 注销GATT客户端回调函数
ret = esp_ble_gattc_register_callback(esp_gattc_cb);
if (ret)
{
ESP_LOGE(COEX_TAG, "%s gattc unregister failed, error code = %x\n", __func__, ret);
return ret;
}

return ESP_OK;
}

某某ESP32友
Posts: 25
Joined: Fri May 07, 2021 4:10 pm

Re: BLE注销GATT客户端报错的问题

Postby 某某ESP32友 » Thu Jan 04, 2024 3:16 am

感谢,解决了,想当然了。

Who is online

Users browsing this forum: No registered users and 147 guests