我尝试在给定(自定义)特征上写入 >20 字节的数据。在以下日志中,我尝试写入 85 个字节:
代码:
connectionObservable
.flatMap(rxBleConnection -> rxBleConnection.writeCharacteristic(
wChar.uuid(),
wChar.bytes()))
.observeOn(mainThread())
.subscribe(
bytes -> wChar.success(),
this::onWriteFailure
);
结果:在服务器端(nrf52)我可以看到 EXEC_WRITE 但只发送了前 20B。
这是日志猫:
D/RxBle#ClientOperationQueue: 排队 ConnectOperation(17461182) D/RxBle#ClientOperationQueue: 已启动 ConnectOperation(17461182) D/RxBle#ClientOperationQueue: 排队 ConnectOperation(218660306) D/RxBle#ClientOperationQueue: 已启动 ConnectOperation(218660306) D/RxBle#BluetoothG onConnectionStateChange newState=2 status=0 D/RxBle#BluetoothGatt: onConnectionStateChange newState=2 status=0 D/RxBle#ClientOperationQueue: FINISHED ConnectOperation(218660306) D/RxBle#ClientOperationQueue: FINISHED ConnectOperation(17461182) D/RxBle#ConnectionOperationQueue: QUEUED ServiceDiscoveryOperation (125599796) D/RxBle#ConnectionOperationQueue: 已启动 ServiceDiscoveryOperation(125599796) D/RxBle#BluetoothGatt: onServicesDiscovered status=0 D/RxBle#ConnectionOperationQueue:QUEUED CharacteristicReadOperation(2626026) D/RxBle#ConnectionOperationQueue: FINISHED ServiceDiscoveryOperation(125599796) D/RxBle#ConnectionOperationQueue: STARTED CharacteristicReadOperation(2626026) D/RxBle#BluetoothGatt: onCharacteristicRead 特性=0000fa03-0278-03be-4447-0dfe 状态RxBle#ConnectionOperationQueue: 已完成 CharacteristicReadOperation(2626026) D/RxBle#ClientOperationQueue: QUEUED ConnectOperation(158692575) D/RxBle#ClientOperationQueue: 已启动 ConnectOperation(158692575) D/RxBle#BluetoothGatt: onConnectionStateChange newState=2 status=0 D/RxBle#ClientOperationQueue:已完成 ConnectOperation(158692575) D/RxBle#ConnectionOperationQueue: 排队 ServiceDiscoveryOperation(20778996) D/RxBle#ConnectionOperationQueue: 已启动 ServiceDiscoveryOperation(20778996) >D/RxBle#BluetoothGatt:onServicesDiscovered 状态=0
D/RxBle#ConnectionOperationQueue: QUEUED CharacteristicWriteOperation(51009974) D/RxBle#ConnectionOperationQueue: FINISHED ServiceDiscoveryOperation(20778996) D/RxBle#ConnectionOperationQueue: STARTED CharacteristicWriteOperation(51009974)
> D/RxBle#BluetoothGatt: onCharacteristicWrite 特性=00020fa444-7883 -091eba91df8e 状态=0D/RxBle#ConnectionOperationQueue:完成 CharacteristicWriteOperation(51009974)
我还尝试使用长 rxAndroidBlewrite 过程:
connectionObservable
.flatMap(rxBleConnection -> {
rxBleConnection.setupNotification(wChar.uuid());
return rxBleConnection.createNewLongWriteBuilder()
.setCharacteristicUuid(wChar.uuid())
.setBytes(array)
.build();
}
)
.subscribe(
bytes -> wChar.success(),
this::onWriteFailure
);
它发送了几个连续的写命令,但它不是长写过程(带有 n ATT_prepare 和 1 ATT_exec),它是独立的写:
D/RxBle#ConnectionOperationQueue: QUEUED CharacteristicLongWriteOperation(74131396) D/RxBle#ConnectionOperationQueue: FINISHED ServiceDiscoveryOperation(250008320) D/RxBle#ConnectionOperationQueue: STARTED CharacteristicLongWriteOperation(74131396)
D/RxBle#BluetoothGatt:onCharacteristicWrite 特性=0000fa04-0278-03be-4447-091eba91df8e 状态=0
D/RxBle#BluetoothGatt:onCharacteristicWrite 特性=0000fa04-0278-03be-4447-091eba91df8e 状态=0
D/RxBle#BluetoothGatt:onCharacteristicWrite 特性=0000fa04-0278-03be-4447-091eba91df8e 状态=0
D/RxBle#BluetoothGatt:onCharacteristicWrite 特性=0000fa04-0278-03be-4447-091eba91df8e 状态=0
D/RxBle#BluetoothGatt:onCharacteristicWrite 特性=0000fa04-0278-03be-4447-091eba91df8e 状态=0
D/RxBle#ConnectionOperationQueue:已完成 CharacteristicLongWriteOperation(74131396)
当然我可以设法在服务器上重建或修改 MTU,但我想使用 BLE 排队写入,这通常由我的中央 (rxandroidble) 和我的外围设备 (nrf52) 支持