How does ConnectionLostPlease.persistIf work compared to autoconnect?

  • Dear SweetBlue Team,

    I'd like to understand a bit better which tool to use. The goal is to "always" have a BLE device connected through a foreground service.

    I understand that autoconnect is pretty much dark magic and it works in mysterious ways. However, it seems like a good solution for our use case.

    I'm curious about the persist feature of the ConnectionLostPlease. Does it set some internal parameter so that SweetBlue will keep trying to connect to that device whenever it appears or does it timeout after some time/retries? Is there any reason to use this if I'm always using autoconnect from the get go?

    Here's what I found in the documentation about what persist means:

    Thanks a lot

  • When a connection has been deemed to be lost, the onConnectionLost() method is called. This interface must return a ConnectionLostPlease to inform the library what to do (persist in trying to get reconnected, or stop trying).

    Usually, you can achieve what you want without having to implement the logic there, and instead use the DefaultDeviceReconnectFilter. If you never want it to stop trying to connect, then set the timeout value for Interval.INFINITE. I would use infinite on the long term reconnect. Something like so:

    config.reconnectFilter = new DefaultDeviceReconnectFilter(2, 0, Interval.secs(1), Interval.FIVE_SECS, Interval.secs(3), Interval.INFINITE);