ANT+ battery status

Hi

I am having problems getting the batteryStatus from different ANT+ devices.

In my datatfield I have implemented all possible ANT+ devices including listeners.

Except for one power device I do not get any battery status on all other ant+ devices. As far as I know all other values work correctly.

Code looks like this:

if(lstBikeSpeed == null) {
    lstBikeSpeed = new MyBikeSpeedListener();
	devBikeSpeed = new AntPlus.BikeSpeed(lstBikeSpeed);
}
...
status = lstBikeSpeed.GetBattery();

...

class MyBikeSpeedListener extends AntPlus.BikeSpeedListener {
	function initialize() {
		BikeSpeedListener.initialize();
	}
	var mBat  = null;
	function onBatteryStatusUpdate(data) {
		mBat = data;
	}
	function GetBattery() {
		if(mBat != null && mBat.batteryVoltage != null) { 
			return mBat.batteryVoltage; 
		} else { 
			return 0; 
		}
	}
...

I also tried this line before the GetBattery, to update the mBat directly:

lstBikeSpeed.mBat = devBikeSpeed.getBatteryStatus(null);

It works only on one power device. Is there anything I should change or do I just dont get the values from the SDK??

thanks

regards

Erich

  • For Speed sensors, battery status (page 82) is optional, so it may be that those devices are simply not sending the info.

    If you go to see details of these sensors on your Garmin device under sensors menu, do you see battery information there?

    One last thing to try, if the sensor is not broadcasting battery info, reading the page 82 directly with sendPageRequest() might work (if available at all). 

  • Hi

    Thanks for the info, I will try the page 82 request.

    I will tell you if it worked...

    regards

    Erich

  • Here is the code I tried:

    if(lstBikeSpeed == null) {
    	lstBikeSpeed = new MyBikeSpeedListener();
    	devBikeSpeed = new AntPlus.BikeSpeed(lstBikeSpeed);
    }
    
    status = lstBikeSpeed.GetBattery(devBikeSpeed));
    
    ...
    
    class MyBikeSpeedListener extends AntPlus.BikeSpeedListener {
    	function initialize() {
    		BikeSpeedListener.initialize();
    	}
    	
        var mBat = null;
    	var iCnt = 0;
    	function GetBattery(dev) {
    		if(iCnt == 0) {
    			if(dev has :sendPageRequest) {
    				var payload = dev.sendPageRequest(82);
    				if(payload != null) { 
    					mBat = (payload[7] & 0x70) >> 4;
    				}
    			} else {
    				return 0;
    			}
    		}
    		iCnt++;
    		if(iCnt >= 5) {
    			iCnt = 0;
    		}
    		if(mBat != null) { 
    			return mBat; 
    		} else { 
    			return 0; 
    		}
    	}

    But I get an invalid value error in the simulator in the line of the sendPageRequest (dev is not null, i checked!)

    Is it possible that it works in "real" life ?

    Because I dont have any ANT+ device to test.

    Or did I miss anything here?

    EDIT: I missed the part where the message from the ant device is returned in the onMessage.

    But I still get the invalid value error for the onPageRequest.

    if(lstBikeSpeed == null) {
    	lstBikeSpeed = new MyBikeSpeedListener();
    	devBikeSpeed = new AntPlus.BikeSpeed(lstBikeSpeed);
    }
    
    lstBikeSpeed.CheckSendReq(devBikeSpeed); 
    status = lstBikeSpeed.GetBattery();
    
    ...
    
        var mBat = null;
    	var iCnt = 0;
    	function CheckSendReq(dev) {
    		if(dev == null) {
    			return;
    		}
    		if(iCnt == 5) {
    			if(dev has :sendPageRequest) {
    				$.L("Send 82");
    				dev.sendPageRequest(82);
    			}
    		}
    		iCnt++;
    		if(iCnt >= 30) {
    			iCnt = 0;
    		}
    	}
    	
    	function GetBattery() {
    		if(mBat != null) { 
    			return mBat; 
    		} else { 
    			return 0; 
    		}
    	}
    	
    	function onMessage(msg) {
    		var payload = msg.getPayload();
    		if(payload != null && payload.size() > 7 && payload[0] == 0x52) {
    			mBat = (payload[7] & 0x70) >> 4;
    		}
    	}

  • I hadn't actually tried using sendPageRequest() myself, so it was 'blind' suggestion. I just tried it on simulator, and Edge 530 device too, I also get "invalid Value" app crash. I didn't have the sensor connected at the time, I'll try at some point if the function works when there is something connected state. Documentation says valid range is 0-255, with the exception of page 0x43. So 82 (0x52) should be fine. 

    In general, it is difficult to test all this Ant stuff on simulator. By default, basically all functions return null when used, and listener callbacks are not called. I haven't tried, but you can also have Ant+ dongle connected on computer, and then you should be able to test on simulator too. But even in that case, you need some sensor or device you want to connect to. To my knowledge, there is no way to simulate connected Ant+ device.

  • Hi

    I ordered a USB ANT stick, so I will try it myself in the simulator. I will post the results when I am finished...

    I got a speed cadence sensor, so at least I can try this device type. Hopefully the other device types work similar.

    regards

    Erich

  • Ok,  I got my ANT stick and connected a speed cadence sensor to it. I am getting data in the onMessage.

    BUT, when I try to send the page 82 request I get an exception:

    Error: Unhandled Exception
    Exception: The ANT+ profile doesn't support sending page requests.

    Does it mean, that this specific ANT+ device does not support such message, or is this a general problem?

    So, I would have just to make a try catch around it, and thats it ?? Any ant devices which support this will send me 

    the correct data ?

    thanks

    regards

    Erich

  • I have only a basic experience  with CIQ and ANT, but it seems in the case of something like an HR monitor, if it's paired as a standard sensor, you can't access it with ANT calls at the same time.  Sounds like that's what you're trying to do here.

    Seems ANT+ has a way to get the battery level, but not all sensors support returning the battery level.

  • Hi

    Thanks for you help. Yes, it seems that some device to not support sending the request. The strange thing is, that I got a 0x52 a few times in the onMessage, so the data is getting sent, but very rarely and not predictable.

    I will play around a little more, maybe I find some more info..

    HRM Run is not found in the simulator, hmm but I think it is a ant+ device I think...

    regards

    Erich

  • You may find some things don't send message that often.  The Tempe is an example where the temperature only updates every minute.

  • I can test Generic ANT devices from Windows in the Simulator using a USB ANT dongle. Works great with my TEMPE sensor. I assume ANT+ should also work just fine. I am also trying sendPageRequest(0x52) for an ANT+ sensor in the sim and I'm getting an Invalid Value. Makes no sense.