-
-
Notifications
You must be signed in to change notification settings - Fork 121
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
Improve resilience of BLE Inquiry mode #887
Conversation
Codecov Report
@@ Coverage Diff @@
## main #887 +/- ##
==========================================
- Coverage 91.61% 91.55% -0.06%
==========================================
Files 97 97
Lines 2624 2665 +41
Branches 397 417 +20
==========================================
+ Hits 2404 2440 +36
- Misses 216 221 +5
Partials 4 4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
From a first look the PR looks good! It does seem like me merging #852 has introduced some conflicts, possibly because of the squash & merge. Let me know if I can help fix that somehow. As for the sleep: I looked at the recent fix commit on abandonware/bluetooth-hci-socket as well, it's a bit out of my depth. Either way, the current safeguard implementation shouldn't hurt even if they fix the issue upstream someday. Since the previous implementation was just based on experiments as well (if I remember correctly), I see nothing wrong with 100ms if that is working better in your tests. |
De-stacked the PR to resolve the conflict. |
I added two "guard" commits to avoid concurrent calls to Rather than relying on
|
@mKeRix , so I'm seeing something "weird" going on and appreciate any insight ... Basically, Noble hci-socket seems to generate a spurious Scan Started event in the middle of a The event is triggered by this line in gap.js and isnt as a result of a A function trace below to show context:
I would be interested to know if this is seen by others. While I dont have a simple repo, if you add a breakpoint or |
Hm - bleno in itself isn't instructed to start scanning at any time, in fact it shouldn't even have to do that for any internal reason. It should only ever toggle the advertising. It certainly could be a root cause for the discussions in the beta issue though... great find! Given that this seems to be resolved once you get rid off bleno I'd suggest to just leave it as is though. bleno was only used for the toggle feature in the app, which also suffered from some other issues on the iOS side. I'm still planning to drop that (and hopefully replace the feature with smth else) like it is on the beta branch currently. The recent changes on main will also be made available as part of a new beta release once this PR is merged. (happy to discuss if you disagree!) |
I agree that Bleno is not directly initiating a scan. I suspect it is either a timing or an inter-operability issue that happens say one in ten times in my setup. Looking at HCI traces during a failed query attempt, you can see an rogue inbound connection to the bleno interface - bleno configures the adapter in Unfortunately, just not starting advertising is insufficient as importing bleno triggers its initialisation and subsequent processing of hci socket commands. I have done a quick dynamic loading commit to avoid this when I think this is a good place to finish up this PR and happy to take any comments/feedback. --- Looks like some test errors from the rebase, will take a look -Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Looks good, LGTM. Will issue a release shortly.
I like your idea of dynamically loading bleno... could be a better path for the next major version (= current beta), instead of dropping the feature just turning it off by default.
# [2.19.0](v2.18.4...v2.19.0) (2021-09-21) ### Features * **bluetooth-low-energy:** add option for reducing discovery log entries ([#853](#853)) ([e405558](e405558)) * **bluetooth-low-energy:** improve resilience of inquiry mode ([#887](#887)) ([9fc0eec](9fc0eec)) * **grid-eye:** add option to mask zero based values ([#891](#891)) ([c8f5b95](c8f5b95)) * support NodeJS 16 ([b795995](b795995)) * **xiaomi-mi:** add support for HA long-term statistics ([92bf8e8](92bf8e8)), closes [#869](#869) * **xiaomi-mi:** publish miflora battery state as sensors ([#852](#852)) ([1cdfcd2](1cdfcd2))
🎉 This PR is included in version 2.19.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [3.0.0-beta.3](v3.0.0-beta.2...v3.0.0-beta.3) (2021-09-21) ### Features * **bluetooth-low-energy:** add option for reducing discovery log entries ([#853](#853)) ([e405558](e405558)) * **bluetooth-low-energy:** improve resilience of inquiry mode ([#887](#887)) ([9fc0eec](9fc0eec)) * **grid-eye:** add option to mask zero based values ([#891](#891)) ([c8f5b95](c8f5b95)) * support NodeJS 16 ([b795995](b795995)) * **xiaomi-mi:** add support for HA long-term statistics ([92bf8e8](92bf8e8)), closes [#869](#869) * **xiaomi-mi:** publish miflora battery state as sensors ([#852](#852)) ([1cdfcd2](1cdfcd2))
🎉 This PR is included in version 3.0.0-beta.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Thanks for taking this on-board, much appreciated. |
Describe the change
Looks to address issues identified in #852. A quick summary:
The first two new commits address the comments here and here.
The next two new commits allow for aborting connection and query logic on a timeout or disconnect. Basically, I have pushed
promiseWithTimeout
down to wrap the specific Noble functions. I have retained the overall timeout duration as per master.The last commit refactors the "unlocking" disconnect listener as that can be handled inline at the end of
queryLowEnergyDevice
directly.There is an outstanding question about the
sleep
call after connection attempts. I have read the noble issue and the fix recently committed on the abandonware hci repo. Unfortunately, the fix didn't make any difference for me. I also found 100ms sleep to be much better than 500ms at filtering out the erroneous disconnect events . Obviously, happy to adjust.I have done this as a stacked PR building on the miflora_battery PR as it has allowed me to test using a large number of active devices. But I'm thinking this will make it very difficult to review. Let me know if it would help to split the commits into separate PRs and base off of main (or maybe beta). I can then fixup miflora_battery once this has landed.
I've marked as WIP as I am still soak testing this and looking at a few other tweaks but be good to get any thoughts thus far.
Checklist
If you changed code:
npm test
)npm run format
)If you added a new integration:
docs/integrations/
docs/.vuepress/config.ts
anddocs/integrations/README.md
Additional information
Is this PR related to any issues? Do you have anything else to add?