Open vsantele opened 2 years ago
I'm getting the same error with .discoverAttributes(), however if I call .discoverService("uuid here") and pass in my service uuid instead it does not crash and lets me connect.
//if (peripheral.discoverAttributes()) { //causes an error on ESP32
if (peripheral.discoverService(SERVICE_ATT)) { //works fine on ESP32
I'm not sure what effect this will have down the line, but happy to see ESP32 support is being actively worked on
Thanks for your comment! So, with your method, you can access to the characteristics of the device?
I will test that tomorrow!
Yes so far everything else in the BLE sample is working on the ESP32. (I'm using the LED control sample as a starting point).
When I use peripheral.discoverService("my-service-uuid")
, the ESP crashes too.
Here is the backtrace:
Decoding stack results
0x400836a5: panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c line 402
0x40092149: esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/esp_system.c line 128
0x400975c5: abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/abort.c line 46
0x40102f93: __cxxabiv1::__terminate(void (*)()) at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc line 47
0x40102fda: std::terminate() at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc line 57
0x40102a79: __cxxabiv1::__cxa_allocate_exception(std::size_t) at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_alloc.cc line 300
0x401028b0: operator new(unsigned int) at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/new_op.cc line 54
0x400d5121: ATTClass::discoverDescriptors(unsigned short, BLERemoteDevice*) at C:\Users\victo\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp line 1738
0x400d3cab: ATTClass::discoverAttributes(unsigned char, unsigned char*, char const*) at C:\Users\victo\Documents\Arduino\libraries\ArduinoBLE\src\utility\ATT.cpp line 217
0x400d22d3: BLEDevice::discoverService(char const*) at C:\Users\victo\Documents\Arduino\libraries\ArduinoBLE\src\BLEDevice.cpp line 274
0x400d16d5: explorerPeripheral(BLEDevice) at C:\Users\victo\Documents\Arduino\generated_examples\PeripheralExplorer_3/PeripheralExplorer_3.ino line 90
0x400d196a: loop() at C:\Users\victo\Documents\Arduino\libraries\ArduinoBLE\src/BLEDevice.h line 39
0x400d93a1: loopTask(void*) at C:\Users\victo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32\main.cpp line 50
The problem occurs when the function ATTClass::discoverDecriptors
creates a new BLERemoteDescriptor
. But I don't know why.
After some researches, I found out that the problem occurs because of an infinite loop in the function bool ATTClass::discoverDescriptors(uint16_t connectionHandle, BLERemoteDevice* device)
in src/utility/ATT.cpp
The program finds descriptors but loop to them until the ESP runs out of memory. I manage to fix this temporary with a counter that stop the loop after 16 iterations, but I suppose there is a bug hidden somewhere that prevents the condition if (responseBuffer[0] == ATT_OP_FIND_INFO_RESP) {
from being false.
Maybe linked to https://github.com/arduino-libraries/ArduinoBLE/pull/259 ?
Maybe #259 fixed peripheral.discoverAttributes()
but there is a problem after. I will rename the issue to be more accurate.
Hi,
Since ArduinoBLE is compatible with ESP32 with the latest merge, I'm trying to use it with an ESP32.
But when I run the example "PeripheralExplorer.ino", I got this exception: (I update the code to detect a peripheral with localName = "D1533286" instead of "Led")
I don't understand why this exception occurred.
Here is my code:
```cpp /* Peripheral Explorer This example scans for Bluetooth® Low Energy peripherals until one with a particular name ("LED") is found. Then connects, and discovers + prints all the peripheral's attributes. The circuit: - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. You can use it with another board that is compatible with this library and the Peripherals -> LED example. This example code is in the public domain. */ #includeThanks
UPDATE 2022-08-31
BLEDevice::discoverService
crashes whenATTClass::discoverAttributes
discovers descriptors withATTClass::discoverDescriptors
.The while loop inside
ATTClass::discoverDescriptors
is never stopped and reads the descriptors in a loop until the ESP has no more memory.I found that for my device there are only 16 descriptors, so I managed to make my program work by stopping the loop after 16 iterations, but I don't understand why the condition
if (responseBuffer[0] == ATT_OP_FIND_INFO_RESP) {
is always true.