RxBluetoothKit icon indicating copy to clipboard operation
RxBluetoothKit copied to clipboard

readValue triggers onNext for observeValueUpdateAndSetNotification

Open Drusy opened this issue 7 years ago • 3 comments

Describe the bug

Normal behavior For any characteristic that can notify, subscribe to observeValueUpdateAndSetNotification. onNext is called everytime the hardware notifies the characteristic. Now at any time, call readValue on the same characteristic. As readValue is a PrimitiveSequence, the onSuccess callback is called with the updated characteristic value

I am using CharacteristicIdentifier for both notify and read subscriptions.

Potential Issue Right before onSuccess is called on the readValue observable, I noticed that the onNext callback of observeValueUpdateAndSetNotification is also called. In my case, it results in a double notification and so a double management of the read value which could have unexpected behavior

To Reproduce Steps to reproduce the behavior:

  1. Subscribe to observeValueUpdateAndSetNotification and print any notified value on characteristic
  2. Call readValue on this same characteristic
  3. Observe the observeValueUpdateAndSetNotification being called

Expected behavior The notification callback should not be triggered

Environment:

  • OS: iOS 9/10/11/12
  • Library version 5.1.3
  • Swift version 4.2

Drusy avatar Dec 13 '18 08:12 Drusy

As far as I know this is the default behaviour of vanilla iOS API. There is a single callback for wether the value of a characteristic was updated by a notification or a read. I may be wrong but sorting it in the library may introduce some edge cases when a notification would be triggered at the time a read would happen. Thoughts?

dariuszseweryn avatar Jan 11 '19 11:01 dariuszseweryn

I agree, the default behavior of the iOS API has a unique callback func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) . The use of the RxBluetoothKit API seem misleading to me in that case because you can subscribe to readValue and you have a onSuccess call. By default I wouldn't expect any other callback/observer to be triggered.

Is this bothering only me ? If it's the case, this issue can be closed and I will adapt my code properly. I would like to have the opinion of a contributor though

Drusy avatar Jan 11 '19 12:01 Drusy

We will get back to the topic next week probably

dariuszseweryn avatar Jan 11 '19 13:01 dariuszseweryn