feat: add Bluetooth adapter power state handling and auto-power-on

Addresses the common "Not Powered" error where Bluetooth adapters are
powered off, preventing BLE operations. This issue is particularly common
on Raspberry Pi after boot or system updates.

Changes:

1. README.md - Added comprehensive troubleshooting section
   - New section: "Bluetooth adapter not powered"
   - Documented symptoms, causes, and 4 solution methods
   - Instructions for automatic power-on at boot
   - Cross-referenced from other sections

2. BLEInterface.py - Enhanced error handling in _discover_peers()
   - Detect "Not Powered" errors specifically
   - Show clear, actionable error messages instead of stack traces
   - Provide direct solution commands
   - Link to troubleshooting documentation
   - Gracefully handle error without crashing

3. install.sh - Automatic power state checking
   - New "Step 5B: Bluetooth Adapter Power State" section
   - Check if adapter is powered using `bluetoothctl show`
   - Automatically power on adapter if needed
   - Verify operation succeeded
   - Provide troubleshooting steps if power-on fails
   - Check for rfkill blocks

4. examples/bluetooth-power-on.service - New systemd service
   - Ensures Bluetooth is powered on at boot
   - Optional but recommended for production
   - Includes installation instructions in README

5. examples/config_example.toml - Added troubleshooting entry #7
   - Documents power state issue in config comments
   - Cross-references systemd service example
   - Notes that installer (v1.x+) handles this automatically

Impact:
- Users get clear guidance instead of cryptic stack traces
- Installer automatically fixes the issue during setup
- Reduces support burden for common power state errors
- Enables automatic recovery at boot via systemd service

Fixes: "Not Powered" / "No powered Bluetooth adapters found" errors
Tested on: Raspberry Pi Zero 2 W with Raspberry Pi OS Lite 64-bit

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
torlando-tech 2025-10-29 00:10:57 -04:00
commit a0f361a3f4
5 changed files with 121 additions and 3 deletions

View file

@ -250,6 +250,50 @@ These errors occur when BlueZ attempts Classic Bluetooth (BR/EDR) connections in
**Solution:**
Enable BlueZ experimental mode (see Installation → Manual Installation → step 4). If you used the automated installer, re-run it without `--skip-experimental`.
### Bluetooth adapter not powered / "No powered Bluetooth adapters found"
The Bluetooth adapter exists but is powered off, preventing BLE operations.
**Symptoms:**
- Error: `dbus.exceptions.DBusException: org.bluez.Error.Failed: Not Powered`
- Error: `BleakError: No powered Bluetooth adapters found.`
- BLE interface fails to start or discover peers
- GATT server startup fails immediately
**Cause:**
The Bluetooth adapter is in a powered-off state. This commonly happens on Raspberry Pi after boot or system updates.
**Solution:**
Power on the Bluetooth adapter:
```bash
# Option 1: Using bluetoothctl (recommended)
bluetoothctl power on
# Option 2: If adapter is RF-blocked
sudo rfkill unblock bluetooth
# Option 3: Using hciconfig (older systems)
sudo hciconfig hci0 up
# Verify adapter is powered:
bluetoothctl show
# Should display "Powered: yes"
```
**Automatic power-on at boot:**
Ensure Bluetooth service is enabled and starts at boot:
```bash
# Enable Bluetooth service
sudo systemctl enable bluetooth
sudo systemctl start bluetooth
# For persistent power-on, create a systemd service:
# See examples/bluetooth-power-on.service
```
The automated installer (v1.x+) automatically checks and powers on the Bluetooth adapter during installation.
## Architecture
The BLE interface consists of four main components: