Read Characteristic from RxBluetoothKit

Dear Everyone!

I am using RxBluetoothKit library to connect bluetooth to peripheral devices. But now, when I read data from 1 characteristics, in call back I did not read another characteristics.

My code is as follows:

viewDidAppearSubject

         .take (1)
         .flatMap {self.bluetoothProvider.getValueUpdates (for: charator2102)}
         .subscribe (
             onNext: {
                 if $ 0 == "2103" {
                     self.read2103 ()
                 }
                 print ($ 0)
             },
             onError: {_ in self.showError ()}
         )
         .disposed (by: disposeBag)

When I receive data of charator2102, I cannot read more data of charactor2103 anymore.

Hope everyone help me!

Thanks very much!

Welcome hungnx5,

If I understand your question correctly, you are wondering why the subscription closure only receives the data for charator2102, but no other values that are published.

In your example the .take(1) filter operator takes the first emitted value. However, you are not processing that value any further. You can access the filtered element with $0. So instead of:

.flatMap { self.bluetoothProvider.getValueUpdates(for: charator2102) }

you probably want:

.flatMap { self.bluetoothProvider.getValueUpdates(for: $0) }

For more information on this, please have a look at the documentation for .take(n) at: ReactiveX - Take operator

I hope this helps! :]

2 Likes

Dear @prepar
I tried your way but it still doesn’t work well.
Please tell me more!
Thank you so much!