Improve Bluetooth handling: permission errors and automatic reconnection - #52
Open
GlassOnTin wants to merge 4 commits into
Open
Improve Bluetooth handling: permission errors and automatic reconnection#52GlassOnTin wants to merge 4 commits into
GlassOnTin wants to merge 4 commits into
Conversation
- Detect when user is not in bluetooth group - Provide clear instructions for permanent fix (usermod command) - Show exact sudo command as temporary workaround - Enhanced error messages for common Bluetooth failures - Check permissions before attempting Bluetooth scan - Improve user experience when running without proper permissions This makes it much clearer to users why Bluetooth scanning fails and provides actionable steps to resolve the issue.
- Implement connection state tracking (disconnected/connecting/connected/reconnecting) - Add exponential backoff for reconnection attempts (1s to 60s max) - Enhance error handling to detect Bluetooth disconnections - Add comprehensive logging for connection state changes - Ensure device continues attempting reconnection until manually stopped This improves reliability when Bluetooth connections drop due to: - Device timeouts after prolonged streaming - Bluetooth interference - Device power cycling - Other processes connecting to the device
Owner
|
Please rebase your branch to the current |
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.
Two changes from running a RadiaCode as a long-lived monitor, where Bluetooth turned out to be fragile in two distinct ways.
The first is permissions. When scanning fails because the user isn't in the
bluetoothgroup, theBTLEExceptionsurfaces as a generic failure with no hint of the cause.radiacode/discovery.pynow recognises the permission case, anddevice_reader.pychecks group membership before attempting to scan, so the message can say exactly what to do:The second is drops during streaming, which happen in normal use — the device times out after a minute or two of prolonged streaming, other processes grab it, interference, power cycling. Previously the reader just stopped.
device_reader.pynow tracks a connection state (disconnected/connecting/connected/reconnecting), logs transitions through the standardloggingmodule, and reconnects with exponential backoff from 1 s doubling to a 60 s cap, retrying until stopped:Tested without sudo and outside the bluetooth group (gets the instructions above), with sudo, and with proper group membership; the reconnection path and backoff sequence verified across forced connection drops.