c++bluetooth-lowenergyesp32platformio

ESP32 BLE not turning off


I am working on a project that uses BLE. I am using the BLE library from arduino, and when I turn off the BLE by calling BLEDevice::deinit(true) the code gets stuck.

I made a deeper search and found that the code got stuck on one of the four functions inside the deinit function. The deinit function os composed of these four functions:

/* STATIC */ void BLEDevice::deinit(bool release_memory) {
if (!initialized) return;

esp_bluedroid_disable();
esp_bluedroid_deinit();
esp_bt_controller_disable();
esp_bt_controller_deinit();
#ifdef ARDUINO_ARCH_ESP32
if (release_memory) {
    esp_bt_controller_mem_release(ESP_BT_MODE_BTDM);  // <-- require tests because we released classic BT memory and this can cause crash (most likely not, esp-idf takes care of it)
} else {
    initialized = false;   
} 
#endif

}

I found that the code stops on the function esp_bluedroid_disable();. I don't have Wi-Fi on the project, so I would ask for help to understand what is going on here.


Solution

  • As discussed in the comments, there was a problem on that BLE library of a memory leak.

    The solution I found is to use another library. I used the Arduino BLE from Arduino: Arduino BLE

    It also can be used on platformio projects: Arduino BLE PlatformIO Registry

    A useful tutorial can be found on this link: Example