Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reconnect mechanism not working #764

Open
MohamedEbrahimPos opened this issue Sep 27, 2024 · 6 comments
Open

reconnect mechanism not working #764

MohamedEbrahimPos opened this issue Sep 27, 2024 · 6 comments

Comments

@MohamedEbrahimPos
Copy link

MohamedEbrahimPos commented Sep 27, 2024

val peripheral = scope.peripheral(..) {
    autoConnectIf { true }
}
peripheral.connect()
@twyatt
Copy link
Member

twyatt commented Sep 27, 2024

The code snippet you provided will initiate a connection, but your code doesn't handle reconnection.

autoConnectIf determines if autoConnect should be true for Android's connect call.

Per Kable's documentation, autoConnectIf configures the connect process, not reconnect.

@MohamedEbrahimPos
Copy link
Author

Dose the kable's support reconnection when the connection between the devices failed after the initial connection happen ?
I want to listen if the connection failed Retry to connect .
How can I handel that with kable's?

@twyatt
Copy link
Member

twyatt commented Oct 1, 2024

There are many ways to implement auto-reconnect. One possible approach is to monitor the Peripheral.state and connect when Disconnected state is seen, as demonstrated in the SensorTag sample app.

@MohamedEbrahimPos
Copy link
Author

i want to thank you for your response it helps me a lot

@eygraber
Copy link

The answer explaining autoConnect that is linked in the README states:

If the connection was established through an auto connect, Android will automatically try to reconnect to the remote device when it gets disconnected until you manually call disconnect() or close()

If Kable is explicitly calling disconnect or close when the connection is lost, then the Kable documentation should call out that it will not try to reconnect if autoConnect is true.

@twyatt
Copy link
Member

twyatt commented Dec 18, 2024

Good call out, @eygraber. TY!

I'll re-open issue as a reminder to update the documentation.
Additionally, it might make sense to rename the autoConnect to avoid confusion. Not sure what I would call it instead. 🤔

@twyatt twyatt reopened this Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants