0
votes

I am having some difficulties with Bluetooth Low Energy on Android. I have closely done the guide I linked, as well as checked the full example code. I have a BLE device I need to connect to and retrieve data frames from. The documentation at one point dictates to

Discover/Enable service: Service UUID UUID1, Characteristic UUID UUID2

Once this has been executed correctly, the device should start streaming frames of 20 bytes formatted in a particular way.

Searching for the device, connecting to it and discovering services on it I have no problem with. But then I'm stuck. To get the services, BluetoothGatt's method getServices() is called. This returns a list of BluetoothGattService's, which on their part also contain a list of BluetoothGattCharacteristic's. Obviously the BluetoothGattService's UUID must be equal to provided UUID1, and BluetoothGattCharacteristic's UUID to UUID2. But I do not know how to 'enable' this service with certain characteristic.

My documentation also does not mention descriptors. I have checked and there is only one descriptor in the UUID2 characteristic. So now I have everything one could possibly need - Service UUID, Characteristic UUID and Descriptor... But how do I read the data?

1

1 Answers

1
votes

You can iterate over all found characteristics and get the BluetoothGattCharacteristic object with UUID1 and UUID2. Use "UUID.fromString()" to convert a string representing the UUID to a UUID object, which than can be used with ".equals" to compare with "characteristic.getUuid()".

If I've understood you correctly, you want to read some data of a characteristic. When you call "connectGatt" on your BluetoothDevice, you get an object of type "BluetoothGatt". Use this gatt object after discovering the service and characteristics to call "readCharacteristic()" on it, passing the desired BluetoothCharacteristic as argument.

I hope I could help and let me know if I should clarify my answer

Linard