Newbie cannot read body battery on 245.

Former Member
Former Member

I'm trying to create a watch face which displays body battery. Even copying the code from the documented examples does not work. Any advice on what I'm doing wrong?

Watch: Forerunner 245, latest firmware update

App: Simple watch face

Minimum API supported: 3.3

Notes:

I've included "import Toybox.SensorHistory;" at the top of the code
Code runs until the following snippet is added / called

Code snippet:

    // Create a method to get the SensorHistoryIterator object
    function getIterator() {
        // Check device for SensorHistory compatibility
        if ((Toybox has :SensorHistory) and (Toybox.SensorHistory has :getBodyBatteryHistory)) {
            // Set up the method with parameters
            return Toybox.SensorHistory.getBodyBatteryHistory({});
        }
        return null;
    }

    // Used to draw body battery ring
    // maths excessive for initilisation but function will be rarely called for that fuction
    // low frequency call so memory saving better than power saving
    private function bodyBattery (dc as Dc) as Number {
        var bbIterator = getIterator(); // get the body battery iterator object
        var sample = bbIterator.next(); // get the body battery data

        if (sample != null) {
            var currentValue = (sample.data / 10).toNumber() * 10; // we only want to display a granularity of 10%
        }
    }