Problems pulling the uniqueIdentifier

Former Member
Former Member
In this code snippet below I check if getDeviceSettings returns a variable that includes the uniqueIdentifier. It should work fine on any watch with a connect iq version above 2.4.1 according to the API. On a watch below that version I would expect the uniqueID to evaluate to null.

var deviceSettings = System.getDeviceSettings();
// Check if device supports this.
if (deviceSettings has :uniqueIdentifier) {
uniqueID = (deviceSettings.uniqueIdentifier).toNumber();
}

if (uniqueID == null) {
// Can't get unique ID on device set static ID.
uniqueID = 0xABCD;
}


On a Fenix 5S this works as expected. The version on it is 2.4.1. However on both a Fenix 5 and 5X that are both on 2.4.1 the uniqueID evaluates to null. The only difference is that on the 5 and 5X I upgraded the watch from v2.3.x to 2.4.1 myself. Whereas the 5S came updated with 2.4.1 on delivery.

I don't really know why it is evaluating to null on both watches when the CIQ version is clearly 2.4.1 as reflected by the watche's about pages. There must be something I'm missing. Any help would be appreciated!
  • The documentation for uniqueIdentifier says it's an alphaNumeric string (maybe hex characters?) so the toNumber() you use is likely the problem. It would probably overflow the size of a number even it was all digits. So you want to treat it as a string.

    The example in the doc shows it as a 32 character string.
  • Former Member
    Former Member
    That was it! Thank you for your help. I just converted the string to a char array and then took the values I wanted from that.

    // Get the unique ID.
    var deviceSettings = System.getDeviceSettings();
    // Check if device supports this.
    if (deviceSettings has :uniqueIdentifier) {
    var tempArray = (deviceSettings.uniqueIdentifier).toCharArray();

    // Convert first two chars in array to a number.
    if (tempArray.size() >= 2) {
    uniqueID = (((tempArray[1].toNumber() << 8) & 0xFF00) | ((tempArray[0].toNumber()) & 0x00FF));
    }
    }

    if (uniqueID == null) {
    // Can't get unique ID on device set static ID.
    uniqueID = 0xABCD;
    }
  • I think there's a good chance you'll wind up with a bunch of cases where your uniqueID is 0xABCD or you'll see a bunch of duplicates.

    What is it you want as the result?
  • Former Member
    Former Member
    I'm trying to generate a somewhat unique ID for the ANT device number. The device number is only 16 bits so I was just taking two bytes from the unique ID and using it as that. I'm not permanently storing the ID anywhere. It is really just to protect my application from the possibility of two watches being within range of my ANT slave with duplicate device numbers causing issues.

    Is there any better way you'd recommend generating a semi unique 16 bit number out of the CIQ unique ID?
  • How unique, does it need to be persistent after the app executes, how many at the same time?

    Could the slave assign an ID?
  • Former Member
    Former Member
    No it doesn't need to be persistent but it would be ideal if it was the same each time. There could be any number but realistically not more than 5.

    And no the slave can't in this situation.
  • However on both a Fenix 5 and 5X that are both on 2.4.1 the uniqueID evaluates to null.

    What firmware versions are you using on the 5 and 5X? I just verified with the 5X and beta firmware (9.5x) and it is working fine there.

    Travis