Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discoverCharacteristics not emitting the anything #287

Open
eliekarouz opened this issue Sep 19, 2018 · 3 comments
Open

discoverCharacteristics not emitting the anything #287

eliekarouz opened this issue Sep 19, 2018 · 3 comments

Comments

@eliekarouz
Copy link

Describe the bug
I started characteristics discovery by calling this peripheral.discoverCharacteristics(nil, for: service) but when I subscribe I don't get any event. The bug can't be easily reproduced and you need to disconnect/reconnect for it to happen but here's my investigation:
I found out that the filter operator was preventing the emitted event from the delegateWrapper to go through the rest of the chain. The filter operator (line 328 of Peripheral.swift) is checking if remainingCharacteristicsDiscoveryRequest doesn't reach 0 and in my case the value was still > 0 and it actually reached 5.
I think that this can happen if you disconnect from the device in the middle of service or characteristic discovery because when subscribe the counter is incremented and when you receive the event it's decremented but when you disconnect before receiving the "didDiscoverCharacteristic" event it stays > 0. Any further attempt to reconnect and discover the characteristics would fail.
I think this can happen either with discoverServices or discoverCharacteristics although I was only able to reproduce the issue with the discoverCharacteristics method.

I tried to understand why you need to track the number of requests but didn't get a clear response.
I managed to bypass this issue by sending an empty array instead of nil as a first argument just because the code would skip the counter check and sticks only with if the all characteristics are there allowing the event to traverse the filter.

Environment:

  • Device: iPhone
  • OS: iOS 11.4
  • Library version 5.1.2
  • Swift version 4.1

Thanks!

@bartoszstelmaszuk
Copy link
Contributor

Hi! Thanks for the feedback.

As far as we can see the solution is to just clear our internal cache on every peripheral disconnection or state change to powered off. We will try to reproduce the problem and implement a fix.

@bartoszstelmaszuk bartoszstelmaszuk self-assigned this Sep 25, 2018
@c0diq
Copy link
Contributor

c0diq commented Feb 5, 2019

Probably the same problem as #309

@c0diq
Copy link
Contributor

c0diq commented Mar 1, 2019

Any update on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants