Skip to content

Release BLE adapter when idle; make connection hold configurable (connectionTimeout) - #161

Open
AloisKlingler wants to merge 1 commit into
wimaha:mainfrom
AloisKlingler:configurable-connection-timeout
Open

Release BLE adapter when idle; make connection hold configurable (connectionTimeout)#161
AloisKlingler wants to merge 1 commit into
wimaha:mainfrom
AloisKlingler:configurable-connection-timeout

Conversation

@AloisKlingler

Copy link
Copy Markdown
Contributor

Addresses #158 (adapter is not shared / stays claimed).

Two changes:

  1. Release the adapter when idle. BleControl.Loop() now calls ble.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.

  2. Configurable connection hold. The post-command connection hold in operateConnection() was hard-coded to 29s. It is now driven by a new connectionTimeout environment variable (default 10s), in the same style as cacheMaxAge / 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, the go-ble replace in go.mod can 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 info shows the controller returning to BlueZ ~10s after each command.

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.
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

Successfully merging this pull request may close these issues.

1 participant