esp32-ota-with-ble-setup
esp32-ota-with-ble-setup copied to clipboard
BLE library stack size
Any suggestion how I can increase the stack size in the BLE library (callbacks) ?
Usually its not needed, but you can start new task and start BLE from it.
Where I can find a example how to start my own task and start the BLE from it ? (so far I have seen only examples that the BLE LIB is doing everything it self)
Its common use. Just create normal task, let say somewhere on start your app, then move to it all BLE related functions, like init, start advertising or start scan etc.
you mean the BLE lib checks of it runs on the main thread/task and if YES create its own but in NOT then continue running on the current one ?
e.g. if it is started inside a RTOS task/thread the callback will be the same task/thread ? (as currently the callbacks are on another task/thread)
this is the current scenario - all called on the setup() function 👍
BLEDevice::init(String(BLE_NAME_PREFIX + String(GetSetupDeviceName()) + ")").c_str()); BLEDevice::setMTU(BLE_DEFAULT_MTU); // Create the BLE Server bleServer = BLEDevice::createServer(); bleServer->setCallbacks(new bleServiceCallbacks());
// Create the BLE Service BLEService *pService = bleServer->createService(BLE_SERVICE_UUID);
// Create input BLE Characteristic bleCharacteristicInTransport = pService->createCharacteristic( BLE_CHARACTERISTIC_TRANSPORT_IN_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE );
bleCharacteristicInTransport->setCallbacks(new bleCharacteristicInTransportCallback());
// Create a BLE Descriptor bleCharacteristicInTransport->addDescriptor(new BLE2902());
// Create output BLE Characteristic bleCharacteristicOutTransport = pService->createCharacteristic( BLE_CHARACTERISTIC_TRANSPORT_OUT_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE );
// Create a BLE Descriptor bleCharacteristicOutTransport->addDescriptor(new BLE2902());
// Start the service pService->start();
LOG64_SET(F("BLE: CONNECTED : START NOTIFY")); LOG64_NEW_LINE; // Start advertising
bleServer->getAdvertising()->setScanResponse(true); bleServer->getAdvertising()->setMinPreferred(0x06); bleServer->getAdvertising()->setMaxPreferred(0x12); bleServer->getAdvertising()->start();
This looks like usual use case, in which default arduino stack should be enough. If you have problem with stack i would suggest to check stack water mark.
You can create new task in setup, and like i said earlier, move all BLE init stuff to new task. Callbacks will be called from new task, but global data can be accessible from other tasks too, also in loop.
The issue is inside the callbacks - e.g. I want to change the callbacks task stack size..
Do you have logs? Do you track stack watermark?
also I have some issue with the BLE lib - if I leave a mobile phone connected to the BLEServer for about 24h with constant small data exchange e.g. log messages - sometime after closing the app on the mobile phone the BLE server do not issue the void onDisconnect(BLEServer* pServer) callback and I need to restart the device to get the BLE working again as the bleServer->startAdvertising(); // restart advertising is called only after disconnect
and if I enable the verbose from time to time the ESP32 restarts with the watchdog triggered from BLE
[V][BLEServer.cpp:271] handleGATTServerEvent(): << handleGATTServerEvent
23:18:53: [D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
23:18:53: [V][BLEUtils.cpp:1530] dumpGattServerEvent(): GATT ServerEvent: Unknown
23:18:53: [V][BLEUtils.cpp:1720] dumpGattServerEvent(): dumpGattServerEvent: *** NOT CODED ***
23:18:53: [V][BLEServer.cpp:144] handleGATTServerEvent(): >> handleGATTServerEvent: Unknown
23:18:53: [V][BLECharacteristic.cpp:198] handleGATTServerEvent(): >> handleGATTServerEvent: Unknown
23:18:53: [V][BLECharacteristic.cpp:452] handleGATTServerEvent(): << handleGATTServerEvent
23:18:53: [V][BLECharacteristic.cpp:198] handleGATTServerEvent(): >> handleGATTServerEvent: Unknown
23:18:53: [V][BLECharacteristic.cpp:452] handleGATTServerEvent(): << handleGATTServerEvent
23:18:53: [V][BLEServer.cpp:271] handleGATTServerEvent(): << handleGATTServerEvent
23:18:53: [D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
23:18:53: [V][BLEUtils.cpp:1530] dumpGattServerEvent(): GATT ServerEvent: Unknown
23:18:53: [V][BLEUtils.cpp:1720] dumpGattServerEvent(): dumpGattServerEvent: *** NOT CODED ***
23:18:53: [V][BLEServer.cpp:144] handleGATTServerEvent(): >> handleGATTServerEvent: Unknown
23:18:53: [V][BLECharacteristic.cpp:198] handleGATTServerEvent(): >> handleGATTServerEvent: Unknown
23:18:53: [V][FreeRTOS.cpp:143] give(): Semaphore giving: name: ConfEvt (0x3fff6394), owner: <N/A>
23:18:53: [V][BLECharacteristic.cpp:452] handleGATTServerEvent(): << handleGATTServerEvent
23:18:53: [V][BLECharacteristic.cpp:198] handleGATTServerEvent(): >> handleGATTServerEvent: Unknown
23:18:53: [V][FreeRTOS.cpp:143] give(): Semaphore giving: name: ConfEvt (0x3fff6df4), owner: <N/A>
23:18:53: [V][BLECharacteristic.cpp:452] handleGATTServerEvent(): << handleGATTServerEvent
23:18:53: [V][BLEServer.cpp:271] handleGATTServerEvent(): << handleGATTServerEvent
23:18:53: [D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
23:18:53: [V][BLEUtils.cpp:1530] dumpGattServerEvent(): GATT ServerEvent: Unknown
23:18:53: [V][BLEUtils.cpp:1720] dumpGattServerEvent(): dumpGattServerEvent: *** NOT CODED ***
23:18:54: [V][BLESerE (27871) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
23:18:54: E (27871) task_wdt: - IDLE0 (CPU 0)
23:18:54: E (27871) task_wdt: Tasks currently running:
23:18:54: E (27871) task_wdt: CPU 0: Btc_task
23:18:54: E (27871) task_wdt: CPU 1: loopTask
23:18:54: E (27871) task_wdt: Aborting.
23:18:54: abort() was called at PC 0x400f37b3 on core 0
23:18:54: 3ffe6f40 0x400ec60a:0x3ffe6fa0 0x400ea2c9:0x3ffe6ff0 0x4015d069:0x3ffe7030 0x401562e6:0x3ffe7070 0x4008f75d:0x3ffe70a0
23:18:54: Rebooting...
23:18:54: Initialized: SERIAL_LOG64
23:18:56: Ver.#3.20.1238
Its either in your code or esp-idf bluetooth stack:
23:18:54: E (27871) task_wdt: CPU 0: Btc_task
23:18:54: E (27871) task_wdt: CPU 1: loopTask
EDIT try to decrease log level to info or debug