From 035950df48e8ba00e2fd92924322a6d0e8b25769 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 23 Nov 2025 03:53:51 +0000 Subject: [PATCH] Fix addons menu numbering and improve bluetooth device scanning Fixes: 1. Addons menu: Remove duplicate menu items (1,2 appeared twice) - Fixed numbering: Remote Access is now option 5 instead of 6 2. Bluetooth scanning improvements: - Make controller pairable/discoverable before scanning - Capture scan output to show DISCOVERED devices (not just paired) - Real-time progress indicator during 30-second scan - Separate display of discovered vs already-paired devices - Better error handling for pairing failures - Proper cleanup of scan process with 'scan off' - Helpful hints when pairing fails (e.g., AuthenticationFailed) The bluetooth scan previously only showed paired devices after scanning, which made it appear that no devices were found even when they were broadcasting. Now it properly captures and displays discovered devices. --- install_kiosk_0.9.6-2.sh | 102 +++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/install_kiosk_0.9.6-2.sh b/install_kiosk_0.9.6-2.sh index dfc47ba..6e7f747 100755 --- a/install_kiosk_0.9.6-2.sh +++ b/install_kiosk_0.9.6-2.sh @@ -7154,24 +7154,92 @@ addon_bluetooth() { case "$bt_choice" in 1) echo - echo "Scanning for devices (30 seconds)..." + echo "Preparing bluetooth for scanning..." + # Enable bluetooth and make it discoverable bluetoothctl power on - bluetoothctl scan on & + bluetoothctl pairable on + bluetoothctl discoverable on + + # Remove old scan results + rm -f /tmp/bt_scan_* 2>/dev/null + + # Start scanning and capture output + echo "Scanning for devices (30 seconds)..." + echo "Please put your device in pairing mode now..." + echo + + # Use timeout to control scan duration and capture output + timeout 30s bluetoothctl --timeout 30 scan on 2>&1 | tee /tmp/bt_scan_$$.log & scan_pid=$! - sleep 30 - kill $scan_pid 2>/dev/null + + # Show discovered devices in real-time + sleep 2 # Give scan time to start + for i in {1..14}; do + sleep 2 + # Show new devices discovered + if grep -q "Device" /tmp/bt_scan_$$.log 2>/dev/null; then + echo -ne "\rScanning... ($((i*2))s) - Devices found: $(grep -c "Device" /tmp/bt_scan_$$.log 2>/dev/null || echo 0) " + fi + done + + wait $scan_pid 2>/dev/null + bluetoothctl scan off 2>/dev/null + echo - echo "Devices found:" - bluetoothctl devices echo - read -r -p "Enter device MAC address to pair: " bt_mac + echo "Scan complete. Devices found:" + + # Parse and display discovered devices + if [[ -f /tmp/bt_scan_$$.log ]]; then + grep -E "Device [0-9A-F:]{17}" /tmp/bt_scan_$$.log | sort -u | while read -r line; do + mac=$(echo "$line" | grep -oE "[0-9A-F:]{17}") + name=$(echo "$line" | sed -E 's/.*Device [0-9A-F:]{17} //') + # Check if already paired + if bluetoothctl devices Paired 2>/dev/null | grep -q "$mac"; then + echo " $mac - $name (already paired)" + else + echo " $mac - $name" + fi + done + fi + + # Also show already paired devices + echo + echo "Already paired devices:" + if bluetoothctl devices Paired 2>/dev/null | grep -q "Device"; then + bluetoothctl devices Paired | while read -r line; do + echo " $line" + done + else + echo " (none)" + fi + + echo + read -r -p "Enter device MAC address to pair (or Enter to cancel): " bt_mac if [[ -n "$bt_mac" ]]; then echo "Pairing with $bt_mac..." - bluetoothctl pair "$bt_mac" - bluetoothctl trust "$bt_mac" - bluetoothctl connect "$bt_mac" - log_success "Device paired and connected" + + # Try to pair + if bluetoothctl pair "$bt_mac" 2>&1 | tee /tmp/bt_pair_$$.log; then + echo "Trusting device..." + bluetoothctl trust "$bt_mac" + echo "Connecting..." + if bluetoothctl connect "$bt_mac"; then + log_success "Device paired and connected successfully" + else + echo "Warning: Paired but connection failed. Device may not be ready." + echo "You can try connecting again from the main bluetooth menu." + fi + else + echo "Pairing failed. Make sure the device is in pairing mode." + if grep -qi "AuthenticationFailed" /tmp/bt_pair_$$.log; then + echo "Try: Remove any existing pairing on your device and try again." + fi + fi + rm -f /tmp/bt_pair_$$.log fi + + rm -f /tmp/bt_scan_$$.log pause addon_bluetooth ;; @@ -9434,23 +9502,19 @@ addons_menu() { echo "Available Addons:" echo " 1. LMS Server / Squeezelite Player" echo " 2. CUPS Printing" - echo " 1. LMS Server / Squeezelite Player" - echo " 2. CUPS Printing" echo " 3. Bluetooth Audio & Devices" echo " 4. talkkonnect/Murmur Intercom (native audio)" - echo " 6. Remote Access (VNC/VPN)" + echo " 5. Remote Access (VNC/VPN)" echo " 0. Return" echo - read -r -p "Choose [0-6]: " choice - + read -r -p "Choose [0-5]: " choice + case "$choice" in - 1) addon_lms_squeezelite ;; - 2) addon_cups ;; 1) addon_lms_squeezelite ;; 2) addon_cups ;; 3) addon_bluetooth ;; 4) addon_talkkonnect_intercom ;; - 6) remote_access_menu ;; + 5) remote_access_menu ;; 0) return ;; esac done