You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am running a program that initializes a BLE connection using this code:
void my_ble::initialize_connection(){
// Create the BLE Device
if(!BLEDevice::getInitialized())
{
BLEDevice::init("UART Service");
}
//Set the MTU of the packets sent, maximum is 500, Apple needs 23 apparently.
BLEDevice::setMTU(25);
config.MTU_BLE = 23;
// Create the BLE Server
pServer = BLEDevice::createServer();
ESP_LOGI(TAG_BLE, "Created server");
if(callbacks == NULL)
{
callbacks = new MyServerCallbacks();
}
pServer->setCallbacks(callbacks);
// Create the BLE Service
pService = pServer->createService(SERVICE_UUID);
// Create a BLE Characteristic
pTxCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_NOTIFY
);
if(ble_2902 == NULL)
{
ble_2902 = new BLE2902();
}
pTxCharacteristic->addDescriptor(ble_2902);
pRxCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_RX,
BLECharacteristic::PROPERTY_WRITE
);
// Start the service
pService->start();
}
And then I (try) to clean up the resources used using this function:
my_ble::~my_ble(void){
BLEDevice::deinit();
pServer->removeService(pService);
free(pServer);
free(pService);
pTxCharacteristic->~BLECharacteristic();
pRxCharacteristic->~BLECharacteristic();
free(pTxCharacteristic);
free(pRxCharacteristic);
free(ble_2902);
ble_2902 = NULL;
//Release the wifi_synch_semaphore
ESP_LOGE(TAG_BLE, "Free heap space is %d", esp_get_free_heap_size());
}
Am I missing something?
Also something else that I have noticed:
When I deinitialize the BLEDevice using BLEDevice::deinit() it seems like this code:
void BLEDevice::deinit(bool release_memory) {
if (!initialized) return;
ESP_LOGI("BLEDevice", "Called deinit of BLE Device.");
esp_bluedroid_disable();
esp_bluedroid_deinit();
esp_bt_controller_disable();
esp_bt_controller_deinit();
// initialized = false; // Shouldn't this be added?
#ifndef 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)
ESP_LOGE("BLEDevice", "Releasing memory!!");
// Why is initialized = false not set here? Because we cannot reinitialize anyway (bc of release_mem=true)?
} else {
ESP_LOGE("BLEDevice", "Set initialized to false");
initialized = false;
}
#endif
}
Should set initialized to false regardless of whether the flag ARDUINO_ARCH_ESP32 is set.
The text was updated successfully, but these errors were encountered:
Apparently the memory leak disappears when omitting the call to (see here)esp_bluedroid_deinit(). The problem then becomes that btStart() gets stuck in a while loop:
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
Hi,
I am running a program that initializes a BLE connection using this code:
And then I (try) to clean up the resources used using this function:
Am I missing something?
Also something else that I have noticed:
When I deinitialize the BLEDevice using
BLEDevice::deinit()
it seems like this code:Should set initialized to false regardless of whether the flag
ARDUINO_ARCH_ESP32
is set.The text was updated successfully, but these errors were encountered: