Remove reinitializing the BLE stack on each scan. (#949)
Using NimBLE requires less resources than bluedroid so it is much less beneficial to deinitialize the stack. Instead this initializes it once in initial setup and only deinitializes before entering deep sleep.
This commit is contained in:
1 parent
e3731bdccf
commit
c82f6cadb6
1 file changed
+4
-8
+4
-8
@@ -649,8 +649,6 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
||||
void BLEscan() {
|
||||
disableCore0WDT();
|
||||
Log.notice(F("Scan begin" CR));
|
||||
BLEDevice::setScanDuplicateCacheSize(BLEScanDuplicateCacheSize);
|
||||
BLEDevice::init("");
|
||||
BLEScan* pBLEScan = BLEDevice::getScan();
|
||||
MyAdvertisedDeviceCallbacks myCallbacks;
|
||||
pBLEScan->setAdvertisedDeviceCallbacks(&myCallbacks);
|
||||
@@ -660,7 +658,6 @@ void BLEscan() {
|
||||
BLEScanResults foundDevices = pBLEScan->start(Scan_duration / 1000, false);
|
||||
scanCount++;
|
||||
Log.notice(F("Found %d devices, scan number %d end deinit controller" CR), foundDevices.getCount(), scanCount);
|
||||
BLEDevice::deinit(true);
|
||||
enableCore0WDT();
|
||||
}
|
||||
|
||||
@@ -713,7 +710,6 @@ void notifyCB(
|
||||
*/
|
||||
void BLEconnect() {
|
||||
Log.notice(F("BLE Connect begin" CR));
|
||||
BLEDevice::init("");
|
||||
for (vector<BLEdevice*>::iterator it = devices.begin(); it != devices.end(); ++it) {
|
||||
BLEdevice* p = *it;
|
||||
if (p->sensorModel == LYWSD03MMC || p->sensorModel == MHO_C401) {
|
||||
@@ -819,10 +815,7 @@ void deepSleep(uint64_t time_in_us) {
|
||||
# endif
|
||||
|
||||
Log.trace(F("Deactivating ESP32 components" CR));
|
||||
esp_bluedroid_disable();
|
||||
esp_bluedroid_deinit();
|
||||
esp_bt_controller_disable();
|
||||
esp_bt_controller_deinit();
|
||||
BLEDevice::deinit(true);
|
||||
esp_bt_mem_release(ESP_BT_MODE_BTDM);
|
||||
// Ignore the deprecated warning, this call is necessary here.
|
||||
# pragma GCC diagnostic push
|
||||
@@ -866,6 +859,9 @@ void setupBT() {
|
||||
atomic_init(&jsonBTBufferQueueNext, 0); // in theory, we don't need this
|
||||
atomic_init(&jsonBTBufferQueueLast, 0); // in theory, we don't need this
|
||||
|
||||
BLEDevice::setScanDuplicateCacheSize(BLEScanDuplicateCacheSize);
|
||||
BLEDevice::init("");
|
||||
|
||||
// we setup a task with priority one to avoid conflict with other gateways
|
||||
xTaskCreatePinnedToCore(
|
||||
coreTask, /* Function to implement the task */
|
||||
|
||||
Reference in new issue
Block a user