Open maciej-szulc opened 1 year ago
I think I have found a solution. Actually it was also proposed in #301 . I inserted a long delay after canceling the stream and before taking any other action.
I agree, for me instead of just wait a fixed amount of time, I check the connectedDeviceStream and wait for the disconnected event for that specific device, just do a firstwhere and check device ID match and state is "disconnected"
For me, the problem occurs only on Android. Stream returned from the connect method never fires disconnect
event. I had to change the listener for connectedDeviceStream
as @William-Geng suggested. So I just ignored events from connect method and only used the subscription to disconnect from the device.
Moreover, I have faced issues with asynchronous actions, also only on Android. After disconnecting, I call some writes on the device, which creates unhandled connection that is never terminated (requires application to be killed, BT turned off / on on the device or restart the device manually). More here: https://github.com/PhilipsHue/flutter_reactive_ble/issues/589
+1. I have set a connection timeout of 1 second. Even after inserting a delay of 4 seconds between disconnecting device 1 and connecting to device 2, I am facing the same issue. @maciej-szulc Is the delay working consistently for you?
@rsubramanyam2994 I haven't tested it recently. Have you tried the more elegant solution that William suggested above?
Describe error. [Android only, all versions - on iOS it works fine for me]
After disconnecting (canceling the stream), when I try to reconnect new device the status remains "connecting" indefinitely.
It happens when I want to connect another device. I am able to connect the same device, but I am not able to connect a new device.
Simply put, when I clear the connections to zero connected devices by canceling the stream, I can't connect to any other device than what was previously connected. After turning the app off and on, it works fine.
Interestingly, when one device is connected and tries to change the other device - the bug does not occur.
Does anyone have any idea?
To reproduce. Steps to reproduce the behavior:
Expected behavior. When I disconnect from any device, the app should be ready to reconnect to any new/same device.
Smartphone / tablet.
Peripheral device.
Additionally. This is how I disconnect to device.![image](https://user-images.githubusercontent.com/72496306/234556008-e4e915b7-472c-469d-89d4-a10f18ca17b8.png)
Do you think it may be causes by custom BLE device? It should work anyway, maybe any suggestion what to try?