ESP32 BLEScan Problem

Jachin
Posts: 11
Joined: Fri Mar 18, 2022 9:06 pm

ESP32 BLEScan Problem

Postby Jachin » Fri Apr 01, 2022 7:50 pm

Question:
When the program just starts running, pblescan - > start (0), even if the corresponding device cannot be found, it can run all the time without any error. However, after the corresponding device is found, if the device can be found continuously, it will not report an error. However, once the corresponding device is not found, the program will report an error guru mediation error: core 0 panic'ed (interrupt WDT timeout on cpu0) in a few seconds. I'd like to ask you what causes this and why there are no problems with the program before searching this device.
  1. #include "BLEDevice.h"
  2. #include "soc/rtc_wdt.h"
  3.  
  4. hw_timer_t *ble_unlock_timer = NULL;
  5.  
  6. bool doorflag = false;                            
  7.  
  8. BLEScan* pBLEScan;
  9. String bleServerName = "HJX2_86BAXXXXXXXX";
  10. long long blescannums = 0;
  11.  
  12. void ScanBLE();
  13. void TaskBLE(void *parameter);
  14. void IRAM_ATTR ble_unlock_onTimer();
  15.  
  16. class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks{
  17.     void onResult(BLEAdvertisedDevice advertisedDevice){
  18.         blescannums ++;
  19.         //Serial.println(advertisedDevice.toString().c_str());
  20.         if(advertisedDevice.haveServiceUUID() && doorflag == false){
  21.             if(strncmp(advertisedDevice.getName().c_str(), bleServerName.c_str(), 9) == 0){
  22.                 advertisedDevice.getScan()->stop();
  23.                 doorflag = true;
  24.                 Serial.print("MAC:");
  25.                 Serial.println(advertisedDevice.getAddress().toString().c_str());
  26.                 pBLEScan->clearResults();
  27.                 ble_unlock_timer = timerBegin(0, 80, true);                
  28.                 timerAttachInterrupt(ble_unlock_timer, &ble_unlock_onTimer, true);    
  29.                 timerAlarmWrite(ble_unlock_timer, 5000000, true);
  30.                 timerAlarmEnable(ble_unlock_timer);
  31.             }
  32.         }
  33.         else{
  34.          
  35.         }
  36.     }  
  37. };
  38.  
  39. void setup(){
  40.     Serial.begin(115200);                        
  41.     BLEDevice::init("");
  42.     pBLEScan = BLEDevice::getScan();
  43.     pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  44.     pBLEScan->setActiveScan(true);
  45.     xTaskCreate(TaskBLE, "TaskBLE", 10000, NULL, 1, NULL);  
  46. }  
  47.  
  48. void loop(){
  49.     Serial.print(blescannums);
  50.     Serial.print(" ");
  51.     delay(1000);
  52. }  
  53.  
  54. void ScanBLE(){
  55.     BLEScanResults scanResults = pBLEScan->start(0);
  56. }
  57.  
  58. void TaskBLE(void *parameter){
  59.     ScanBLE();
  60.     vTaskDelete(NULL);
  61. }
  62.  
  63. void IRAM_ATTR ble_unlock_onTimer(){
  64.     doorflag = false;
  65.     xTaskCreate(TaskBLE, "TaskBLE", 10000, NULL, 1, NULL);    
  66.     timerDetachInterrupt(ble_unlock_timer);
  67.     ble_unlock_timer = NULL;    
  68. }
  69.  
  1. Result
  2. 0 2 2 3 3 3 3 3 3 3 3 3 3 3 MAC:86:ba:4b:44:02:24[2022-04-02 03:44:10.466]
  3. 4 4 4 4 4 4 6 7 7 7 Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU0). [2022-04-02 03:44:20.770]

Who is online

Users browsing this forum: No registered users and 61 guests