BLEScan crashes whole ESP32 on second call

Mike1997
Posts: 14
Joined: Fri May 10, 2019 6:57 am

BLEScan crashes whole ESP32 on second call

Postby Mike1997 » Tue Feb 25, 2020 6:47 pm

I make use of following code to scan for Bluetooth-devices:

Code: Select all

   BLEDevice::init("");
   pBLEScan = BLEDevice::getScan(); //create new scan
   if (pBLEScan)
   {
      pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
      pBLEScan->setActiveScan(true); //set passive scan; active scan uses more power, but get results faster
      pBLEScan->setInterval(100);
      pBLEScan->setWindow(99);  // less or equal setInterval value
      BLEScanResults foundDevices = pBLEScan->start(5,false);
      pBLEScan->stop();
      pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory
      delete pBLEScan;
      pBLEScan=0;
   }
   BLEDevice::deinit(true);
This code works properly on the very first call (called out of setup()) but when I try to call it the second time some minutes later (this time out of loop() but this does not seem to make a difference), pBLEScan->start() crashes with folowing error message:
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c:1443 (xQueueGenericReceive)- assert failed!
The whole Bluetooth-stuff is completely initialised and removed on every call due to memory problems - when I do not release this stuff completely, my application lacks enough memory.

Any idea what is wrong and how I can avoid this crash?

Thanks!

Who is online

Users browsing this forum: Baoshi and 379 guests