Unable to poll for temperature data

I am having problem poll the temperature data at regular interval. The scheduled task - getResult() is null even though used scheduleAsync to create and set the scheduled task and checked on the tempTask.isFaulted() which is false - so no error. One time temp. value I can retrieve from the metasensor by read() call but can't set the regular interval data retriever.

Do I need to configure anything on the metasensor or am I missing anything? Any insight appreciated. Thanks!

private void retrieveBoard(String macAddr) {

final BluetoothManager btManager=
            (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    final BluetoothDevice remoteDevice=

    // Create a MetaWear board object for the Bluetooth Device
    board= serviceBinder.getMetaWearBoard(remoteDevice);
    board.connectAsync().onSuccessTask(task -> {
            Log.i("mbientlabtest", "Connected to "+macAddr+"...........");
            timer = board.getModule(Timer.class);
            temperature = board.getModule(Temperature.class);
            tempSensor = temperature.findSensors(SensorType.PRESET_THERMISTOR)[0];

            return tempSensor.addRouteAsync(new RouteBuilder() {
                public void configure(RouteComponent source) {
                    source.stream(new Subscriber() {
                        public void apply(Data data, Object... env) {
                            Log.i("mbientlabtest", "Temmperature (C) =" + data.value(Float.class).toString());
    }).continueWith((Continuation<Route, Void>) task -> {
                Log.w("mbientlabtest", "Failed to configure app", task.getError());
                Log.i("mbientlabtest", "App configured");

             //Task<Timer.ScheduledTask> tempTask =  timer.scheduleAsync(1000, false,  tempSensor::read);
            // send a read command to the data producer every 30 seconds, start immediately
            Task<Timer.ScheduledTask> tempTask =  timer.scheduleAsync(1000, false,  new CodeBlock() {
                public void program() {

        Log.i("mbientlabtest", "Returning ******************* isFaulted ="+ tempTask.isFaulted());

        //    tempSensor.read();
        //tempTask2 = timer.lookupScheduledTask((byte)0);
        Log.i("mbientlabtest", "2 Returning ******************* isFaulted ="+tempTask.getResult());
            return null;


  • You are not waiting for scheduleAsync to complete.

  • Any tip as to how I can make sure scheduleAsync is complete? Thx

  • I am getting "Did not received timer id within 1000ms" on the scheduledAsync call. Even though I put task.waitForcompletion() to make sure task is complete. Any ideas on the error - thanks!

  • Ok - had to reset the board to get rid of all these problems

  • waitForcompletion blocks the current thread. In general, you should be using continuations, which is what your other async calls are doing (connectAsync and addRouteAsync).

    I'm confused as to why you decided to not use them for scheduleAsync.

  • I did use scheduleAsync. waitForcompletion I used for debugging to make sure that task was somehow completed. Thanks for your input.

  • That's not what I said. I stated that your code was already handling async tasks with continuations and saw no reason why you would deviate from that when calling scheduleAsync.

Sign In or Register to comment.