I'm trying to read an unsolicited data stream from my Bluetooth device. The data should appear as a byte array. Unfortunately, the UUID I'm supplying doesn't seem to be the correct one. What could be going wrong?
val stringDeviceUUID = rxBleDevice.bluetoothDevice.uuids[0].toString()
val charUUID = UUID.fromString(stringDeviceUUID)
println("$stringDeviceUUID = $charUUID?")
/* If device if it is not already connected... */
if (rxBleDevice.connectionState != RxBleConnection.RxBleConnectionState.CONNECTED) {
/* Establish connection to device */
device !!.establishConnection(false) ?
.doOnNext {
_ -> Log.d("Device: ", "Connection Established")
} ?
.flatMapSingle {
rxBleConnection -> rxBleConnection.readCharacteristic(charUUID)
} ? .subscribe({
count ->
// count should be in bytes
println("OUTPUT: $count")
}, {
throwable ->
Log.d("Device: ", "$throwable")
})
}
I get the following error:
D/Device:: com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException: Characteristic not found with UUID 00001101-0000-1000-8000-00805f9b34fb
What is wrong with this UUID? This is precisely the UUID I retrieve from the device so why won't it let me communicate?
It can't be seen from your code snippet, but are
rxBleDevice
anddevice
the same RxAndroidBle instance? If not, perhaps replacedevice !!.establishConnection(false)
withrxBleDevice.establishConnection(false)