From ef9488fc5c0625da5a63d632062a0dc1c4275652 Mon Sep 17 00:00:00 2001 From: Yogendra Singh Date: Sun, 15 Feb 2026 21:50:14 +0530 Subject: [PATCH] Add Bluetooth speaker support via BlueAlsa --- README.md | 8 +- .../install_airplay_v3.sh | 470 +++++++++++++++++- .../pre_check_airplay_on_pi.sh | 17 + 3 files changed, 466 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 23015ac..232b320 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # RaspberryPi-AirPlay-Installer 📻 -Turn any Raspberry Pi (Zero 2 W, 3, 4, 5) into a modern, high-quality AirPlay 2 receiver in just 5 minutes. This project uses a set of robust scripts to automate the entire installation process, making it incredibly easy to revive your old home theater or favorite speakers. +Turn any Raspberry Pi (Zero 2 W, 3, 4, 5) into a modern, high-quality AirPlay 2 receiver in just 5 minutes. Stream to a USB DAC, built-in audio, or a **Bluetooth speaker** (e.g., Amazon Echo, JBL, Sony). This project uses a set of robust scripts to automate the entire installation process, making it incredibly easy to revive your old home theater or favorite speakers. > **If you find this project helpful, please consider giving it a ⭐ star on GitHub!** It helps others discover it and shows your appreciation for the work. Also, please like the video and **[subscribe to the channel](https://www.youtube.com/@ravis1ngh)**. It helps us create more content like this. @@ -18,6 +18,7 @@ The goal of this project was to simplify the manual installation process, making * **🤖 Fully Automated:** The script handles system updates, dependency installation, compiling, and configuration. * **✅ Smart Pre-Checks:** A pre-installation script verifies your system is ready, checking for internet, disk space, and audio devices to prevent errors. * **🔌 USB DAC Auto-Detection:** Intelligently finds your external USB sound card and lets you choose the correct one if you have multiple. +* **🔵 Bluetooth Speaker Support:** Pair and stream to any Bluetooth speaker (Amazon Echo, JBL, Sony, etc.) with automatic reconnection on boot. * **⚙️ Optimized for Performance:** Automatically configures settings for the best audio quality and prompts to disable Wi-Fi power saving to prevent dropouts. * **🛠️ Robust & Reliable:** Includes error handling and detailed logging for easy troubleshooting. @@ -28,9 +29,10 @@ The goal of this project was to simplify the manual installation process, making * **Raspberry Pi:** A Pi Zero 2 W, 3, 4, or 5 is recommended. * **MicroSD Card:** A quality card with at least 8GB. * **Power Supply:** The official power supply for your Pi model. -* **Audio Output:** +* **Audio Output** (one of the following): * For Pi Zero: An **OTG cable** and a **USB DAC** with a 3.5mm output. * For Pi 3/4/5: The built-in 3.5mm jack or an optional USB DAC. + * **Bluetooth speaker** (e.g., Amazon Echo, JBL, Sony) — requires Pi with built-in Bluetooth or a USB BT adapter. --- @@ -43,7 +45,7 @@ curl -sSL https://raw.githubusercontent.com/Techposts/RaspberryPi-AirPlay-Instal curl -sSl https://raw.githubusercontent.com/Techposts/RaspberryPi-AirPlay-Installer/main/RaspberryPi-AirPlay-Installer-Scripts/install_airplay_v3.sh | bash ``` -The script is interactive and will guide you through the process. Once finished, it will reboot, and your AirPlay 2 receiver will be ready to use! +The script is interactive and will guide you through the process. You'll be asked to choose between **USB DAC/built-in audio** or **Bluetooth speaker** output. Once finished, it will reboot, and your AirPlay 2 receiver will be ready to use! --- diff --git a/RaspberryPi-AirPlay-Installer-Scripts/install_airplay_v3.sh b/RaspberryPi-AirPlay-Installer-Scripts/install_airplay_v3.sh index 6b9cbee..305606f 100644 --- a/RaspberryPi-AirPlay-Installer-Scripts/install_airplay_v3.sh +++ b/RaspberryPi-AirPlay-Installer-Scripts/install_airplay_v3.sh @@ -3,13 +3,14 @@ # =================================================================================== # Shairport-Sync AirPlay 2 ROBUST Installer - ENHANCED VERSION 3.0 # -# Tailored for: Raspberry Pi (Zero 2/3/4/5) with USB DAC -# Version: 3.0 - Production Ready +# Tailored for: Raspberry Pi (Zero 2/3/4/5) with USB DAC or Bluetooth Speaker +# Version: 3.1 - Production Ready # Features: # - Comprehensive error handling with rollback capability # - Dependency validation before installation # - Build failure recovery -# - Audio device validation +# - Audio device validation (USB DAC and Bluetooth) +# - Bluetooth speaker pairing and auto-reconnect # - Service health checks # - Firewall configuration # - Latest package versions @@ -19,7 +20,7 @@ set -eo pipefail # Exit on error and pipe failures IFS=$'\n\t' # Safer word splitting # --- Global Variables --- -SCRIPT_VERSION="3.0" +SCRIPT_VERSION="3.1" LOG_FILE="/tmp/airplay_install_$(date +%Y%m%d_%H%M%S).log" BACKUP_DIR="/tmp/airplay_backup_$(date +%Y%m%d_%H%M%S)" INSTALLATION_FAILED=0 @@ -34,6 +35,12 @@ selected_device="" airplay_name="" disable_wifi_pm=false +# Bluetooth configuration variables +output_mode="" # "alsa" or "bluetooth" +bt_mac_address="" # paired device MAC address +bt_device_name="" # friendly Bluetooth device name +bt_pcm_alias="bt_speaker" # ALSA PCM alias for BlueAlsa device + # --- Cleanup Handler --- cleanup() { local exit_code=$? @@ -51,6 +58,8 @@ cleanup() { cecho "yellow" "Restoring original configuration..." [ -f "$BACKUP_DIR/shairport-sync.conf" ] && \ sudo cp "$BACKUP_DIR/shairport-sync.conf" /etc/shairport-sync.conf 2>/dev/null || true + [ -f "$BACKUP_DIR/asound.conf" ] && \ + sudo cp "$BACKUP_DIR/asound.conf" /etc/asound.conf 2>/dev/null || true fi cecho "yellow" "Installation log saved to: $LOG_FILE" @@ -282,6 +291,325 @@ pre_flight_checks() { echo } +# --- Output Mode Selection --- +select_output_mode() { + echo + cecho "yellow" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + cecho "yellow" " Audio Output Selection" + cecho "yellow" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo + cecho "cyan" "⏸ PLEASE RESPOND TO THIS PROMPT ⏸" + echo + cecho "blue" "How would you like to output audio?" + echo + echo " [1] USB DAC / Built-in Audio (wired)" + echo " [2] Bluetooth Speaker (e.g., Amazon Echo, JBL, Sony)" + echo + + local mode_choice + while true; do + read -p "Enter your choice [1 or 2]: " mode_choice || true + case "$mode_choice" in + 1) + output_mode="alsa" + cecho "green" "✓ Output mode: USB DAC / Built-in Audio" + break + ;; + 2) + output_mode="bluetooth" + cecho "green" "✓ Output mode: Bluetooth Speaker" + break + ;; + *) + cecho "red" "Invalid selection. Please enter 1 or 2." + ;; + esac + done + echo +} + +# --- Bluetooth Adapter Check --- +check_bluetooth_adapter() { + cecho "blue" "Checking Bluetooth adapter..." + + if ! command_exists hciconfig; then + cecho "red" "❌ hciconfig not found. Installing bluez..." + sudo apt-get install -y bluez 2>&1 | tee -a "$LOG_FILE" + fi + + if ! hciconfig hci0 >/dev/null 2>&1; then + cecho "red" "❌ No Bluetooth adapter found (hci0)." + cecho "yellow" " Make sure your Pi has Bluetooth or plug in a USB BT adapter." + exit 1 + fi + + # Try to bring it up if it's down + local bt_state + bt_state=$(hciconfig hci0 | grep -o "UP RUNNING" || true) + if [ -z "$bt_state" ]; then + cecho "yellow" "Bluetooth adapter is down, bringing it up..." + sudo hciconfig hci0 up 2>&1 | tee -a "$LOG_FILE" + sleep 2 + bt_state=$(hciconfig hci0 | grep -o "UP RUNNING" || true) + if [ -z "$bt_state" ]; then + cecho "red" "❌ Failed to bring up Bluetooth adapter." + exit 1 + fi + fi + + cecho "green" "✓ Bluetooth adapter is UP" + log "Bluetooth adapter hci0 is active" +} + +# --- Bluetooth Speaker Pairing --- +pair_bluetooth_speaker() { + echo + cecho "yellow" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + cecho "yellow" " Bluetooth Speaker Pairing" + cecho "yellow" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo + cecho "cyan" "⏸ PLEASE RESPOND TO THE PROMPTS BELOW ⏸" + echo + + # Make sure bluetooth service is running + sudo systemctl enable bluetooth 2>/dev/null || true + sudo systemctl start bluetooth 2>/dev/null || true + sleep 2 + + cecho "blue" "Put your Bluetooth speaker into pairing mode now." + cecho "yellow" " Amazon Echo: Say 'Alexa, pair' or hold the action button" + cecho "yellow" " JBL/Sony/Other: Press and hold the Bluetooth/pairing button" + echo + read -p "Press Enter when your speaker is in pairing mode..." || true + echo + + cecho "blue" "Scanning for Bluetooth devices (30 seconds)..." + log "Starting Bluetooth scan..." + + # Scan for devices + local scan_output + scan_output=$(timeout 30 bluetoothctl --timeout 30 scan on 2>/dev/null & + sleep 30 + bluetoothctl scan off 2>/dev/null + bluetoothctl devices 2>/dev/null + ) || true + + # Get discovered devices + local devices_list + devices_list=$(bluetoothctl devices 2>/dev/null | grep "^Device" || true) + + if [ -z "$devices_list" ]; then + cecho "yellow" "⚠ No Bluetooth devices found during scan." + cecho "yellow" " You can enter the MAC address manually." + echo + read -p "Enter the Bluetooth MAC address (e.g., AA:BB:CC:DD:EE:FF): " bt_mac_address || true + if [[ ! "$bt_mac_address" =~ ^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$ ]]; then + cecho "red" "❌ Invalid MAC address format." + exit 1 + fi + read -p "Enter a friendly name for this device: " bt_device_name || true + [ -z "$bt_device_name" ] && bt_device_name="Bluetooth Speaker" + else + cecho "green" "Found Bluetooth devices:" + echo + + # Parse into arrays + local -a device_macs=() + local -a device_names=() + while IFS= read -r line; do + local mac name + mac=$(echo "$line" | awk '{print $2}') + name=$(echo "$line" | cut -d' ' -f3-) + device_macs+=("$mac") + device_names+=("$name") + done <<< "$devices_list" + + for i in "${!device_macs[@]}"; do + echo " [$i] ${device_names[$i]} (${device_macs[$i]})" + done + echo " [m] Enter MAC address manually" + echo + + local bt_choice + while true; do + read -p "Select your speaker [0-$((${#device_macs[@]}-1)) or m]: " bt_choice || true + if [[ "$bt_choice" == "m" ]]; then + read -p "Enter the Bluetooth MAC address (e.g., AA:BB:CC:DD:EE:FF): " bt_mac_address || true + if [[ ! "$bt_mac_address" =~ ^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$ ]]; then + cecho "red" "Invalid MAC address format. Try again." + continue + fi + read -p "Enter a friendly name for this device: " bt_device_name || true + [ -z "$bt_device_name" ] && bt_device_name="Bluetooth Speaker" + break + elif [[ "$bt_choice" =~ ^[0-9]+$ ]] && [ "$bt_choice" -lt "${#device_macs[@]}" ]; then + bt_mac_address="${device_macs[$bt_choice]}" + bt_device_name="${device_names[$bt_choice]}" + break + fi + cecho "red" "Invalid selection. Please try again." + done + fi + + cecho "blue" "Pairing with $bt_device_name ($bt_mac_address)..." + log "Pairing Bluetooth device: $bt_device_name ($bt_mac_address)" + + # Pair, trust, and connect + bluetoothctl pair "$bt_mac_address" 2>&1 | tee -a "$LOG_FILE" || true + sleep 2 + bluetoothctl trust "$bt_mac_address" 2>&1 | tee -a "$LOG_FILE" || true + sleep 1 + bluetoothctl connect "$bt_mac_address" 2>&1 | tee -a "$LOG_FILE" || true + sleep 3 + + # Verify connection + if bluetoothctl info "$bt_mac_address" 2>/dev/null | grep -q "Connected: yes"; then + cecho "green" "✓ Connected to $bt_device_name" + else + cecho "yellow" "⚠ Device may not be fully connected yet." + cecho "yellow" " The auto-reconnect service will handle this on boot." + read -p "Continue anyway? (Y/n): " continue_choice || true + if [[ "$continue_choice" =~ ^[Nn]$ ]]; then + exit 1 + fi + fi + + log "Bluetooth pairing complete: $bt_device_name ($bt_mac_address)" + echo +} + +# --- Install BlueAlsa --- +install_bluealsa() { + cecho "blue" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + cecho "blue" " Installing BlueAlsa..." + cecho "blue" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + log "Installing BlueAlsa for Bluetooth audio..." + + local os_codename + os_codename=$(lsb_release -cs 2>/dev/null || echo "unknown") + log "Detected OS codename: $os_codename" + + local bluealsa_pkg="bluealsa" + if [[ "$os_codename" == "bookworm" ]] || [[ "$os_codename" == "trixie" ]]; then + bluealsa_pkg="bluez-alsa-utils" + fi + + if ! sudo apt-get install -y bluez "$bluealsa_pkg" 2>&1 | tee -a "$LOG_FILE"; then + cecho "yellow" "⚠ Failed to install $bluealsa_pkg, trying alternative package name..." + if [[ "$bluealsa_pkg" == "bluez-alsa-utils" ]]; then + bluealsa_pkg="bluealsa" + else + bluealsa_pkg="bluez-alsa-utils" + fi + if ! sudo apt-get install -y "$bluealsa_pkg" 2>&1 | tee -a "$LOG_FILE"; then + cecho "red" "❌ Failed to install BlueAlsa. Please install it manually." + exit 1 + fi + fi + + # Enable and start BlueAlsa service + sudo systemctl enable bluealsa 2>/dev/null || true + sudo systemctl restart bluealsa 2>&1 | tee -a "$LOG_FILE" || true + sleep 2 + + cecho "green" "✓ BlueAlsa installed and running" + log "BlueAlsa installation complete" + echo +} + +# --- Configure ALSA for Bluetooth --- +configure_asound_conf() { + cecho "blue" "Configuring ALSA for Bluetooth output..." + log "Writing /etc/asound.conf for BlueAlsa device $bt_mac_address" + + # Backup existing asound.conf if present + [ -f /etc/asound.conf ] && sudo cp /etc/asound.conf "$BACKUP_DIR/" 2>/dev/null || true + + sudo tee /etc/asound.conf > /dev/null < /dev/null </dev/null | grep -q "Connected: yes"; then + echo "Bluetooth speaker connected successfully (attempt \$i)" + exit 0 + fi + echo "Attempting to connect to \$BT_MAC (attempt \$i/\$MAX_RETRIES)..." + bluetoothctl connect "\$BT_MAC" 2>/dev/null || true + sleep \$RETRY_DELAY +done + +echo "WARNING: Could not connect to Bluetooth speaker after \$MAX_RETRIES attempts" +exit 1 +BTEOF + + sudo chmod +x /usr/local/bin/bt-speaker-reconnect.sh + + # Create systemd service + sudo tee /lib/systemd/system/bt-speaker-reconnect.service > /dev/null <&1 | tee -a "$LOG_FILE" + + cecho "green" "✓ Bluetooth auto-reconnect service created" + log "bt-speaker-reconnect service installed and enabled" + echo +} + # --- Detect and Select USB DAC --- select_audio_device() { echo @@ -486,13 +814,14 @@ main() { clear cecho "green" "╔═════════════════════════════════════════════════════╗" cecho "green" "║ ║" - cecho "green" "║ AirPlay 2 Installer for Raspberry Pi + DAC ║" + cecho "green" "║ AirPlay 2 Installer for Raspberry Pi + DAC/BT ║" cecho "green" "║ Version $SCRIPT_VERSION ║" cecho "green" "║ ║" cecho "green" "╚═════════════════════════════════════════════════════╝" echo cecho "blue" "This installer will turn your Raspberry Pi into a" - cecho "blue" "high-quality AirPlay 2 receiver. Just follow the prompts!" + cecho "blue" "high-quality AirPlay 2 receiver via USB DAC or Bluetooth." + cecho "blue" "Just follow the prompts!" echo cecho "yellow" "Installation log: $LOG_FILE" echo @@ -514,8 +843,19 @@ main() { echo # Run all setup steps + select_output_mode pre_flight_checks - select_audio_device + + # Bluetooth adapter check during pre-flight if BT mode selected + if [ "$output_mode" = "bluetooth" ]; then + check_bluetooth_adapter + fi + + if [ "$output_mode" = "bluetooth" ]; then + pair_bluetooth_speaker + else + select_audio_device + fi get_airplay_name configure_wifi @@ -527,8 +867,13 @@ main() { cecho "magenta" "╚═════════════════════════════════════════════════════╝" echo cecho "yellow" " 📱 AirPlay Name: $airplay_name" - cecho "yellow" " 🔊 Audio Output: $audio_device_plug" - cecho "yellow" " 🎚️ Volume Control: ${mixer_control:-None (fixed volume)}" + if [ "$output_mode" = "bluetooth" ]; then + cecho "yellow" " 🔊 Audio Output: Bluetooth: $bt_device_name" + cecho "yellow" " 🔗 BT MAC Address: $bt_mac_address" + else + cecho "yellow" " 🔊 Audio Output: $audio_device_plug" + cecho "yellow" " 🎚️ Volume Control: ${mixer_control:-None (fixed volume)}" + fi cecho "yellow" " 📡 Disable Wi-Fi PM: $disable_wifi_pm" echo cecho "blue" "Installation will take 10-30 minutes depending on your Pi model." @@ -550,6 +895,7 @@ main() { # Create backup directory mkdir -p "$BACKUP_DIR" [ -f /etc/shairport-sync.conf ] && cp /etc/shairport-sync.conf "$BACKUP_DIR/" 2>/dev/null || true + [ -f /etc/asound.conf ] && cp /etc/asound.conf "$BACKUP_DIR/" 2>/dev/null || true # --- System Update --- cecho "blue" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" @@ -580,7 +926,7 @@ main() { build-essential git autoconf automake libtool pkg-config libpopt-dev libconfig-dev libasound2-dev avahi-daemon libavahi-client-dev libssl-dev - libsoxr-dev libplist-dev libsodium-dev + libsoxr-dev libplist-dev libplist-utils libsodium-dev libavutil-dev libavcodec-dev libavformat-dev uuid-dev libgcrypt20-dev xxd alsa-utils ) @@ -602,6 +948,11 @@ main() { cecho "green" "✓ Dependencies installed" echo + # Install BlueAlsa if Bluetooth mode selected + if [ "$output_mode" = "bluetooth" ]; then + install_bluealsa + fi + # Make sure avahi-daemon is running if ! systemctl is-active --quiet avahi-daemon; then cecho "yellow" "Starting avahi-daemon..." @@ -771,12 +1122,19 @@ FALLBACK_EOF sudo sed -i "s|^//[[:space:]]*name = .*| name = \"$airplay_name\";|" /etc/shairport-sync.conf # Set output device - uncomment and set it - log "Configuring audio output: $audio_device_plug" - sudo sed -i "s|^[[:space:]]*output_device = .*| output_device = \"$audio_device_plug\";|" /etc/shairport-sync.conf - sudo sed -i "s|^//[[:space:]]*output_device = .*| output_device = \"$audio_device_plug\";|" /etc/shairport-sync.conf + if [ "$output_mode" = "bluetooth" ]; then + log "Configuring audio output: Bluetooth via $bt_pcm_alias" + configure_asound_conf + sudo sed -i "s|^[[:space:]]*output_device = .*| output_device = \"$bt_pcm_alias\";|" /etc/shairport-sync.conf + sudo sed -i "s|^//[[:space:]]*output_device = .*| output_device = \"$bt_pcm_alias\";|" /etc/shairport-sync.conf + else + log "Configuring audio output: $audio_device_plug" + sudo sed -i "s|^[[:space:]]*output_device = .*| output_device = \"$audio_device_plug\";|" /etc/shairport-sync.conf + sudo sed -i "s|^//[[:space:]]*output_device = .*| output_device = \"$audio_device_plug\";|" /etc/shairport-sync.conf + fi - # Set mixer control if available - if [ -n "$mixer_control" ]; then + # Set mixer control if available (ALSA mode only) + if [ "$output_mode" != "bluetooth" ] && [ -n "$mixer_control" ]; then log "Configuring mixer control: $mixer_control on hw:$card_number" sudo sed -i "s|^//[[:space:]]*mixer_control_name = .*| mixer_control_name = \"$mixer_control\";|" /etc/shairport-sync.conf sudo sed -i "s|^[[:space:]]*mixer_control_name = .*| mixer_control_name = \"$mixer_control\";|" /etc/shairport-sync.conf @@ -804,8 +1162,8 @@ FALLBACK_EOF cecho "green" "✓ Configuration file created and customized" - # Set mixer volume to maximum if available - if [ -n "$mixer_control" ]; then + # Set mixer volume to maximum if available (ALSA mode only) + if [ "$output_mode" != "bluetooth" ] && [ -n "$mixer_control" ]; then cecho "blue" "Setting mixer volume to 100%..." if amixer -c "$card_number" set "$mixer_control" 100% unmute > /dev/null 2>&1; then sudo alsactl store > /dev/null 2>&1 || true @@ -833,11 +1191,34 @@ FALLBACK_EOF log "Created shairport-sync user" fi + # Add shairport-sync user to bluetooth group if BT mode + if [ "$output_mode" = "bluetooth" ]; then + sudo usermod -aG bluetooth shairport-sync 2>/dev/null || true + log "Added shairport-sync user to bluetooth group" + fi + log "Creating systemd service manually (make install sometimes fails at this step)..." # Create systemd service file manually - this is more reliable than 'make install' # which often fails on the systemd service installation step on Raspberry Pi - sudo tee /lib/systemd/system/shairport-sync.service > /dev/null < /dev/null < /dev/null <&1 | tee -a "$LOG_FILE" @@ -863,6 +1245,11 @@ EOF exit 1 fi + # Set up Bluetooth auto-reconnect service if BT mode + if [ "$output_mode" = "bluetooth" ]; then + create_bt_reconnect_service + fi + # Verify avahi-daemon is running (required for AirPlay discovery) cecho "blue" "Checking Avahi daemon (required for device discovery)..." if ! systemctl is-active --quiet avahi-daemon; then @@ -931,23 +1318,42 @@ EOF read -p "Do you want to test audio output? (Y/n): " test_audio || true if [[ -z "$test_audio" || "$test_audio" =~ ^[Yy]$ ]]; then + local test_device + if [ "$output_mode" = "bluetooth" ]; then + test_device="$bt_pcm_alias" + else + test_device="$audio_device_plug" + fi + cecho "yellow" "Playing test sound in 2 seconds..." cecho "yellow" "(You should hear a voice saying 'Front Left', 'Front Right')" sleep 2 - if timeout 10 speaker-test -D "$audio_device_plug" -c 2 -t wav -l 1 > /dev/null 2>&1; then + if timeout 10 speaker-test -D "$test_device" -c 2 -t wav -l 1 > /dev/null 2>&1; then echo cecho "green" "✓ Audio test completed!" read -p "Did you hear the test sound? (y/N): " heard_sound || true if [[ ! "$heard_sound" =~ ^[Yy]$ ]]; then - cecho "yellow" "⚠ If you didn't hear sound, check:" - cecho "yellow" " - Speaker/headphone connections" - cecho "yellow" " - Volume level on your amplifier/speakers" - cecho "yellow" " - USB DAC power" + if [ "$output_mode" = "bluetooth" ]; then + cecho "yellow" "⚠ If you didn't hear sound, check:" + cecho "yellow" " - Bluetooth speaker is powered on and connected" + cecho "yellow" " - Volume level on the Bluetooth speaker" + cecho "yellow" " - Try: bluetoothctl connect $bt_mac_address" + else + cecho "yellow" "⚠ If you didn't hear sound, check:" + cecho "yellow" " - Speaker/headphone connections" + cecho "yellow" " - Volume level on your amplifier/speakers" + cecho "yellow" " - USB DAC power" + fi fi else cecho "yellow" "⚠ Audio test couldn't run, but setup is complete." - cecho "yellow" " You can test manually with: speaker-test -D $audio_device_plug -c 2 -t wav" + if [ "$output_mode" = "bluetooth" ]; then + cecho "yellow" " This is common with Bluetooth — the speaker may need a moment." + cecho "yellow" " Test manually: speaker-test -D $bt_pcm_alias -c 2 -t wav" + else + cecho "yellow" " You can test manually with: speaker-test -D $audio_device_plug -c 2 -t wav" + fi fi fi echo @@ -973,8 +1379,12 @@ EOF cecho "magenta" "🎵 Your AirPlay 2 device is ready!" echo cecho "yellow" " 📱 Device Name: $airplay_name" - cecho "yellow" " 🔊 Audio Output: $audio_device_plug" - cecho "yellow" " 🎚️ Volume: ${mixer_control:-Fixed (no hardware control)}" + if [ "$output_mode" = "bluetooth" ]; then + cecho "yellow" " 🔊 Audio Output: Bluetooth: $bt_device_name ($bt_mac_address)" + else + cecho "yellow" " 🔊 Audio Output: $audio_device_plug" + cecho "yellow" " 🎚️ Volume: ${mixer_control:-Fixed (no hardware control)}" + fi echo cecho "blue" "┌─────────────────────────────────────────────────────┐" cecho "blue" "│ How to use: │" @@ -988,6 +1398,14 @@ EOF cecho "yellow" " • Device should appear within 30 seconds after reboot" cecho "yellow" " • Make sure iPhone and Pi are on the same Wi-Fi network" cecho "yellow" " • For best quality, use lossless audio sources" + if [ "$output_mode" = "bluetooth" ]; then + echo + cecho "yellow" "🔵 Bluetooth Tips:" + cecho "yellow" " • Auto-reconnect service will connect your speaker on each boot" + cecho "yellow" " • Make sure the BT speaker is powered on before/during Pi boot" + cecho "yellow" " • Manual reconnect: bluetoothctl connect $bt_mac_address" + cecho "yellow" " • Check BT status: bluetoothctl info $bt_mac_address" + fi if [ "$disable_wifi_pm" = true ]; then echo cecho "yellow" "📝 IMPORTANT - After reboot:" diff --git a/RaspberryPi-AirPlay-Installer-Scripts/pre_check_airplay_on_pi.sh b/RaspberryPi-AirPlay-Installer-Scripts/pre_check_airplay_on_pi.sh index 309346c..84b4a61 100644 --- a/RaspberryPi-AirPlay-Installer-Scripts/pre_check_airplay_on_pi.sh +++ b/RaspberryPi-AirPlay-Installer-Scripts/pre_check_airplay_on_pi.sh @@ -133,6 +133,23 @@ else check_warn "No Wi-Fi interface found (wlan0)" fi +# Check 10: Bluetooth adapter +echo +if command -v hciconfig >/dev/null 2>&1; then + if hciconfig hci0 >/dev/null 2>&1; then + BT_STATE=$(hciconfig hci0 | grep -o "UP RUNNING" || true) + if [ -n "$BT_STATE" ]; then + check_pass "Bluetooth adapter found and active" + else + check_warn "Bluetooth adapter found but not active (run: sudo hciconfig hci0 up)" + fi + else + check_warn "No Bluetooth adapter found (optional — needed only for BT speaker output)" + fi +else + check_warn "hciconfig not found (install bluez for Bluetooth support)" +fi + # Summary echo echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"