java.util.concurrent.TimeoutException: Did not received timer id within 1000ms

Hello!

Board: MetaMotion C
Firmware: 1.3.6
Android Compile SDK:  23
SDK: 3.2.2

I'm attempting to use the Timer to record the temperature and battery settings every 100 ms.  I'm receiving a java.util.concurrent.TimeoutException with the message "Creating timer timed out".

Interestingly enough, the scheduleAsync call seems to succeed since the subscribers for both streams receive data.  However, I don't have access to the Timer.ScheduledTask object (or its id) which I need to stop the task properly.

My code for invoking scheduleAsync is:

board.getModule(Timer.class)
.scheduleAsync(period, true, callback)
.continueWithTask(timerTask -> {
Timer.ScheduledTask scheduledTask = timerTask.getResult();

if (scheduledTask == null) {
if (timerTask.getError() != null) {
Log.w(sensorStreamName, "Error in timer task result: " + timerTask.getError());
...




The callback passed for Temperature is:

Temperature temperature = board.getModule(Temperature.class);

Temperature.Sensor[] sensors = temperature.findSensors(Temperature.SensorType.BOSCH_ENV);

if (sensors.length != 1 || sensors[0] == null) {
Log.w("UploadActivity", "Unable to find Bosch temperature sensor!!!");
return;
}

this.temperatureSensor = sensors[0];
...
callback = () -> this.temperatureSensor.read();




The callback passed for battery is:

Settings settings = board.getModule(Settings.class);
...
callback = () -> settings.battery().read();

Any thoughts on how to proceed?  I can do something hacky like invoke Timer.lookupScheduledTask for all 256 possible values of a byte to find my scheduled tasks.

Also, do the timer tasks stop by default when we call disconnectAsync on the board?

Thanks for any help!

Comments

  • Did you ever remove the previously created timers or are you continually scheduling new tasks?  It sounds like you are scheduling tasks but never removing them.

    The ScheduledTask interface has an id method

    You don't need to use lookupScheduledTask unless you need to access the object from another activity or if you need to rebuild your app state.
  • edited February 2018
    Ah, just to clarify, are "timers" and "scheduled tasks" the same in your first question?

    I only attempt to schedule each task once in my app.  I never remove the scheduled task because I never received a reference to a valid ScheduledTask object (which I need in order to remove the task).

    Do timers persist over disconnects to the device?  E.g. is it possible that a timer is running from the last time my app was connected?
  • They are not the same thing but for the purposes of this conversation, they are interchangeable.

    You receive one if the task is successful, which, it sounds like it was at some point if you are getting periodic reads.  However, since you never removed your previously scheduled tasks, they continue to exist on your device and eventually, there are no more resources available to schedule a new task.

    As stated in the docs, you need to release the allocated resources once you are done using them.
  • Ah, excellent!  This resolved the timer creation issue.  Do you accept pull requests to the Android SDK GitHub project?  I'd like to add documentation if possible.

    I have another question regarding cleanup of routes though but I'll ask this in a separate thread.
  • You will need to sign a contributor license agreement before we can accept pull requests.  Email "hello at mbientlab dot com" with your GitHub username to request the agreement.  That said, the documentation is internally maintained so you can just post criticisms on the forums if you'd prefer.
This discussion has been closed.