Page 1 of 1

Disable Bluetooth error

Posted: Tue Dec 05, 2017 5:05 am
by quanvuee
Hi everyone.
I want to disable BLE affter my function done.
But when I try "esp_bluedroid_disable", It never return and code affter this don't work.
I don't know how and I can't find any example about disable Bluetooth.
Hope someone can help me.
This is my code to disable Bluetooth. It never run to "ESP_LOGI(GATTS_TAG, "esp_bluedroid_disable done");"

Code: Select all

    ESP_LOGI(GATTS_TAG, "Stop ble");
    esp_err_t ret;
    ret = esp_ble_gatts_app_unregister(gl_profile_tab.gatts_if);
    if (ret) {
        ESP_LOGE(GATTS_TAG, "%s esp_ble_gatts_app_unregister failed\n", __func__);
        return;
    }
    ret = esp_bt_controller_disable();
    if (ret) {
        ESP_LOGE(GATTS_TAG, "%s esp_bt_controller_disable failed\n", __func__);
        return;
    }
     ESP_LOGI(GATTS_TAG, "esp_bt_controller_deinit");
   ret = esp_bt_controller_deinit();
    if (ret) {
        ESP_LOGE(GATTS_TAG, "%s esp_bt_controller_deinit failed\n", __func__);
        return;
    }
    ESP_LOGI(GATTS_TAG, "esp_bluedroid_disable");
    ret = esp_bluedroid_disable();
    ESP_LOGI(GATTS_TAG, "esp_bluedroid_disable done");
    if (ret) {
        ESP_LOGE(GATTS_TAG, " esp_bluedroid_disable failed\n");
        return;
    }
    ESP_LOGI(GATTS_TAG, "esp_bluedroid_deinit");
    ret = esp_bluedroid_deinit();
    if (ret) {
        ESP_LOGE(GATTS_TAG, "%s esp_bluedroid_deinit failed\n", __func__);
        return;
    }

Re: Disable Bluetooth error

Posted: Fri Dec 15, 2017 10:10 am
by blekyo
Hi quanvuee,
Did you manage to make it work? I've heard that instead of deinit evertything we should just use "esp_bt_controller_disable", it doesn't work for me eitheir. I also tried to execute "ESP.restart();" on the loop (only on a certain condition), but the esp32 restart every seconds. I'm clueless, so if have any idea, would be great.
Cheers

Re: Disable Bluetooth error

Posted: Thu Mar 07, 2019 5:45 pm
by adam_ohara
This may be a bit late, but I found this issue after positing my own thread on this topic. This seems to happen when you try to disable the bluetooth in its own thread (IE, in the gatt callback or something). You basically end up with a deadlock. I worked around it using https://www.freertos.org/xTimerPendFunctionCall.html to run the disable code on the timer thread.

Re: Disable Bluetooth error

Posted: Tue Mar 05, 2024 8:23 am
by wanglong126
adam_ohara wrote:
Thu Mar 07, 2019 5:45 pm
This may be a bit late, but I found this issue after positing my own thread on this topic. This seems to happen when you try to disable the bluetooth in its own thread (IE, in the gatt callback or something). You basically end up with a deadlock. I worked around it using https://www.freertos.org/xTimerPendFunctionCall.html to run the disable code on the timer thread.
I have been looking for a long time, your answer is very helpful to me, thank you.