How to make sure the sensor is actually working?


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:

.enableUndersampling((byte) 4)
timerModule.scheduleTask(new com.mbientlab.metawear.module.Timer.Task() {
public void commands() {
}, 3000, true).onComplete(new AsyncOperation.CompletionHandler<com.mbientlab.metawear.module.Timer.Controller>() {
public void success(final com.mbientlab.metawear.module.Timer.Controller result) {
accel_module.routeData().fromMotion().monitor(new DataSignal.ActivityHandler() {
public void onSignalActive(Map<String, DataProcessor> map, DataSignal.DataToken dataToken) {
}).commit().onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
public void success(RouteManager result) {

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


  • 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$     at android.os.Handler.handleCallback(
    W/System.err:     at android.os.Handler.dispatchMessage(
    W/System.err:     at android.os.Looper.loop(
    W/System.err:     at
    W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
    W/System.err:     at java.lang.reflect.Method.invoke(
    W/System.err:     at$
    W/System.err:     at
    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);
    accel_module = board.getModule(Bmi160Accelerometer.class);
    Debug debug = board.getModule(Debug.class);

    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() {
    public void commands() {
    }, 3000, true).onComplete(new AsyncOperation.CompletionHandler<com.mbientlab.metawear.module.Timer.Controller>() {
    public void success(final com.mbientlab.metawear.module.Timer.Controller result) {
    Log.i("test", "Success! timer id = " +; }

    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.