How to use sensor.delegate class? Where can i find examples?

Garmin's System8 announcement includes:

"Sensor Pairing

If your device application or data field communicates wirelessly with a sensor or peripheral using ANT, ANT plus, or Bluetooth Low Energy (BLE), then you will need to implement a pairing process. Connect IQ allows you to implement a Sensors.SensorDelegate that allows you to have your device pair as part of the device’s sensor paring UI flow. See the Sensors.SensorDelegate class in the API docs for details."

Is there any further information on this? The API docs are short... - i would like to see an example how to program a sensor delegate.

  • Not really. But you could test it in the simulator (I haven't tested it but you can pair and ANT sensor if you have an USB ANT dongle)

  • Is there any further information on this?

    There is now a Core Topic on this subject which describes the intended use case and the typical user experience:

    https://developer.garmin.com/connect-iq/core-topics/pairing-wireless-devices/

    Interestingly the docs say this:

    Testing in the Simulator

    If you’d like to test your pairing code in the Connect IQ simulator, use the Settings > Manage Sensors option.

    In Windows, when I select Manage Sensors it just shows me a blank dialog haha. Maybe because I don't have an ANT+ stick? But this stuff is also supposed to work with BLE (no idea if it would work in the sim with BLE though). EDIT: I have reason to believe it would work with BLE since it crashes on Mac when I try to use it, and it seems similar to another BLE-related Mac crash. Plus the dialog has a "type" column which implies support for multiple sensor types (ANT, ANT+, BLE?)

    in Mac the dialog looks normal but it crashes if I press Add.

    i would like to see an example how to program a sensor delegate.

    The 8.1.0 SDK has an example in the NordicThingy52 sample app.

  • To use BLE in the sim, you need the nRF52 DK or nRF52840 dongle and a specific hex file flashed to it.  As far as a mac, if you try to use BLE without the needed HW, it will crash,  Heard that from a friend the other day.  He got the dongle and no crash.

  • The 8.1.0 SDK has an example in the NordicThingy52 sample app.

    Thanks for this important hint. That was what i am searching for, but i did not find any hint that it was integrated in this example. Now i have a new task to figure out how this works, and if it's worth a refactoring of my datafield application which connects to a generic external BLE sensor. So far i do the BLE scanning and pairing foo in my datafield. It took me some time to ge this running smooth and stable, but now it is. Let's see which advantage the new sensor.delegate class brings into.

    Would it be possible to bring in a generic speed sensor this way? So that Garmin is using the speed value from this sensor, instead it's calculated speed from onboard GPS?

  • Yes, that's what happens when you pair and connect the speed sensor in the device's settings.

    No, that's not possible to do from CIQ.

  • Also not possible if i program a sensor.delegate for sensor type speed?

  • I have no experience with that (nor any sensor that supports secure mode) but my guess is that it won't change the fact that the sensor is either paired to the "system" and used as native data, or isn't paired to the system and CIQ code can use it, but the system's calculations won't be based on that or the recorded data in the fit file won't be based on that.

    What I do with HR sensor is this: Polar H10 can be paired both using bluetooth and ANT, so I pair and connect to the system via BT and pair in my CIQ datafield via ANT so I get the data as well. But this of course depends on the sensor.

  • Hmm, before i invest time to dive into this new sensor.delegate rabbit hole: what could be the advantage, compared to my datafield which does scanning and pairing without using sensor.delegate class? (as does the old nordicthingy52 example)

  • I've not looked into this at all and still do things the original way.  I'm interested in the secure BLE connection, but I think I only have one sensor that supports that, and for that I'll start with setConnectionStrategy.  In the past, boding didn't work in the sim.

  • Still no bonding in the SIM with SDK 8.1.0.
    That's why i did not start yet to implement secure connection in my app, neither on the sensor. Testing without SIM is too time consuming.