ESP32 BLE::init() triggers Task watchdog

Hello guys.
This is my first community post, so feel free to tell me if anything is wrong with my post.

Now the real talk. I am trying to implement BLE on my ESP32-S3 dev board using Arduino IDE. I tried to make the simplest possible program, just to be able to connect to my board via nRFConnect app.

Here's what I made :

#include <BLEDevice.h>
#include <BLEServer.h>

bool deviceConnected = false;

class MyServerCallbacks : public BLEServerCallbacks{
  void onConnect(BLEServer *MyServer){
    deviceConnected = true;
    Serial.println("BLE connected!");
  }
  void onDisconnect(BLEServer *MyServer){
    deviceConnected = false;
    Serial.println("Ble disconnected.");
  }
};

void setup(){
  Serial.begin(115200);
  Serial.println("Starting BLE");

  //Create BLE device 
  BLEDevice::init("ESP32BLE");
  Serial.println("BLEDevice init");

  //Create BLE server
  BLEServer *MyServer = BLEDevice::createServer();
  MyServer->setCallbacks(new MyServerCallbacks());
  Serial.println("BLEServer init");

  //Start advertising
  MyServer->getAdvertising()->start();
  Serial.println("Server start");
}


void loop(){

}

This code was copied from a french tutorial available here:

When reading my Serial Monitor, "Starting BLE" is displayed, then the program waits for about 10 seconds and Task Watchdog is triggered, reseting the app.
I am NOT able to detect my device on the app even though it should be capable of doing so. Any idea how to solve this problem?

Sorry if that sounds trivial to some of you, but hope to get some helpfull tips.
Thanks

Hi @lemniscate-a ,

Welcome to the forum..

You have declared and initialized MyServer inside of setup..
It's not valid after setup finishes..
declare MyServer (globally) before setup and init it inside of setup..

good luck.. ~q

1 Like

Thanks for the answer but I'm not sure that is the problem.
I tried many different ways of declaring MyServer, but nothing works. And I'm quite suprised as it litterally is copy pasted from a tutorial and the code is pretty simple.

BLEDevice::init("ESP32BLE"); always fail

Okay I found the error. I was suprised that the watchdog was tiggered, wich has nothing to do with an issue in the program itself.
My CPU ClockSpeed was too low (I ran it at 10MHz in hope to reduce current, which was not enough for BLE to work properly),

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.