Disable Bluetooth error

quanvuee
Posts: 5
Joined: Tue Dec 05, 2017 4:53 am

Disable Bluetooth error

Postby quanvuee » Tue Dec 05, 2017 5:05 am

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;
    }

blekyo
Posts: 10
Joined: Tue Nov 14, 2017 2:15 am

Re: Disable Bluetooth error

Postby blekyo » Fri Dec 15, 2017 10:10 am

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

adam_ohara
Posts: 7
Joined: Thu Jun 07, 2018 2:13 pm

Re: Disable Bluetooth error

Postby adam_ohara » 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.

Who is online

Users browsing this forum: Bing [Bot] and 3 guests