2
votes

I am having trouble developing android software for my BLE device. My software can find my devices and GATT service, but couldn't find any characteristic in my services.

I checked android-sdk-4.4.2 source,and found some code. https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-sdk-4.4.2_r1 https://android.googlesource.com/platform/packages/apps/Bluetooth/+/android-sdk-4.4.2_r1

static char BASE_UUID[16] = {
    0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
    0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

int uuidType(unsigned char* p_uuid)
{
    int i = 0;
    int match = 0;
    int all_zero = 1;

    for(i = 0; i != 16; ++i)
    {
        if (i == 12 || i == 13)
            continue;

        if (p_uuid[i] == BASE_UUID[i])
            ++match;

        if (p_uuid[i] != 0)
            all_zero = 0;
    }
    if (all_zero)
        return 0;
    if (match == 12)
        return LEN_UUID_32;
    if (match == 14)
        return LEN_UUID_16;
    return LEN_UUID_128;
}

My BLE device UUID is 0000XXXX-AABB-1000-8000-00805F9B34FB. Does this code cause this trouble? Or does my BLE devices UUID have some problem?

3

3 Answers

1
votes

This is what you are looking for. It is a callback for gatt.discoverServices(); and returns the UUID for each service and for each service it returns the characteristic UUID.

@Override
    // New services discovered
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            for (BluetoothGattService gattService : gatt.getServices()) {
                for (BluetoothGattCharacteristic mCharacteristic : gattService.getCharacteristics()) {
                    Log.i(TAG, "Found Characteristic: " + mCharacteristic.getUuid().toString());
                }
                Log.i(TAG, "onServicesDiscovered UUID: " + gattService.getUuid().toString());
            }
        } else {
            Log.w(TAG, "onServicesDiscovered received: " + status);
        }
1
votes

Understand the GATT implementation. While I am not from android background and I really can't see what you are doing through the code you have posted, I'll suggest you to try few things in order to get it work. Firstly, just as your device has a unique MAC ID, every service has its UUID, and the characteristics enclosed within a service too have their own UUID.

  • Once connected, read the GATT services that you need.
  • Once you have received the GATT descriptor, you should be able to see the characteristics enclosed within the service, and you should be able to access them by respective IDs or handles. Since I have no experience on android development, I can not tell you what handle, what descriptor, what ID, what data structure would do that for you, but there has to be some.
0
votes

I would expect the UUID be of the form: 0000AABB-0000-1000-8000-00805F9B34FB. Also it would be much easier to use UUID.fromString("your uuid"). If you know the characteristic uuid, inside of the onServicesDiscovered() you may directly enable the char by:

onServicesDiscovered()
{
            BluetoothGattCharacteristic characteristic = gatt.getService(
                    UUID.fromString(SENSOR_SERVICE_UUID)).getCharacteristic(
                    UUID.fromString(CONFIG_UUID
                    ));

            characteristic.setValue(new byte[]{0x01});
            gatt.writeCharacteristic(characteristic);
}