BleCharacteristicNotFoundException: характеристика не найдена с UUID.Как я могу получить характерные UUID с устройства Bluetooth? - PullRequest
0 голосов
/ 28 марта 2019

Я не могу получить данные с моего устройства, несмотря на то, что я предоставляю то, что я считаю правильным 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».

1 Ответ

1 голос
/ 28 марта 2019

UUID, который вы пытаетесь использовать, относится к BluetoothDevice.getUuids(), который, кажется, происходит из "классического" мира Bluetooth.

scanResult.scanRecord.serviceUuids также может быть null, поскольку UUID s негарантированно будет рекламироваться.Помните, что служба 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 в скобках.Вам просто нужно найти тот, который вы ищете.

...