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

Spurious data due to unnecessary call to [peripheral readValueForCharacteristic:characteristic] #4

Open
gene-pavlovsky opened this issue Jan 31, 2021 · 0 comments

Comments

@gene-pavlovsky
Copy link

Hello there,

I used your code as a base for writing a little test program for a different device that also has an accelerometer.
When I dumped the data to stdout, it looked a bit strange. While shaking the device, for every 3 realistic looking samples there was one sample with all zeros.

I tracked it down to this:
CBMicroBitBridge.mm, didUpdateValueForCharacteristic method does a call to [peripheral readValueForCharacteristic:characteristic]. I believe this is wrong.

The doc for didUpdateValueForCharacteristic says:

Core Bluetooth invokes this method when your app calls the readValueForCharacteristic: method. A peripheral also invokes this method to notify your app of a change to the value of the characteristic for which the app previously enabled notifications by calling setNotifyValue:forCharacteristic:.

Since your code uses notifications, there is no need to call readValueForCharacteristic manually. And doing that seems to be causing issues somehow. After I removed this call, I'm not getting all-zeros samples anymore. You might want to add && !error in the if condition as well, although I was not getting errors, just all-zeros samples.

Best regards
Gene

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

1 participant