Unique

I need a way for any data field running on a device to be able to generate the same "unique" ID for that device. I know there is a "uniqueIdentifier" method, but that is only unique for a particular app. So 2 different data fields running on that same device will generate two different values.

One way would be to get the serial number for an attached power meter. In my use case, for the fields we create there will always be a power meter. So that would work. The ANT ID isn't visible to CIQ, but this suggests the serial number should be. I get this error. Any ideas? Or if this isn't available to data fields, is there another way? I need to support devices from API 2.4 and up.

  • I think you've been led astray by the poor documentation / example.

    Even though the example suggests calling AntPlus.getProductInfo(null), that's really not going to work. getProductInfo() is an instance method which requires an object (an instance of AntPlus). The reason the code/example as written doesn't work is because AntPlus is a class, not an object. Besides, getProductInfo is a member of AntPlus.Device, not AntPlus.

    This is not the only CIQ example in the docs which has a similar problem:

    - the example really needs an object (class instance), not a class

    - the example is confusingly written as though the function could be called on the class

    - mostly importantly, the example does not really explain how to get an instance of the class

    In your case, I think the idea would be to implement a class which extends BikePowerListener, as per:

    https://developer.garmin.com/connect-iq/api-docs/Toybox/AntPlus/BikePowerListener.html

    https://developer.garmin.com/connect-iq/api-docs/Toybox/AntPlus/BikePower.html

    https://developer.garmin.com/connect-iq/api-docs/Toybox/AntPlus/DeviceListener.html

    https://developer.garmin.com/connect-iq/api-docs/Toybox/AntPlus/Device.html

    I don't have any experience with this myself, so I could be off on some of the details:

    class MyBikePowerListener extends AntPlus.BikePowerListener {
    
        function initialize() {
            BikePowerListener.initialize();
        }
    
        function onProductInfoUpdate(data as AntPlus.ProductInfo) as Void {
            // do something with data.serial
        }
    }
    
    class myView extends WatchUi.View {
        var bikePowerListener;
        function initialize() {
            bikePowerListener = new MyBikePowerListener();
        }
    }

  • Having said all that, I don't think this is the best approach for determining a unique ID for a Garmin device, but it's up to you.

  • Thank you! I'm open to other options, in which multiple data fields can generate a common (but unique to the device or better, to a user who might have an EDGE and a Watch for example) identifier. Each time the device is powered on that same ID is generated. And doesn't require a user setting or an inquiry to the web. I would be ok with getting a unique value from a connected phone since our fields also require a connected smart phone. Any suggestions? 

  • Well, I guess I will point out that, by design, Connect IQ lacks a way to generate such a unique identifier.

    So maybe your ideas of getting the serial number of a connected power meter or getting a value from a connected phone are the best you can do, unless you want your apps to contact an internet server.

    I guess what I really want to say is:

    - there's no foolproof way to do what you're trying to do

    - Garmin doesn't really want you to do what you're trying to do (or at the very least, they will not help you)

    I don't have any better ideas right now.

  • I guess there would be no point knowing the user's id if we're only on the device, much less because he also talks about the user maybe having an edge and a watch as well, so anyway I think he's talking about sending and receiving data between the different apps via a web service.

    Using email address could work, but of course it's more work for the user, as they have to type it in. However if have another argument against using an ID of an ant device: what if two riders have the app, but for some reason my app also connects to your sensor before we start the ride (maybe your sensor is closer when we park the bikes)

  • so anyway I think he's talking about sending and receiving data between the different apps via a web service.

    But he said:

    Each time the device is powered on that same ID is generated. And doesn't require a user setting or an inquiry to the web. I would be ok with getting a unique value from a connected phone since our fields also require a connected smart phone
  • However if have another argument against using an ID of an ant device: what if two riders have the app, but for some reason my app also connects to your sensor before we start the ride (maybe your sensor is closer when we park the bikes)

    I agree. I would've thought this kind of scenario goes without saying.

  • I would be ok with getting a unique value from a connected phone since our fields also require a connected smart phone. Any suggestions? 

    Set up a web server on the phone, have the Garmin device contact the web server, and record the MAC address of the Garmin device?

    Just a half-baked suggestion on my part, not sure if it will work in practice for you.

  • Good idea. But too much work for the thousands of users who use these fields. We currently have a working approach in which we generate a random string and store it on the device and in the FIT file. The first activity save acts as a registration process that links that random string with a particular user, since the service grabs the FIT file from Garmin Connect with the string and user ID. We detect the condition in which the user doesn't have a registered string, and lets them know to do a SAVE to perform the registration. Takes a few seconds. Works great. But every field has to have their own unique registration string, since CIQ apps can't share stored values. As we consider using this auth method for more fields, we hoped to find a way in which all the fields could generate a common string (that is unique for a device or user).

  • We currently have a working approach in which we generate a random string and store it on the device and in the FIT file.

    Given that your random string is also only unique to a specific device and app combination, what is the advantage of generating it yourself instead of using DeviceSettings.uniqueIdentifier?

    One advantage I can see is that your identifier can be reset if such a process is desired. It would also reset automatically if the user uninstalls and reinstalls the app. I am not sure how the Garmin identifier behaves in that situation. It probably depends on whether the app component of the identifier is based on the app store ID or the local ID assigned after installation (e.g. the one used in the log file name).