How to make sure the sensor is actually working?

Hi, 

One general question first, will the sensors automatically stop sampling or don't execute the data routes after disconnect?

My use case is that after I set up any motion interrupt to trigger axis sampling for few seconds and then log the raw data points onto the board, I disconnect the sensor and reconnect every few minute to download data (if there are some). I applied this configuration to 4 sensors. The problem I am facing is that while some sensors are working properly as I expected, occasionally some sensors won't pick up any activity even if I shake them hard.
The configuration snippet is as below:

accel_module.configureAxisSampling()
.setOutputDataRate(Bmi160Accelerometer.OutputDataRate.ODR_1_5625_HZ)
.enableUndersampling((byte) 4)
.commit();
accel_module.routeData().fromAxes().log(SENSOR_DATA_LOG).commit().onComplete(accelHandler);
timerModule.scheduleTask(new com.mbientlab.metawear.module.Timer.Task() {
@Override
public void commands() {
accel_module.disableAxisSampling();
}
}, 3000, true).onComplete(new AsyncOperation.CompletionHandler<com.mbientlab.metawear.module.Timer.Controller>() {
@Override
public void success(final com.mbientlab.metawear.module.Timer.Controller result) {
accel_module.routeData().fromMotion().monitor(new DataSignal.ActivityHandler() {
@Override
public void onSignalActive(Map<String, DataProcessor> map, DataSignal.DataToken dataToken) {
result.start();
accel_module.enableAxisSampling();
}
}).commit().onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
accel_module.configureAnyMotionDetection().setThreshold(0.032f).commit();
accel_module.enableMotionDetection(Bmi160Accelerometer.MotionType.ANY_MOTION);
accel_module.startLowPower();
}
});
}
});

Is there any method to make sure the any motion detection as well as data route is working properly?

Comments

  • I tried to capture more error messages and this is what I've found:

    W/System.err: java.util.concurrent.TimeoutException: Creating a MetaWear timer timed out after 3000ms
    W/System.err:     at com.mbientlab.metawear.impl.DefaultMetaWearBoard$TimerImpl$1.run(W/System.err:     at android.os.Handler.handleCallback(Handler.java:733)
    W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
    W/System.err:     at android.os.Looper.loop(Looper.java:137)
    W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5082)
    W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
    W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
    W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
    W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
    W/System.err:     at dalvik.system.NativeStart.main(Native Method)
  • This only happens to certain sensors. After I took out and put in the battery to reset the board, the data timer is working now. Are there any ways in SDK that can reset the board?
  • edited April 2016
    Sensors run until they receive their stop command or run out of power.

    It sounds like you are simply tacking on timers and data routes without removing the ones you previously created.  Call removeRoutes and removeTimers to tear everything down before rerunning your code.  You can also issue a reset by calling resetDevice which will reboot the board.
  • @Eric, I have an initialization phase before I configure the sensors. I removed all my data routes, cleared the timers as well as cleared the log entries. 

    I think resetDevice can help me initializing the board. I will try that out.
  • @Eric, a follow-up question: how long will it take for the board to clear its entries if the log module is full? 
  • If you "initialization phase" is running after the app starts up, then the API doesn't have any routes or timers to remove unless you have serialized the state before hand.  The tear down should be happening after you're finished testing and before you close the app.

    I'd wait 10+ seconds before reconnecting after issuing a log clear
  • @Eric, in an extreme case, if the phone restarted while the app is running, will resetDevice and then MetawearBoard.disconnect tear down all the routes as well as timers on board?
  • Have tried that out, seemed like working properly.
  • Oh.. I checked the sensors today... No luck with resetDevice + MetawearBoard.disconnect. Are there any ways other than tearing them down or serializing the board status?
  • In other words, are there ways to 'reset' the device on app start up?
  • You should not be calling disconnect.  It's possible you are cutting the BLE connection before the reset command is send by the radio.  Let the API update the connection status automatically.  

    No, those are the only ways to reset the board through software.
  • @Eric, Thank you. I'll try that out. 
  • I commented out the disconnect and let API handle the connection. Below is my code to 'initialize' the board. I saw that the board disconnected automatically. I think it's the signal indicating the software 'reset' is triggered.

                            Logging logger = board.getModule(Logging.class);
    logger.stopLogging();
    accel_module = board.getModule(Bmi160Accelerometer.class);
    accel_module.disableAxisSampling();
    accel_module.stop();
    Debug debug = board.getModule(Debug.class);
    debug.resetDevice();

    However, a few minutes later when I connect to the sensor and try to configure the timer as well as other data routes, there's still timer timeout error. Previously before I implement the resetDevice method, I can read the routeIDs of my accelerometer data routes (log) and my temperature data routes. After my implementation of resetDevice(), I am not even possible to read the RouteID, indicating that the data routes are not configured properly.

    I cannot figure out what happened to the sensor.
  • edited April 2016
    The board is fine.  However, I can't really think of why you are running into this error.  Can you send me the full flow and relevant code of how you app works so I can try to replicate the issue on my side?

    Are you still testing on your LG Optimus Fuel?  Do you have other Android devices to test with?
  • @Eric, I've sent you my code snippet via email yesterday. Thank you!
  • I also tried to reset the board by pulling out the battery for few minutes. After that, I used the latest Metawear sample Android app to connect to each sensor and reset the sensor. 

    After these operations, I started my application and try to configure the data routes. I still get a timer timeout of 3000 ms. And I am not able to establish temperature route or data route as well.

    Then I reverted my code to exclude all resetDevice and I tried to disconnect after the 'initialization phase'. I could set up the data routes as well as temperature routes. However, I still got that 300ms timeout from the Timer Module.
  • Your code works fine on 3 of our Android devices: Nexus 6 (6.0.1), Samsung Galaxy S4 (5.0.1), and Nexus 7 (4.4.2).  I also tested it by:
    1. Running your code
    2. Issuing the reset command
    3. Reconnect and repeat from step 1
    I suppose first off, can you even create a timer?  If you pare down your code to simply creating the timer, does that piece of code work?
    timerModule.scheduleTask(new com.mbientlab.metawear.module.Timer.Task() {
    @Override
    public void commands() {
    accel_module.disableAxisSampling();
    }
    }, 3000, true).onComplete(new AsyncOperation.CompletionHandler<com.mbientlab.metawear.module.Timer.Controller>() {
    @Override
    public void success(final com.mbientlab.metawear.module.Timer.Controller result) {
    Log.i("test", "Success! timer id = " + result.id()); }

    @Override
    public void failure(Throwable error) {
    error.printStackTrace(); // Often get a timeout error here
    }
    });
    Also, do you have other Android devices to test with? If not, you need to get more models.
  • Previously, I am able to set up the timers on some sensors but not the others. So I can see the Timer route ID "2". And those sensors works well. 

    That's why I asked for methods to "reset" the sensors to make sure I can create timers on all the boards.

    However, after I implemented resetDevice(), the problem got worse and I was not able to even configure the data/temperature routes.

    I'll try to figure out other Android phones to test on.
This discussion has been closed.