Release BLE adapter when idle; make connection hold configurable (connectionTimeout) - #161
Open
AloisKlingler wants to merge 1 commit into
Open
Conversation
Loop() now calls ble.CloseAdapter() when no command is pending, so the HCI adapter is handed back to BlueZ between command sessions and other BlueZ-based tools can share the same controller instead of being locked out until the proxy restarts. The post-command connection hold (previously hard-coded to 29s) is now configurable via the connectionTimeout environment variable (default 10s), matching the existing cacheMaxAge / scanTimeout options. A shorter hold frees the adapter for other tools sooner; a longer hold batches follow-up commands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #158 (adapter is not shared / stays claimed).
Two changes:
Release the adapter when idle.
BleControl.Loop()now callsble.CloseAdapter()in its idle branch (no pending retry) before waiting for the next command. This hands the HCI adapter back to BlueZ between command sessions so other BlueZ-based tools (e.g. a second BLE service on the same host) can use the same controller, instead of being locked out until the proxy is restarted.Configurable connection hold. The post-command connection hold in
operateConnection()was hard-coded to 29s. It is now driven by a newconnectionTimeoutenvironment variable (default 10s), in the same style ascacheMaxAge/scanTimeout. A shorter value releases the adapter for other tools sooner; a longer value batches follow-up commands.For the adapter to actually become usable by BlueZ again after release, the HCI User Channel must be brought back up on close — see the companion PR wimaha/ble_BleConnectFix#1 (add HCIDEVUP in
Close()). After that merges, thego-blereplace ingo.modcan be bumped to include it.Tested on a Raspberry Pi sharing one adapter between this proxy and a second BLE service: commands succeed, and
btmgmt infoshows the controller returning to BlueZ ~10s after each command.