Battery not reporting on newly-purchased CPRO sensor
I purchased a CPRO sensor late last year (2016) which I built a fully-functioning app for, which included reading the battery at regular intervals to check status.
The battery reading code worked perfectly on that sensor. However, I recently purchased a new sensor (March 2017), and the battery reading code no longer works.
All my other code works fine on both devices -- both devices connect correctly, and I enable the barometer and take pressure readings, which works fine on both old and new devices.
Here is the code that works for the old CPRO, but not the new CPRO. The sensor connects, the settings module is valid (not null), but no "Battery reading " message is logged.
Has something changed recently in the CPRO modules that would cause this code to stop working? I notice that the latest docs do not describe this API, but I would have expected it to still be compatible with the sensor firmware.
------------------------------------
public class App extends Activity implements ServiceConnection {
...
private MetaWearBoard metawear_board;
private void sensor_read_battery() {
if (metawear_board == null) return; // Sensor disconnected.
final Settings settings_module = metawear_board.lookupModule(Settings.class);
if (settings_module == null) return; // settings_module can be null if sensor was disconnected (possibly unintentionally)
settings_module.readBatteryState();
settings_module.routeData().fromBattery().stream("battery_state").commit()
.onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
public void success(RouteManager result) {
result.subscribe("battery_state", new RouteManager.MessageHandler() {
public void process(Message msg) {
log("Battery reading " + String.valueOf(msg.getData(BatteryState.class).charge()));
}
});
}
});
}
This discussion has been closed.
Comments