PhilipsHue / flutter_reactive_ble

Flutter library that handles BLE operations for multiple devices.
https://developers.meethue.com/
Other
661 stars 321 forks source link

Do not receive DeviceConnectionState.connecting on iOS example app v 5.0.2 #468

Open cjcdev opened 2 years ago

cjcdev commented 2 years ago

Describe the bug On iOS, I do not receive DeviceConnectionState.connecting state before the Connected state.

On Android, I am always seeing Connecting state.

To Reproduce Steps to reproduce the behavior:

  1. Use example code app from 5.0.2 package.
  2. Connect to device
  3. Disconnect from device
  4. Look at the logs. You will see a Connected event, but not a Connecting event.

Expected behavior I should always see Connecting state prior to Connected state

Smartphone / tablet

Peripheral device

arthurv commented 2 years ago

Can confirm this issue as well - we can see a connected event, but DeviceConnectionState.connecting never happens.

pzehle commented 2 years ago

Any updates on this?

I am also having this issue. This comes as a big problem when the user decides to click on "Cancel" when the pair prompt appears. Because connecting never happens, the library thinks the user clicked on "Pair", which is not always true.

Anyway, when the prompt appears, library reports as connected, so there is actually no way to know for sure if the device is actually connected or not. Only way for me to do this right now is to attempt the connection 2 times.

Any better ideas?

arthurv commented 2 years ago

This issue has actually been mentioned elsewhere: https://github.com/PhilipsHue/flutter_reactive_ble/issues/385#issuecomment-1040502145

And I can also confirm the linked comment - the "connecting" state isn't communicated on the first connect, but if I disconnect and reconnect, the "Connecting" state is seen.

santa010 commented 2 years ago

Any news on the issue?

santa010 commented 2 years ago

Did anyone find any better workaround for the 1st connection issue, or is disconnect and then reconnect the way to go for now?

mckn commented 2 years ago

Same issue here, any news regarding this?

trueb2 commented 1 year ago

This issue has actually been mentioned elsewhere: #385 (comment)

And I can also confirm the linked comment - the "connecting" state isn't communicated on the first connect, but if I disconnect and reconnect, the "Connecting" state is seen.

385 is not resolved, but the issue hasn't been re-opened. The fix was reverted in https://github.com/PhilipsHue/flutter_reactive_ble/pull/440 according to https://github.com/PhilipsHue/flutter_reactive_ble/issues/385#issuecomment-1040524572. The error Warning! No event channel set up to report a connection update is still happening on iOS in 5.0.2.

Attempting but failing to mitigate the issue, I do several steps recommended in various issues

  1. WidgetsFlutterBinding.ensureInitialized(); as the first line in main
  2. Initialize a FlutterReactiveBle ble instance as soon as I have permission approved
  3. Await a ble.initialize() call
  4. Await 100 milliseconds
  5. Subscribe to ble.statusStream
    1. If ble.status = BleStatus.ready, then cancel existing scan subscription, await 50 milliseconds, and start a new one.
  6. before connectTo on a DiscoveredDevice, await 100 milliseconds
  7. before subscribing to characteristics after connect, await 500 milliseconds

This sequence does not mitigate the issue but seems reliable for everything else.

vanlooverenkoen commented 1 year ago

I'm having the same issue on iOS using 5.0.3