h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
700 stars 145 forks source link

ESP get Stuck on Boot because of BLE setAdvertisedDeviceCallbacks wantDuplicates parameter #592

Closed Hisham9 closed 11 months ago

Hisham9 commented 1 year ago

hi , I have two separated issues ,note that I'm using last commit for the library: 1- First issues that sometime BLE scan get Stuck and don't report the result any more and only work if I restart the ESP32 any one has any idea why this problem appear ? 2- second problem is kind of weird one if I use setAdvertisedDeviceCallbacks method and make wantDuplicates parameter false (default) when I restart the esp sometime it's hang on boot and code didn't start at all ### I solve this problem temporally by disable all interrupts before restarting but I want to know the real cause of the problem , but when I put wantDuplicates parameter true then esp restart normally .

note that I use ESP32-WROOM-32E and I have very reliable power supply , and here part of code that I use for BLE scanning (I use ESP freeRTOS and this Task run separately on Core 1 with stack size 5000) :

BLEDevice::init(""); pBLEScan = BLEDevice::getScan(); //create new scan BLEDevice::setPower(ESP_PWR_LVL_P7); pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), true); pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster pBLEScan->setInterval(100); pBLEScan->setWindow(99); // less or equal setInterval value pBLEScan->setMaxResults(0);

  if (millis() >= (6006 + TimerCountDown)) {
    while (pBLEScan->isScanning()) delay(1);
    TimerCountDown = millis();
    BLEUpdater();
  }

======================= void BLEUpdater() { Serial.println("Scan started!"); BLEScanResults foundDevices = pBLEScan->start(6, false); //BLEScanResults foundDevices = pBLEScan->getResults(1, false); Serial.print("Devices found: "); Serial.println(foundDevices.getCount()); Serial.println("Scan done!"); pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory pBLEScan->stop(); }

Hisham9 commented 11 months ago

all above have been solved by use library v1.3.8 I think the above issues related to esp-nimble library 1.4