Documentation says 'null' is allowed but throws error in VS Code?

I'm just starting with Connect IQ development and have already bumped into an issue I don't understand.

I'm trying to get the battery status of a sensor (at this moment, any sensor). The Garmin docs says:

var batteryStatus = AntPlus.getBatteryStatus(null);  // Get the batteryStatus Enum value
                                                     // for a single component system.

In my code i have:

import Toybox.AntPlus;
...
var myDevice = new AntPlus.BikeSpeed(null);
var batteryStatus = myDevice.getBatteryStatus(null);

However, the second line gives an error:

Invalid 'Null' passed as parameter 1 of type '$.Toybox.Lang.Number'.

I realise that this is definitely a newbie question but I'm finding the whole entry into the SDK a bit baffling.

  •  I myself ran into this bug about 4 yrs ago. My work around was to use a wrapper function.

    I don't recall exactly how I came to this and what else I tried but it works for me.

    YMMV ;)


    function batteryStatus(device) {        // Can't declare device type; bug in getBatteryStatus()
        // Return battery status, check for null
        var battStatus = device.getBatteryStatus(null);
        return (battStatus == null) ? AntPlus.BATT_STATUS_INVALID : battStatus.batteryStatus ;
    }


  • Ah! Thanks for that! I’ll have another crack when I get a chance. Incidentally do you happen to know where the battery status of the HRM sensor can be found? It doesn’t appear to be accessible from the AntPlus class.

    I raised a bug report on another issue wherein I commented on the woeful state of the SDK, the documentation and Garmin’s seeming disregard for user development.

    i got a fairly dismissive reply from another forum user but this sort of thing only backs up what I was saying.

  • I seem to remember the HRM strap is a different Ant subclass than Bikespeed. But I may be wrong.