Skip to content Skip to sidebar Skip to footer

Bluetooth Gatt Uuid

I'm trying to build an android app that uses the BluetoothLE. In tutorials they use a 128bit UUID but I only have the 16 bit UUID. I have to create a new 128 bit UUID using the ser

Solution 1:

I use this:

publicclassBLEUtils {

    publicstaticfinallongBT_UUID_LOWER_BITS=0x800000805F9B34FBl;
    publicstaticfinallongBT_UUID_UPPER_BITS=0x1000l;
    publicstaticfinallongBT_CCCD_SHORT_UUID=0x2902l;
    publicstaticfinalUUIDBT_CCCD_UUID= get16BitBTUUID(BT_CCCD_SHORT_UUID);

    publicstatic UUID get16BitBTUUID(long uuid) {
        returnnewUUID(BT_UUID_UPPER_BITS + (uuid << 32), BT_UUID_LOWER_BITS);
    }
}

Your example looks sane. Is it recognized properly by other devices?

Edit: The reverse operation requested in the comment would be:

publicstaticlonggetShortUuid(UUID uuid){
    long result = uuid.getMostSignificantBits();
    result = result - BT_UUID_UPPER_BITS;
    result = result >> 32;
    return result;
}

I didn't test it though.

Post a Comment for "Bluetooth Gatt Uuid"