Search code examples
bluetooth-lowenergygattcharacteristicsrxandroidble

RxAndroidBle: Reading Pre-Defined GATT Characteristics


I have a BLE device with multiple characteristics addressed by default addresses as defined here

Things like Manufacturer Name String, Hardware Revision String, Serial Number String etc.

Using the UUID class I've attempted several different ways to construct a UUID that RxAndroidBle would accept and read from these characteristics.

The one I though would work most was this:

UUID GATT_DSR1_MANUFACTURER_NAME = new UUID(0L, 0x2A29L);

but I just get back onError callbacks.

RxBleConnection.readCharacteristic only accepts UUID or a BluetoothGattCharacteristic which is created with a UUID...


Solution

  • Creating UUIDs (copied from How to correctly use UUID.fromString method? )

    In the BLE specification there are two kinds of UUIDs.

    • Fully qualified 128 bits long which are usually assigned for a specific vendor of the BLE device for non-standard functionality: UUID.fromString("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
    • Also fully qualified (but defined by standard) UUIDs which have the same prefix and postfix: UUID.fromString("F000xxxx-0451-4000-B000-000000000000"); UUID.fromString("0000xxxx-0000-1000-8000-00805f9b34fb") where xxxx is the place to fill the four characters you get from the SensorTag Bluetooth Core specification. For convenience the standard UUIDs are usually referenced with the four characters identifier.

    Your 0x2A29L stands for "2A29" String as the xxxx.

    Obtaining BluetoothGattCharacteristic

    On Android there is no possibility to create a working BluetoothGattCharacteristic with a UUID. It is still possible to call RxBleConnection.discoverServices() and get it from the result though.