TimeoutException: Creating a MetaWear timer timed out after 3000ms

I am trying to set up a timer on my MetaMorion R board running in my Android app using version 2.8.0 of the MetaWear Android API. But for some reason I can't successfully schedule a timer task. I keep getting the following message: "TimeoutException: Creating a MetaWear timer timed out after 2000ms"

This is what my code looks like:
       if (mMWBoard1 != null && mMWBoard1.isConnected()) {
try {

gpio = mMWBoard1.getModule(Gpio.class);
Debug debug = mMWBoard1.getModule(Debug.class);
debug.resetDevice();
timer = mMWBoard1.getModule(Timer.class);
timer.removeTimers();
Timer.Task sendCodeBitTask = new Task() {
@Override
public void commands() {...
                    }
};


AsyncOperation<Timer.Controller> taskResult=
timer
.scheduleTask(sendCodeBitTask, 1000, false, (short) 5);

taskResult.onComplete(new AsyncOperation.CompletionHandler<Timer.Controller>() {
@Override
public void success(Timer.Controller result) {
// start executing the task
result.start();
}
@Override
public void failure(Throwable error) {
Log.e(TAG, error.toString());
}
});

} catch (UnsupportedModuleException e) {
Log.e(TAG, e.toString());
}

}

And this is the stack trace:

...
09-07 20:04:20.231 6086-6279/com.example.android.vpt D/BluetoothGatt: onClientConnectionState() - status=8 clientIf=5 device=DC:A8:5D:64:75:63
09-07 20:04:20.276 6086-6279/com.example.android.vpt D/BluetoothGatt: refresh() - device: DC:A8:5D:64:75:63
09-07 20:04:20.281 6086-6279/com.example.android.vpt D/BluetoothGatt: close()
09-07 20:04:20.284 6086-6279/com.example.android.vpt D/BluetoothGatt: unregisterApp() - mClientIf=5
09-07 20:04:27.848 6086-6086/com.example.android.vpt E/MetaWear: java.util.concurrent.TimeoutException: Creating a MetaWear timer timed out after 3000ms

Any ideas?

Comments

  • A bit more information. For some reason my MetaWearBoard object is being disconnected... not sure why and how...
  • Calling reset reboots the board.  It is not meant to be used within a normal app flow, hence being placed in the Debug interface.  
  • Ok, but it still gives me the error even without the reset.

    Do you have any ideas/suggestions for why the board/device is disconnected when I try to set up a timer?
  • Originally it was because you were calling "reset".  Is your board still losing connection after removing that function call?
  • No it's no longer losing connection, but I still get the error...
  • edited September 2017
    How odd.  What is the code inside the commands function?  Does the timeout error consistently happen if you are using a clean board i.e. one that was just powered on or rebooted?  If rebooted, you need to wait for the d/c event and then reconnect before proceeding.
  • This is my commands function: 
    Timer.Task sendCodeBitTask = new Task() {
    @Override
    public void commands() {
    // Set the data bit
    if ( ((code>>bit_no)&0x01) == 1 ) {
    gpio.setDigitalOut(DATA_PIN_1);
    }
    else {
    gpio.clearDigitalOut(DATA_PIN_1);
    }
    // Increment the bit number
    bit_no++;
    // And change the clock signal
    if (clockState) {
    gpio.clearDigitalOut(CLOCK_PIN_0);
    }
    else {
    gpio.setDigitalOut(CLOCK_PIN_0);
    }
    clockState = !clockState;
    }
    };
    I have set a breakpoint in my commands function and one in failure and success of the taskResult.onComplete function. 
    When I power cycle the board ( I have tried it several times) what happens is very consistent. The first breakpoint is hit in the commands function, so I know it get in there, but then it hit's the failure function with the mentioned error (TimeoutException: Creating a MetaWear timer...) 
    If I restart the application I get the same behaviour, so it makes no difference if I power cycle the board or just restart the application. But if I try to call timer.scheduleTask again, (after I get the error), it no longer hits the breakpoint in the commands function.
    I have even tried to remove all code from the commands function, but I still get the error (this time with the small change that it was 5500ms to time out).
    By reboot, do you mean the same as reset? I'm not sure what the D/C event is and how to wait for it...

  • edited September 2017
    Connection state handling is explained in the documentation:

    What other code are you executing in this app?  I assume your app is doing more than just scheduling a task.

    You should also be using API v3 at this point.  v2 is no longer support (last release was 8 months ago) and v3 addresses a lot issues with the v2 API.
This discussion has been closed.