com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException:找不到带有UUID的特征 [英] com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException: Characteristic not found with UUID
问题描述
我正在尝试从我的蓝牙设备读取未经请求的数据流.数据应显示为字节数组.不幸的是,我提供的UUID似乎不正确.可能出什么问题了?
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")
})
}
我收到以下错误:
D/Device:: com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException: Characteristic not found with UUID 00001101-0000-1000-8000-00805f9b34fb
此UUID有什么问题?正是我从设备中检索到的UUID,为什么它不让我进行交流?
What is wrong with this UUID? This is precisely the UUID I retrieve from the device so why won't it let me communicate?
推荐答案
从您的代码段中看不到它,但是rxBleDevice
和device
是相同的RxAndroidBle实例吗?如果不是,也许用rxBleDevice.establishConnection(false)
It can't be seen from your code snippet, but are rxBleDevice
and device
the same RxAndroidBle instance? If not, perhaps replace device !!.establishConnection(false)
with rxBleDevice.establishConnection(false)
这篇关于com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException:找不到带有UUID的特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!