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>() {
            @Override
            public void success(RouteManager result) {
                result.subscribe("battery_state", new RouteManager.MessageHandler() {
                    @Override
                    public void process(Message msg) {
                        log("Battery reading " + String.valueOf(msg.getData(BatteryState.class).charge()));
                    }
                });
            }
        });
}


Tagged:

Comments

  • Does the same behavior occur if you use the readBatteryLevel function from the MetaWearBoard class?
  • readBatteryLevel() works great, thanks! And it's simpler code, which is even better.

    It returns "44" in my case. I assume this is a percentage, the same as .charge() returns above? The docs are particularly uninformative on this point :-S
  • Yes, that is the same value as battery charge from the settings module.
Sign In or Register to comment.