ArduinoBLE icon indicating copy to clipboard operation
ArduinoBLE copied to clipboard

Problem with BLEDevice.discoverAttributes in 1.2.0 version

Open akumar36 opened this issue 4 years ago • 8 comments

I'm working on Arduino Nano 33 IoT and trying to discover attributes of nearby BLE devices. With BLE library version 1.1.3, everything works fine. But, with version 1.2.0, the Arduino device goes to a bad state when I execute discover attributes for some BLE peripherals(Mi band 4 in this case).

I'm attaching my sketch which scans nearby devices and discovers their attributes. BLE_Explorer.zip

Update to reproduction steps: The issue can also be reproduced by using an Android phone acting as a BLE peripheral using NRF connect app. Just configure the GATT server with "Sample Configuration" and try to discover attributes.

akumar36 avatar Apr 21 '21 08:04 akumar36

Running into the same issue, have you found a workaround yet?

My logs from nRF Connect:

22:10:39>Connecting to <MAC_ADDRESS>
22:10:39>gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
22:10:39>[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
22:10:39>Connected to <MAC_ADDRESS>
22:10:39>Discovering services...
22:10:39>gatt.discoverServices()
22:10:39>[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
22:10:40>Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
22:10:54>[Callback] Connection state changed with status: 22 and new state: DISCONNECTED (0)
22:10:54>Error 22 (0x16): GATT CONN TERMINATE LOCAL HOST
22:10:54>Disconnected
22:10:54>[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED

It's also worth mentioning that when it stops advertising, both the OnConnect and OnDisconnect handlers are called

baconcheese113 avatar May 23 '21 04:05 baconcheese113

I isolated my issue down to BLE.advertise() not also allowing service discovery by peripherals

Not sure why, but calling BLE.available() every loop cycle allowed services to be discovered

baconcheese113 avatar May 23 '21 23:05 baconcheese113

The issue seems to be due to this submission: https://github.com/arduino-libraries/ArduinoBLE/commit/3074107

Reverting the above change back resolves the issue.

akumar36 avatar Jun 23 '21 12:06 akumar36

I isolated my issue down to BLE.advertise() not also allowing service discovery by peripherals

Not sure why, but calling BLE.available() every loop cycle allowed services to be discovered

calling BLE.available() function did not help.

akumar36 avatar Jun 23 '21 12:06 akumar36

I have the same issue on Arduino BLE Nano 33 with a Cycling Power Meter.

For Reference I have attached debug dumps for hcidump-bsp1.3.1-library1.1.3.txt hcidump-bsp2.4.1-library1.2.1.txt

  • Arduino Nano 33 BSP 1.3.1 - ArduinoBLE 1.1.3 (working)
  • Arduino Nano 33 BSP 2.4.1 - ArduinoBLE 1.3.1 (with the bug described above)

@polldo: Can you look into this?

ElreboCM avatar Aug 13 '21 15:08 ElreboCM

I can confirm that reverting the change of this commit resolves the issue.

ElreboCM avatar Aug 14 '21 10:08 ElreboCM

Small update just in case someone else was experiencing this issue as of March 2023: Reverting the change of the aforementioned commit resolved it for me as well (Hardware: Portenta H7 connecting over BLE to two Nicla Sense ME boards).

Elaboration on our setup: Both Nicla boards have a unique BLE device name, but identical service and characteristic UUIDs. We cycle through each peripheral (nicla) on the Central device. The first Nicla was discovered as expected, however the second one kept failing the characteristic discovery step.

Changing "J+1" to "J" seemed to immediately resolve this.

If I broke any rules by commenting / updating - My sincere apologies :)

TheMadMoose avatar Mar 06 '23 08:03 TheMadMoose

@TheMadMoose Can you elaborate on where I should change J+1 to J? My peripheral discoverAttributes() call always returns false, and I'm at a loss. I'm using two esp32s...

ForrestThump avatar Feb 01 '24 05:02 ForrestThump