I am using RxAndroidBle library to connect to android devices, but I couldn't find any way to connect BLE device and send MTU request and get characteristic UUID of service by Service UUID in a single requet
Describe the issue
I need to connect BLE device & send MTU request and get characteristic UUID of service by Service UUID step by step
To Reproduce
Steps to reproduce the behavior:
- Find the BLE device by name or mac address
- Send MTU request 517
- Get service by Service UUID
- Get characteristic value by characteristic UUID
Additional context I can not combine all methods and unable to call one after one
private Observable<RxBleConnection> connectionObservable;
private PublishSubject<Boolean> disconnectTriggerSubject = PublishSubject.create();
private void connect() {
Disposable disposable = connectionObservable
.flatMapSingle(rxConn -> rxConn.requestMtu(RxBleConnection.GATT_MTU_MAXIMUM))
.doOnComplete(() -> {
Disposable notifDisposable = connectionObservable.doOnNext(rxBleConnection -> {
Single<Integer> mtu = rxBleConnection.requestMtu(RxBleConnection.GATT_MTU_MAXIMUM);
Log.w("TAG_TAG", "notif --> Mtu: " + rxBleConnection.getMtu());
}).flatMapSingle(RxBleConnection::discoverServices)
.flatMapSingle(rxBleDeviceServices -> rxBleDeviceServices.getCharacteristic(CHARACTERISTIC_UUID))
.doOnComplete(() -> {
Disposable reedDisposable = connectionObservable.flatMapSingle(RxBleConnection::discoverServices)
.flatMapSingle(rxBleDeviceServices -> rxBleDeviceServices.getCharacteristic(CHARACTERISTIC_UUID))
.subscribe(
characteristic -> {
Log.w("TAG_TAG", "reed --> Value: " + Arrays.toString(characteristic.getValue()));
if (characteristic.getValue() != null) {
Log.w("TAG_TAG", "reed --> Value: " + characteristic.getValue().length + " , HexString: " + toHexString(characteristic.getValue()));
}
},
this::onConnectionFailure,
this::onConnectionFinished
);
})
.subscribe(
characteristic -> {
Log.w("TAG_TAG", "notif --> Value: " + Arrays.toString(characteristic.getValue()));
if (characteristic.getValue() != null) {
Log.w("TAG_TAG", "notif --> Value: " + characteristic.getValue().length + " , HexString: " + toHexString(characteristic.getValue()));
}
},
this::onConnectionFailure,
this::onConnectionFinished
);
})
.subscribe(
integer -> {
Log.w("TAG_TAG", "connect --> Integer: " + integer);
}
);
}