Simultaneous use of Sensor and AntPlus APIs.

For my Watch App need to use the AntPlus API to access the power meter so I can access the deviceID. 
I also want to be able to read Heartrate data.

Despite Heartrate being used as an example in the CIQ api docs, there isn't actually an AntPlus listener for Heart Rate devices.

So I need to use the Sensor API for the heartrate data.

However when I do this EITHER the bike power OR the heart rate data are displayed, but never both at the same time.  Seems a bit random.  For example, to debug I put in some Sys.println calls in my initialisation routines, but this resulted in the heartrate showing, but the bike power not showing.

The behavior is also different in the emulator to the actual device - bike power might show in the emulator but not heart rate, but the reverse on the device.

I imagine there is some race condition going on explaining the random behavior, but fundamentally is there a reason why Sensor and AntPlus APIs cannot be used simultaneously?

Is there another way around this? 

Why is there not AntPlus listener for heartrate monitors?  Seems like a bit of a weird omission.

Thanks!! 

  • How are you trying to generate data in the sim?  Simulation>Activity Data? If you are playing back a fit file, does it have the data you are looking for?

    The 7.2.1 seems to have an issue with data simulation, so you may want to stick with playing back a fit file.

  • Hey Jim.  thanks for the quick response.
    I am connecting my devices as ANT+ sensors (In CIQ simulator: Settings->Manage Ant+ sensors)

    Either way though, the issue is present on my physical device (Garmin 830) - I cannot simultaneously get data from Sensor and AntPlus libraries.

  • So after further experimentation it seems like using Sensor API is stopping AntPlus events from firing properly both in the simulator (using ANT+ sensors rather than FIT file playback) and Edge830.

    I have a bikepower listener as follows:

    class antplus_bpwr_listener extends AntPlus.BikePowerListener
    {
    	hidden var m_sensor;
    	function initialize(sensor)
    	{
    		m_sensor = sensor;
    		BikePowerListener.initialize();
    	}
    	
    	function onMessage(msg)
    	{
    	 	if (msg.messageId == 0x4E)
    		{
    			logging.log("0x4E from device number " + msg.deviceNumber);
    		}
    	}
    
        function onCalculatedPowerUpdate(data) {
            logging.log("Recieved power value = " + data.power);
    		m_sensor.addData(data.power);
        }
    }

    The "OnCalculatedPowerUpdate" event fires fine until I enable sensor events, i.e. as soon as I call this:

    Sensor.enableSensorEvents(method(:onSensor));

    it stops working.

    Weirdly the "onMessage" event still fires, so I can see a broadcast message coming from my bikepower sensor, but the data is not there.  I have tried removing bikepower from the list of enabled sensors, but that generally causes the bike power sensor to disconnect.


    So it seems like unless I write my own decoder for the bikepower ANT messages I'm a bit stuck.

    I appreciate its a bit of an odd combination of requirements, but it is very limiting.  Is this a bug?
    I'm using SDK 7.1.0

  • One more thing - part of my troubles stem from the fact that Sensor.speed doesn't necessarily come from the ANT+ speed sensor, so if I am testing indoors, with a simulated ANT+ speed sensor the sensorInfo.speed value is not reported at all (it is null).  
    So in short I need to:

    • Use Sensor.sensorInfo for speed and heartrate data.
    • Use AntPlus to report the power meter and speed sensor deviceId.
    • Manually decode the ANT messages in the AntPlus.BikeSpeedListener onMessage event (since onBikeSpeedUpdate doesn't fire).

    If anyone knows of a better way to achieve this I'm all ears!  

  • Since when the manage ant sensors menu works? Last time I checked everyone wrote that it never worked

  • It works, just not very well.  I rely heavily on it because of my application. 
    Trouble is that when you open it nothing happens - it takes a long time to find devices.  
    For me the best way is to stop the debugger executing, leaving the CIQ simulator window open (but no longer showing your UI), then try.  That way it picks up the ANT+ sensors in a few seeconds.  You can then restart your code and it will be able to see the ANT+ data.
    Whilst my code is executing it can take 2-3 minutes which is frustrating.

  • Since when the manage ant sensors menu works?

    For me, it works flawlessly.
    I build the datafield (for Edge devices) and once it is shown in the sim, I often have to connect Varia radar for testing purpose. Finds radar and light within seconds, then pair and it works. (that’s since 4.2. I‘m now on 7.2.1)

  • I think it depends what else you are doing - I suspect I struggle because I am using ANT Generic channel as well which seems to slow the simulator ANT search down way more than it should.

  • My ebike Specialized Levo connects via ANT generic channel immediately, too (without using „Manage ANT sensors“), and in addition no problem to connect Varia radar. And moreover the ANT connection window of the sim shows my ebike as power and speedsensor (what I do not connect for replaying a fitfile).

  • Aaaahhhhh! It works! It NEVER worked for me, but now I understand why. It is not intended for what I need. In fact it works exactly as the real watch in the following way:

    each ANT device is either paired to the watch / paired in ANT+ Sensors manager

    OR

    is detectable with GenericChannel

    This is why it never worked for me, because I always Run my app and that opens the simulator window, where I tried to do something with the ANT manager, but it was always too late, because by that time my app connected to it.

    BUT this will be now useful for something I wanted to do for a long time: see a good way to determine (and display) the source of the ActivityInfo.currentHeartRate