尝试从BLE血压设备获取数据。文档说每次连接设备时都必须同步日期/时间。 代码:
interactionSub = Observable.concat(
deviceConnection
.writeCharacteristic( ReactiveBluetoothHelpers.DATE_TIME_CHARACTERISTIC_UUID, testDateTime )
.doOnSubscribe(() -> Log.d(TAG, "doOnSubscribe called inside writeCharacteristic!"))
.doOnError(Error -> Log.e(TAG, "doOnError called inside writeCharacteristic. " + Error.getMessage()))
.doOnNext(bytes -> Log.d(TAG, "doOnNext called inside writeCharacteristic."))
.delay( 500L, TimeUnit.MILLISECONDS )
.ignoreElements(),
deviceConnection
.setupIndication( ReactiveBluetoothHelpers.BLOOD_PRESSURE_MEASUREMENT_UUID )
.doOnNext( indicationObservable -> {
Log.d(TAG, "Blood Pressure measurement indication has been set up.");
} )
.flatMap(indicationObservable -> indicationObservable) //
) // end of concat
.subscribe(
this::handleBpMeasurement,
this::handleBpMeasurementError
);
设备连接并订阅,但尝试写入特性会导致错误。 BleDisconnectedException的错误消息只是“与F4断开连接:5E:AB:10:DF:5C”,没有解释。
我无法想象这个错误来自哪里。我正在尝试编写的测试日期/时间具有年份(16位小端)和其他1字节数量的有效值。
典型的日志序列:
12-04 15:47:46.617 16544-16612/com.calderadev.truecareccm.truecareservice D/RxBle#ClientOperationQueue: QUEUED ConnectOperation(13884208)
12-04 15:47:46.618 16544-16571/com.calderadev.truecareccm.truecareservice D/BluetoothGatt: unregisterApp() - mClientIf=8
12-04 15:47:46.621 16544-16565/com.calderadev.truecareccm.truecareservice D/RxBle#ClientOperationQueue: FINISHED DisconnectOperation(252854751)
12-04 15:47:46.624 16544-16565/com.calderadev.truecareccm.truecareservice D/RxBle#ClientOperationQueue: STARTED ConnectOperation(13884208)
12-04 15:47:46.630 16544-16571/com.calderadev.truecareccm.truecareservice D/BluetoothGatt: connect() - device: F4:5E:AB:10:DF:5C, auto: false
12-04 15:47:46.630 16544-16571/com.calderadev.truecareccm.truecareservice D/BluetoothGatt: registerApp()
12-04 15:47:46.630 16544-16571/com.calderadev.truecareccm.truecareservice D/BluetoothGatt: registerApp() - UUID=91617ce4-e91f-4117-acd4-95a1b2acbf29
12-04 15:47:46.633 16544-16575/com.calderadev.truecareccm.truecareservice D/BluetoothGatt: onClientRegistered() - status=0 clientIf=8
12-04 15:47:47.042 16544-16575/com.calderadev.truecareccm.truecareservice D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=8 device=F4:5E:AB:10:DF:5C
12-04 15:47:47.043 16544-16575/com.calderadev.truecareccm.truecareservice D/RxBle#BluetoothGatt: onConnectionStateChange newState=2 status=0
12-04 15:47:47.044 16544-16575/com.calderadev.truecareccm.truecareservice D/BluetoothGatt: onClientConnectionState() - status=62 clientIf=8 device=F4:5E:AB:10:DF:5C
12-04 15:47:47.044 16544-16575/com.calderadev.truecareccm.truecareservice D/RxBle#BluetoothGatt: onConnectionStateChange newState=0 status=62
12-04 15:47:47.045 16544-16575/com.calderadev.truecareccm.truecareservice I/RxBle#ConnectionOperationQueue: Connection operations queue to be terminated (F4:5E:AB:10:DF:5C)
12-04 15:47:47.047 16544-16565/com.calderadev.truecareccm.truecareservice D/RxBle#ClientOperationQueue: FINISHED ConnectOperation(13884208)
12-04 15:47:47.054 16544-16612/com.calderadev.truecareccm.truecareservice D/BPMonitor: We have connected to A&D_UA-651BLE_10DF5C with MAC F4:5E:AB:10:DF:5C
12-04 15:47:47.062 16544-16611/com.calderadev.truecareccm.truecareservice D/RxBle#Executors$RunnableAdapter: Terminated.
12-04 15:47:47.083 16544-16612/com.calderadev.truecareccm.truecareservice D/BPMonitor: doOnSubscribe called inside writeCharacteristic!
12-04 15:47:47.100 16544-16612/com.calderadev.truecareccm.truecareservice E/BPMonitor: doOnError called inside writeCharacteristic. Disconnected from F4:5E:AB:10:DF:5C
12-04 15:47:47.118 16544-16612/com.calderadev.truecareccm.truecareservice D/RxBle#ClientOperationQueue: QUEUED DisconnectOperation(246198672)
12-04 15:47:47.120 16544-16565/com.calderadev.truecareccm.truecareservice D/RxBle#ClientOperationQueue: STARTED DisconnectOperation(246198672)
12-04 15:47:47.121 16544-16571/com.calderadev.truecareccm.truecareservice D/BluetoothManager: getConnectionState()
12-04 15:47:47.121 16544-16571/com.calderadev.truecareccm.truecareservice D/BluetoothManager: getConnectedDevices
12-04 15:47:47.125 16544-16612/com.calderadev.truecareccm.truecareservice D/RxBle#ClientOperationQueue: QUEUED ConnectOperation(589767105)
12-04 15:47:47.125 16544-16571/com.calderadev.truecareccm.truecareservice D/BluetoothGatt: close()
12-04 15:47:47.127 16544-16571/com.calderadev.truecareccm.truecareservice D/BluetoothGatt: unregisterApp() - mClientIf=8
12-04 15:47:47.131 16544-16565/com.calderadev.truecareccm.truecareservice D/RxBle#ClientOperationQueue: FINISHED DisconnectOperation(246198672)
答案 0 :(得分:0)
正如您在日志中看到的,onConnectionStateChange()
的调用status=62
与0x3E
相对应。 Android Sources指向:
#define GATT_CONN_FAIL_ESTABLISH HCI_ERR_CONN_FAILED_ESTABLISHMENT /* 0x03E connection fail to establish */
所以看起来连接并没有在操作系统的较低层建立,尽管它首先被报告为连接:
12-04 15:47:47.043 16544-16575/com.calderadev.truecareccm.truecareservice D/RxBle#BluetoothGatt: onConnectionStateChange newState=2 status=0
12-04 15:47:47.044 16544-16575/com.calderadev.truecareccm.truecareservice D/RxBle#BluetoothGatt: onConnectionStateChange newState=0 status=62