Unable to Stream and Log Temperature
Hello Mbientlab,
I have been trying to stream and log Temperature data from a MetaMotion C board using the BOSCH env sensor on the device. However, no matter where I adjust the code placement for board.getModule(BarometerBosch.class).start();
, I can't seem to get the temperature sensor to stream data continuously.
Currently it only streams a single temperature data point each time I start and then stop streaming.
I am attaching a minimum working example of the code below, and would really appreciate your assistance on this.
Also, I would also appreciate it if the API Reference for Android could be up again as it is currently down.
Thank you so much for your help and I look forward to your reply!
public class DataSensorFusionActivityExample extends AppCompatActivity implements ServiceConnection{
public static final String METAWEAR_DEVICE_KEY = "MetaWearDeviceKey";
private MetaWearBoard board;
private BluetoothDevice btDevice;
private static float temperatureData;
private Temperature temperature;
private static Subscriber temperatureStreamSubscriber = new Subscriber() {
private static final long serialVersionUID = 5789372887305000501L;
@Override
public void apply(Data data, Object... env) {
Log.i("DataSensorFusion", "Temperature = " + data.value(Float.class));
temperatureData = data.value(Float.class);
}
};
public void startStreamingOnClick(View v) {
try {
board.getModule(BarometerBosch.class).start();
Temperature.Sensor tempSensor = temperature.findSensors(Temperature.SensorType.BOSCH_ENV)[0];
tempSensor.addRouteAsync(new RouteBuilder() {
@Override
public void configure(RouteComponent source) {
source.stream(temperatureStreamSubscriber);
}
}).continueWith(new Continuation<Route, Void>() {
@Override
public Void then(Task<Route> task) throws Exception {
// board.getModule(BarometerBosch.class).start();
tempSensor.read();
return null;
}
});
} catch(Exception e) {
Log.e("Start Streaming", "Unexpected Exception while requesting to start streaming sensorfusion data", e);
}
}
public void stopStreamingOnClick(View v) {
board.getModule(BarometerBosch.class).stop();
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
board = ((BtleService.LocalBinder) service).getMetaWearBoard(btDevice);
sensorFusion = board.getModule(SensorFusionBosch.class);
temperature = board.getModule(Temperature.class);
// board.getModule(BarometerBosch.class).start();
// temperature.findSensors(Temperature.SensorType.BOSCH_ENV)[0].read();
}
}
This discussion has been closed.
Comments
Refer to the code from the sample app:
https://github.com/mbientlab/MetaWear-SampleApp-Android/blob/master/app/src/main/java/com/mbientlab/metawear/app/TemperatureFragment.java#L228
Documentation is back up on the site.