capacitor-community / bluetooth-le

Capacitor plugin for Bluetooth Low Energy
MIT License
273 stars 79 forks source link

Timeout exception and disconnect during BLE write for iOS #661

Closed WillooWisp closed 2 weeks ago

WillooWisp commented 2 months ago

Describe the bug Depending on version of BLE server (different versions of BlueZ), BLE write on same iOS device behaves different. The problem is that against some BLE servers the behavior is incorrect, where we always gets a timeout exception, even though the data is actually written successfully. Increasing the timeout for iOS does not make any difference, except that it takes longer for the timeout to occur, i.e. exception to get caught.

Reading always seems to work immediately after connecting, but waiting a few seconds and reading again just causes timeout exception to occur and a device disconnect as result. Does not make a difference increasing the timeout option.

Connecting is never a problem.

It works as expected using Android against the same BLE server and BlueZ version.

Seems a bit related to #659, regarding timeout and device disconnect.

To Reproduce Steps to reproduce the behavior:

  1. Make a BLE write against BlueZ 5.55, e.g. on Debian 11, from an iOS device.
  2. Timeout exception occurs even though write is successful.

Expected behavior A successful BLE write without timeout exception.

Plugin version:

Smartphone (please complete the following information):

WillooWisp commented 2 months ago

The workaround for now, is to make the connection stateless, i.e. connect before each read and disconnect right after, same for write. That way read and write works without timeouts almost all the time, and since we do not keep the connection open, we also do not get disconnected when timeout occurs. This works okay for us, since we don't use BLE notifications, but there must be some bug in the framework related to iOS and timeouts.

pwespi commented 1 month ago

Do you know if this behavior is specifically happening when connecting to a device with BlueZ version 5.55 or any BlueZ version?

github-actions[bot] commented 2 weeks ago

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day! Capacitor Community Bot 💙

WillooWisp commented 2 weeks ago

Do you know if this behavior is specifically happening when connecting to a device with BlueZ version 5.55 or any BlueZ version?

@pwespi It for sure happens often with 5.55 but I guess it happens for any version below 5.60, but the problem is that these newer versions of BlueZ are only available for Debian 12 and above. It works perfectly fine on Android with any version however.

I think this issue should be reponed again, since not solved.