CPRO not always connecting first time. Second time usually works.
I have code to connect to a given CPRO sensor, by id. It works fine, except it does not always connect the first time (going to the failure() method of ConnectionStateHandler after trying for a couple seconds). However, if I cause it to retry immediately after failure, it nearly always connects the second time.
What could be the possible causes of this, and how could I make it more robust?
----------------------
private MetaWearBleService.LocalBinder metawear_binder;
private MetaWearBoard metawear_board;
HashMap<String, BluetoothDevice> devices = new HashMap<String, BluetoothDevice>();
...
private void sensor_connect(String id) {
final BluetoothDevice device = devices.get(id);
metawear_board = metawear_binder.getMetaWearBoard(device);
metawear_board.setConnectionStateHandler(new MetaWearBoard.ConnectionStateHandler() {
public void connected() {
connected_device = device;
log("Metawear board connected");
}
public void disconnected() {
connected_device = null;
log("Metawear board disconnected");
}
public void failure(int status, Throwable error) {
connected_device = null;
Log.e("Breather", "Metawear connection failure", error);
// If I retry a single time here, it nearly always connects second time.
}
});
log("Metawear board connecting...");
metawear_board.connect();
}
This discussion has been closed.
Comments
failure
callback?