BleCharacteristicNotFoundException:未使用 UUID 找到特征。如何从蓝牙设备获取特征 UUID?

BleCharacteristicNotFoundException: Characteristic not found with UUID. How can I get the characteristic UUIDs from a Bluetooth device?

尽管提供了我认为正确的内容,但我无法从我的设备中检索数据 UUID: D/ERROR:: com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException: Characteristic not found with UUID 00001101-0000-1000-8000-00805f9b34fb。我应该怎么做?

// 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")
 })

我的预期输出是一个字节数组,例如 "datc00099"。

您尝试使用的UUID来自BluetoothDevice.getUuids(),它似乎来自"classic"蓝牙世界。

scanResult.scanRecord.serviceUuids 也可能是 null,因为不能保证 UUID 被公布。请记住,服务 UUID 和特征 UUID,虽然具有相同的格式,但可以识别 不同的 属性。

最简单的获取方式UUID就是询问外设工程师

或者,如果您知道要搜索什么,您可以连接到您的外围设备,开始服务发现并搜索结果。在 1.9.0 版本中使用此库将如下所示:

rxBleClient.scanBleDevices(
    ScanSettings.Builder()
        .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
        .build(),
    ScanFilter.Builder()
        .setDeviceName("TestDevice")
        .build()
)
    .take(1)
    .flatMap { it.bleDevice.establishConnection(false) }
    .flatMapSingle { it.discoverServices() }
    .take(1)
    .subscribe(
        { t -> t.bluetoothGattServices }, // Print services
        { Log.e("ERROR", "WHOOPS!", it) }
    )

日志选项应该是:

RxBleClient.updateLogOptions(LogOptions.Builder()
        .setLogLevel(LogConstants.VERBOSE)
        .setUuidsLogSetting(LogConstants.UUIDS_FULL)
        .build()

在您的日志中,您应该会看到如下内容:

V/RxBle#ServiceDiscoveryOperation: Preparing services description
V/RxBle#ServiceDiscoveryOperation: --------------- ====== Printing peripheral content ====== ---------------
V/RxBle#ServiceDiscoveryOperation: MAC='XX:XX:XX:XX:XX:XX'
V/RxBle#ServiceDiscoveryOperation: PERIPHERAL NAME: SensorTag
V/RxBle#ServiceDiscoveryOperation: -------------------------------------------------------------------------
V/RxBle#ServiceDiscoveryOperation: Primary Service - Generic Access (00001800-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 1
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Device Name (00002a00-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:  * Appearance (00002a01-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:  * Peripheral Privacy Flag (00002a02-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ WRITE ]
V/RxBle#ServiceDiscoveryOperation:  * Reconnection Address (00002a03-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ WRITE ]
V/RxBle#ServiceDiscoveryOperation:  * Peripheral Preferred Connection Parameters (00002a04-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation: Primary Service - Generic Attribute (00001801-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 12
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Service Changed (00002a05-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ INDICATE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Primary Service - Device Information (0000180a-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 16
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * System ID (00002a23-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:  * Model Number String (00002a24-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:  * Serial Number String (00002a25-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:  * Firmware Revision String (00002a26-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:  * Hardware Revision String (00002a27-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:  * Software Revision String (00002a28-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:  * Manufacturer Name String (00002a29-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:  * IEEE 11073-20601 Regulatory Certification Data List (00002a2a-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:  * PnP ID (00002a50-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation: Primary Service - Unknown service (f000aa00-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 35
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa01-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ NOTIFY ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa02-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Primary Service - Unknown service (f000aa10-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 43
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa11-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ NOTIFY ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa12-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa13-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Primary Service - Unknown service (f000aa20-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 54
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa21-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ NOTIFY ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa22-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Primary Service - Unknown service (f000aa30-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 62
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa31-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ NOTIFY ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa32-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa33-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Primary Service - Unknown service (f000aa40-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 73
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa41-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ NOTIFY ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa42-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa43-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Primary Service - Unknown service (f000aa50-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 85
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa51-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ NOTIFY ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa52-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Primary Service - Unknown service (0000ffe0-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 93
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (0000ffe1-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ NOTIFY ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Primary Service - Unknown service (f000aa60-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 98
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa61-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000aa62-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Primary Service - Unknown service (f000ccc0-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 105
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000ccc1-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ READ NOTIFY ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000ccc2-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000ccc3-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ WRITE ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: Primary Service - Unknown service (f000ffc0-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation: Instance ID: 116
V/RxBle#ServiceDiscoveryOperation: -> Characteristics:
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000ffc1-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ WRITE_NO_RESPONSE WRITE NOTIFY ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:  * Unknown characteristic (f000ffc2-0451-4000-b000-000000000000)
V/RxBle#ServiceDiscoveryOperation:    Properties: [ WRITE_NO_RESPONSE WRITE NOTIFY ]
V/RxBle#ServiceDiscoveryOperation:    -> Descriptors:
V/RxBle#ServiceDiscoveryOperation:      * Client Characteristic Configuration (00002902-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation:      * Characteristic User Description (00002901-0000-1000-8000-00805f9b34fb)
V/RxBle#ServiceDiscoveryOperation: --------------- ====== Finished peripheral content ====== ---------------

特征UUID在括号中提供。您只需要找到您正在寻找的那个。