Sensor isn't Operation again after reconnect.
Hi
Now I'm Using metawear C Pro and development android app in Java
I'm using BMI160 Step detector for my Traker App.
I Service Connected like this.
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
//serviceBinder = (BtleService.LocalBinder) service;
board = ((BtleService.LocalBinder) service).getMetaWearBoard(btDevice);
Log.e(TAG, "onServiceConnected: " + "Service Conn");
board.onUnexpectedDisconnect(status -> attemptReconnect());
retrieveBoard();
}
**retrieveBoard() Method **
public void retrieveBoard() {
final BluetoothManager btManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
final BluetoothDevice remoteDevice = btManager.getAdapter().getRemoteDevice(MW_ADDRESS);
// Create a MetaWear board object for the Bluetooth Device
//board = serviceBinder.getMetaWearBoard(remoteDevice);
//board = serviceBinder.getMetaWearBoard(remoteDevice);
board.connectAsync().onSuccessTask(new Continuation<Void, Task<Route>>() {
@Override
public Task<Route> then(Task<Void> task) throws Exception {
Log.e("MainActivity", "Connected");
board.readDeviceInformationAsync()
.continueWith((Continuation<DeviceInformation, Void>) task1 -> {
Log.e("MainActivity", "Device Information: " + task1.getResult());
manufacturerValue.setText(task1.getResult().manufacturer);
modelNumberValue.setText(task1.getResult().modelNumber);
serialNumberValue.setText(task1.getResult().serialNumber);
firmwareRevisionValue.setText(task1.getResult().firmwareRevision);
hardwareRevisionValue.setText(task1.getResult().hardwareRevision);
deviceMacAddressValue.setText(board.getMacAddress());
return null;
}, Task.UI_THREAD_EXECUTOR);
accBmi160 = board.getModule(AccelerometerBmi160.class);
accBmi160.stepDetector().configure()
.mode(AccelerometerBmi160.StepDetectorMode.NORMAL)
.commit();
return accBmi160.stepDetector().addRouteAsync(new RouteBuilder() {
@Override
public void configure(RouteComponent source) {
source.stream(new Subscriber() {
@Override
public void apply(Data data, Object... env) {
step += 1;
handler.post(new Runnable() {
@Override
public void run() {
stepText.setText(String.valueOf(step));
}
});
Log.e("MainActivity", "Took a step");
}
});
}
});
}
}).continueWith(new Continuation<Route, Void>() {
@Override
public Void then(Task<Route> task) throws Exception {
if (task.isFaulted()) {
Log.e("MainActivity", "Task Get failed " + task.getError());
} else {
Log.e("MainActivity", "Task Get Successsss " + task.getResult());
accBmi160.stepDetector().start();
accBmi160.start();
}
return null;
}
});
}
initial Connect is very good. (change Step Text)**
Then, I tried Metawear Batt to fook off
Then. I insert to Batt in Metawear Again. BMI160 Step detector not working ,couldn't changed step text & not working metawwear
This discussion has been closed.
Comments
Reconnect code
setup Metod
initial log like this (blow) Step Detector was work
After Reconnect, the Step Detector is not work Log Like this,
I'd like to operate step detector again after reconnect. How to do that? and fix?
Since you are basing your code on the sample app, follow how that code base handles a reconnect:
https://github.com/mbientlab/MetaWear-SampleApp-Android/blob/master/app/src/main/java/com/mbientlab/metawear/app/HomeFragment.java#L147