I am unable to retrieve data from my device despite supplying what I believe to be the correct UUID: D/ERROR:: com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException: Characteristic not found with UUID 00001101-0000-1000-8000-00805f9b34fb. What should I do instead?
// Get device from scan
rxBleDevice = scanResult.bleDevice
val deviceUUID = UUID.fromString(scanResult.bleDevice.bluetoothDevice.uuids[0].toString())
// Check device info
println("Name: " + scanResult.bleDevice.name) // Prints to "TestDevice"
println("MAC Address: " + scanResult.bleDevice.macAddress) // Prints to "34:81:F4:3C:2D:7B"
println("UUID = $deviceUUID") // Prints to "00001101-0000-1000-8000-00805f9b34fb"
println("Service UUIDs = " + scanResult.scanRecord.serviceUuids) // Prints to "null"
/* Establish connection to device */
rxBleDevice!!.establishConnection(false) ?
.doOnNext {
_ ->
Log.d("Device: ", "Connection Established")
} ?
.flatMapSingle {
rxBleConnection ->
deviceUUID? .let {
rxBleConnection.readCharacteristic(it)
}
} ? .subscribe({
count ->
// count should be in bytes
println("SUCCESS: $count")
}, {
throwable ->
Log.d("ERROR: ", "$throwable")
})
My expected output is a byte array that reads "datc00099", for example.
The
UUIDyou try to use is fromBluetoothDevice.getUuids()which seems to come from "classic" Bluetooth world.scanResult.scanRecord.serviceUuidsmay also benullbecause theUUIDs are not guaranteed to be advertised. Bear in mind that serviceUUIDand characteristicUUID, while having the same format, identify different attributes.The easiest way to obtain the
UUIDyou are looking for is to ask the peripheral's engineer.Alternatively, if you know what you are searching for, you can connect to your peripheral, commence a service discovery and search through results. Using this lib in
1.9.0version it would look like this:Log options should be:
And in your logs you should see something like:
Characteristic
UUIDs are provided in brackets. You would just need to find the one you are looking for.