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?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With