-
Couldn't load subscription status.
- Fork 57
Reconnection
There are two different interfaces for dealing with reconnecting devices.
If a connection to a device fails (either the raw BLE connection, or if service discovery fails if the option BleManagerConfig.connectFailRetryConnectingOverall is set to true), then SweetBlue looks at the Please that is returned from the ConnectionFailListener to know what to do. If you do not explicitly set a listener, the default is used (DefaultConnectionFailListener), which retries twice before giving up.
This filter only applies once the device you are connecting to has reached the INITIALIZED state. If connection is lost, the device will go into the RECONNECTING_SHORT_TERM state. When in this state, the device is still treated as being "connected", in that you can still do reads/writes, and they will queue up until the device gets connected again. If the short term reconnect fails to establish a connection, then the device will fall into the DISCONNECTED state, and also go into RECONNECTING_LONG_TERM. If the long term fails to connect after it's timeout period, then the device will stop trying to reconnect completely. At this point, to connect to the device you will have to call one of the connect methods manually.
If you do not set a ReconnectFilter, the default will be used (DefaultReconnectFilter). The default values for this are:
(Interval below means the time SweetBlue will wait before attempting another reconnect)
Short term timeout: 5 seconds Short term interval: 1 second
Long term timeout: 5 minutes Long term interval: 3 seconds
If you would like to change the above times, feel free to instantiate DefaultReconnectFilter, and input your own values.
