Skip to content

Commit

Permalink
connection reattempts only if sensor is in CONNECTING state
Browse files Browse the repository at this point in the history
  • Loading branch information
richrobe committed Mar 27, 2019
1 parent 930c3df commit 8418a75
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected BluetoothGattService getService(UUID uuid) {
private boolean mWasDiscovered = false;

private int mReconnectAttempts = 0;
private static final int MAX_RECONNECT_ATTEMPTS = 5;
private static final int MAX_RECONNECT_ATTEMPTS = 2;

/**
* GATT callback instance.
Expand All @@ -184,14 +184,14 @@ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState
mGatt = null;
}
} else {
if (mReconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
mGatt.close();
mGatt = null;
sendConnectionLost();
} else {
if (getState() == SensorState.CONNECTING && mReconnectAttempts < MAX_RECONNECT_ATTEMPTS) {
mReconnectAttempts++;
Log.e(TAG, BluetoothGattStatus.lookup(status) + ", attempting to reconnect (" + mReconnectAttempts + "/" + MAX_RECONNECT_ATTEMPTS + ")...");
mGatt.connect();
} else {
mGatt.close();
mGatt = null;
sendConnectionLost();
}
}
}
Expand Down

0 comments on commit 8418a75

Please sign in to comment.