0
デバイスをスキャンして特定のデバイスに接続し、4つのGATT特性を読み取るために、ライブラリRxAndroidBleを使用しています。ライブラリを使用してAndroidデバイスから複数の特性を読むRxAndroidBle
私はこのコードi番目の一つの特性(電池残量)を読むことができます:
scanSubscription = rxBleClient.scanBleDevices(
new ScanSettings.Builder()
.build()
)
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(
scanResult -> {
if(scanResult.getBleDevice().getName() != null){
if(scanResult.getBleDevice().getName().equals("NODE 1")){
Log.e("BLE SCAN", "SUCCESS");
Log.e("BLE SCAN", scanResult.getBleDevice().getName());
Log.e("BLE SCAN", scanResult.getBleDevice().getMacAddress());
scanSubscription.unsubscribe();
RxBleDevice device = scanResult.getBleDevice();
subscription = device.establishConnection(false) // <-- autoConnect flag
.flatMap(rxBleConnection -> rxBleConnection.readCharacteristic(UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb")))
.subscribe(
characteristicValue -> {
Log.e("Characteristic", characteristicValue[0]+"");
},
throwable -> {
Log.e("Error", throwable.getMessage());
}
);
}
}
}
)
.subscribe();
私が使用して、2つを読むことができます:
.flatMap(rxBleConnection -> Observable.combineLatest(// use the same connection and combine latest emissions
rxBleConnection.readCharacteristic(aUUID),
rxBleConnection.readCharacteristic(bUUID),
Pair::new
))
をしかし、私は4でそれを行う方法を理解していません例えば、特性。
は、上記の例はあなただけPair
以上の値を受け入れるいくつかのデータオブジェクトを必要とするだけで結構です、あなたに
ありがとうございました、それは素晴らしい働いています – yozzy