Open maBarabas opened 2 years ago
I am also running into the same issue
I also have the same issue.
@maBarabas did you succeed with listening to the bleStatusStream. I added gates on the write/read/subscribe functions in my code, for when state != connected
but somehow this is not always working out.
Is this issue still being tracked?
Describe the bug On Android, when I try to write to a disconnected device, a new connection is created with an infinite timeout. This causes several issues:
Stream<ConnectionStateUpdate>
that we could cancel likeconnectToDevice
does. There is no way to cancel this connection, and all subsequent calls toconnectToAdvertisingDevice
fail.To Reproduce Steps to reproduce the behavior:
Expected behavior
I expect an error to be reported by the library when trying to perform illegal operations such as writing to a disconnected device.
connectToDevice
,connectToAdvertisingDevice
functions.The nRF connect UI does not allow read write while the device is not connected.
Smartphone / tablet
Peripheral device
This issue should be reproducible on any peripheral device.
Additional context
This seems to be caused by this line: https://github.com/PhilipsHue/flutter_reactive_ble/blob/c25bedf9bc00abdac60927f42a8aafdc5ae5dbf8/packages/reactive_ble_mobile/android/src/main/kotlin/com/signify/hue/flutterreactiveble/ble/ReactiveBleClient.kt#L245
When the connection for the selected deviceId is not active, a new connection is created. I've looked through the git history for clues as to why a new connection is created here, but that line of code has been there since the inital commit to the repo.
On iOS, an exception is raised as expected:
I'll try wrapping the write/read/subscribe function so that using them on a device that is not in the connected state throws. Monitoring the connection state for all devices should be possible using the bleStatusStream property.