How to get the battery of the bike light

Former Member
Former Member

I see AntPlus.Device has getBatteryStatus(identifier) method in api documentation.

But when I follow the example, I get an error. 

Error: Symbol Not Found Error
Details: Could not find symbol 'getBatteryStatus'

 

I found that the subclass of device has lightnetwork, so i use.

var batteryStatus = mLightNetwork.getBatteryStatus(null);

But batteryStatus always null.

  • For getting battery status from lightNetwork, you cannot just use getBatteryStatus(null). Since there can be multiple lights, you have to use getBikeLights() first and iterate over the array and use the light identifier. Like this:

    var bikeLights = myBikeLights.getBikeLights();
    if (bikeLights != null) {
        for (var i = 0; i < bikeLights.size(); i++) {
            if((bikeLights[i] != null) && (bikeLights[i] instanceof AntPlus.BikeLight)) {
                var batteryStatus = myBikeLights.getBatteryStatus(bikeLights[i].identifier);
                if (batteryStatus != null) {
                    Sys.println("Light status (" + bikeLights[i].identifier + "): " + batteryStatus.batteryStatus + ", " + batteryStatus.batteryVoltage);
                }
            }
        }
    }

    myBikeLights is instance of AntPlus.LightNetwork.

  • I'm trying to post my code but it keeps saying I'm blocked so i'll put it below (sorry for the mess). It;s not all my code, but you should the idea and be able to fill in the blanks regarding variables etc..

    If you only have 1 light then you probably dont need to find the model numbers, but I have 2 ANT+ lights, and I wanted to seperate the battStatus for Headlight vs tailight. So I needed to find the Model number.

    //Light Network and Battery Bar
            // LIGHT_NETWORK_STATE_* NOT_FORMED = 0, FORMING = 1, FORMED = 2
             // BATT_STATUS_NEW = 1, BATT_STATUS_GOOD = 2, BATT_STATUS_OK = 3, BATT_STATUS_LOW = 4, BATT_STATUS_CRITICAL = 5
            if (AntPlus has :LightNetwork){
                eLightlistener = new AntPlus.LightNetworkListener();
                eLight = new AntPlus.LightNetwork(eLightlistener);      
                eLightList = eLight.getBikeLights();
                eLightState = eLight.getNetworkState();    
                if (eLightState == 2 && eLightList != null) {
                     for (var i=0;i<eLightList.size();i++){
                        var eLightId = eLightList[i].identifier;                            
                        var eLightManu = eLight.getManufacturerInfo(eLightId);
                        var eLightProd = eLight.getProductInfo(eLightId);
                        var eLightBatt = eLight.getBatteryStatus(eLightId);
                            if (eLightBatt != null){
    //                            Sys.println("Light_ " + "State:"+ eLightState +" Man#:"+ eLightManu.manufacturerId +" Model:"+ eLightManu.modelNumber +" HW Rev:"+eLightManu.hwRevision+" Serial:"+eLightProd.serial+" Batt:"+eLightBatt.batteryStatus); //Use to identify Model# that referes to Front or Rear Light
                                if (eLightManu.modelNumber == 1){
                                    eTailLightBatt = eLightBatt.batteryStatus;                                    
    //                                Sys.println("TailLight:"+eTailLightBatt);                                    
                                }
                                else if (eLightManu.modelNumber == 4){
                                    eFrontLightBatt = eLightBatt.batteryStatus;
    //                                Sys.println("FrontLight:"+eFrontLightBatt);
                                }
                            }
                    }    
                }
            }

  • About your code, wouldn't it be better to use BikeLight.type to determine the light position, rather that manufacturer model number? It has following enumerations:

    LIGHT_TYPE_HEADLIGHT 0  Headlight light type
    LIGHT_TYPE_TAILLIGHT 2  Taillight light type
    LIGHT_TYPE_SIGNAL_CONFIG 3  Configurable signal light type
    LIGHT_TYPE_SIGNAL_LEFT 4  Left turn signal light type
    LIGHT_TYPE_SIGNAL_RIGHT 5  Right turn signal light type
    LIGHT_TYPE_OTHER 7  Undefined light type

    I'd assume model number is manufacturer specific, and would work only with specific devices from that vendor. 

  • I tired to get BikeLight.type working but couldn't. Gave up and just used the model.

    My method certainly doesn't scale but at present the data field is just for me.

  • Former Member
    0 Former Member over 4 years ago in reply to Kurev

    Thank you for your reply, it is very helpful to me

  • Former Member
    0 Former Member over 4 years ago in reply to eronb

    Thank you for your reply, it is very helpful to me

  • I have Bontrager head/tail lights. In Eclipse I fire up my data field and pair the headlight. I get NETWORK_FORMING status ("1"), but don't see it ever flip over to "FORMED == 2". So my "lightSensor.getBikeLights()" returns NULL and I can't get the battery status. Any tips on what it takes to get the network to form? Thanks!

  • On eclipse any+ sensor do your see the lights listed and are the dot next to them green or grey?