Temperature show error

When this happens the temperature only shows the number 2 withouth updating or showing the real data, I've tested all the formats that are commented and none of them works, someone knows how to fix this? 
protected void boardReady(MetaWearBoard mwBoard, TextView current_temp) throws com.mbientlab.metawear.UnsupportedModuleException
{
this.mwBoard = mwBoard;
tempModule= this.mwBoard.getModuleOrThrow(Temperature.class);
timerModule = this.mwBoard.getModuleOrThrow(Timer.class);
Temperature.Sensor tempsensor = tempModule.sensors()[0];
tempsensor.addRouteAsync(source -> source.stream((data, env) -> {
//current_temp.setText(String.format(Locale.US,"%.1fº",data.value(Float.class)));
current_temp.setText((data.value(Float.class).toString()));
//current_temp.setText(String.format(Locale.US, "%d", data.value(Float.class)));
//TemperaturaReader.this.current_temp.setText("Temperature (C) = " + data.value(Float.class).toString());
}
)).continueWithTask(task -> {
streamRoute = task.getResult();

return timerModule.scheduleAsync(TEMP_SAMPLE_PERIOD, false, tempsensor::read);
}).continueWithTask(task -> {
if(task.isFaulted()) {
Log.e("boardReady", task.getError().getMessage());
}
scheduledTask = task.getResult();
scheduledTask.start();

return null;
});
}

Comments

    • Is the text view large enough to display the entire string?
    • What are the actual values captured by the data variable?
  • Yes, the text view is large enough as it shows completly data now, the data value is the data that he got from the tempsensor.
     the problem is that never updates, the data never updates so it gets in the same number all the time even if I change the temp. on the sensor
  • What I am asking is for the actual values, i.e. numbers that data.value(Float.class) returns.  Are you receiving reasonable values?
  • Yes I am, I'm recieving the actual temperature so they are like the data I was recieving correctly before it failed, but then It has to update and it doesn't work.
  • Actually, now that I think about it, the issue could be simply that you aren't running the code on the UI thread.
  • edited March 2017
    I am, but for some reason the variable data.value doesnt work since I updated the API, any reason?
    public void temp()

    {
    getActivity().runOnUiThread(new Runnable() {
    @Override
    public void run() {

    current_temp.setText(data.value(Float.class).toString());
    }
    });
    }
  • Nevermind, I just solved it, just an error invoking one fragment from another with this. Thanks Eric
This discussion has been closed.