Skip to content

Instantly share code, notes, and snippets.

@mister2d
Forked from qcasey/README.md
Created January 21, 2023 06:22
Show Gist options
  • Select an option

  • Save mister2d/9ddfc0a767f57c12d3924771fdf61976 to your computer and use it in GitHub Desktop.

Select an option

Save mister2d/9ddfc0a767f57c12d3924771fdf61976 to your computer and use it in GitHub Desktop.

Revisions

  1. @qcasey qcasey revised this gist May 24, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -72,6 +72,8 @@ Copy the included file **a2dp-agent** to `/usr/local/bin` and make the file exec
    sudo chmod +x /usr/local/bin/a2dp-agent
    ```

    *A Python 3 version has been generously provided by @abelmatser in [another gist](https://gist.github.com/abelmatser/258ac0aac454323bdb2de2034a6d40e3)*

    ### Testing The Agent
    Before continuing, verify that the agent is functional. The Raspberry Pi should be discoverable, pairable and recognized as an audio device.

  2. @qcasey qcasey revised this gist Sep 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bt-a2dp-autoinstall.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # Update, install prereqs
    #
    apt-get update
    apt-get -y install alsa git gcc make autoconf libtool blueman bluez bluetooth libbluetooth-dev libfdk-aac-dev libsbc-dev libasound2-dev libdbus-1-dev python-dbus glib-2.0-dev libperl-dev libgtk2.0-dev
    apt-get -y install python alsa git gcc make autoconf libtool blueman bluez bluetooth libbluetooth-dev libfdk-aac-dev libsbc-dev libasound2-dev libdbus-1-dev python-dbus glib-2.0-dev libperl-dev libgtk2.0-dev

    #
    # Clone and build bluez-alsa
  3. @qcasey qcasey revised this gist Aug 28, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ Tested to be working on Armbian/Ubuntu/Debian images of the Orange Pi Zero, ODRO
    ## Auto-Install Script

    ```
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/a02665a5e3017e8855c1d9892fe4dec3ff3243c4/bt-a2dp-autoinstall.sh | sudo bash
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/2a3be1bc78e9ac30b744c2fdd332d035ac13d77d/bt-a2dp-autoinstall.sh | sudo bash
    ```

    cURL-ing to bash *can be* dangerous, in the event of a hack. Please ensure what [you're downloading first](https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/a02665a5e3017e8855c1d9892fe4dec3ff3243c4/bt-a2dp-autoinstall.sh).
  4. @qcasey qcasey revised this gist Aug 26, 2020. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions bt-a2dp-autoinstall.sh
    Original file line number Diff line number Diff line change
    @@ -41,15 +41,15 @@ fi
    if [ -f /etc/bluetooth/main.conf ]; then
    mv /etc/bluetooth/main.conf /etc/bluetooth/main.conf.old
    fi
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/main.conf > /etc/bluetooth/main.conf
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/07bea3ac973276723df70dd234f138b4bda31219/main.conf > /etc/bluetooth/main.conf

    #
    # Download and enable service files
    #
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/104a7aab866742d162926cc3082f2757574c1a92/a2dp-agent > /usr/local/bin/a2dp-agent
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/741c69d3f7e0c10b4b5b835a07b25936391df6ae/a2dp-playback.service > /etc/systemd/system/a2dp-playback.service
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/741c69d3f7e0c10b4b5b835a07b25936391df6ae/bt-agent-a2dp.service > /etc/systemd/system/bt-agent-a2dp.service
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/bluealsa.service > /etc/systemd/system/bluealsa.service
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/07bea3ac973276723df70dd234f138b4bda31219/a2dp-agent > /usr/local/bin/a2dp-agent
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/07bea3ac973276723df70dd234f138b4bda31219/a2dp-playback.service > /etc/systemd/system/a2dp-playback.service
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/07bea3ac973276723df70dd234f138b4bda31219/bt-agent-a2dp.service > /etc/systemd/system/bt-agent-a2dp.service
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/07bea3ac973276723df70dd234f138b4bda31219/bluealsa.service > /etc/systemd/system/bluealsa.service
    systemctl enable bt-agent-a2dp.service
    systemctl enable a2dp-playback.service
    systemctl enable bluealsa.service
  5. @qcasey qcasey revised this gist Jul 24, 2020. 2 changed files with 7 additions and 7 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -15,10 +15,10 @@ Tested to be working on Armbian/Ubuntu/Debian images of the Orange Pi Zero, ODRO
    ## Auto-Install Script

    ```
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/a02665a5e3017e8855c1d9892fe4dec3ff3243c4/bt-a2dp-autoinstall.sh | sudo bash
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/a02665a5e3017e8855c1d9892fe4dec3ff3243c4/bt-a2dp-autoinstall.sh | sudo bash
    ```

    cURL-ing to bash *can be* dangerous, in the event of a hack. Please ensure what [you're downloading first](https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/a02665a5e3017e8855c1d9892fe4dec3ff3243c4/bt-a2dp-autoinstall.sh).
    cURL-ing to bash *can be* dangerous, in the event of a hack. Please ensure what [you're downloading first](https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/a02665a5e3017e8855c1d9892fe4dec3ff3243c4/bt-a2dp-autoinstall.sh).

    ## Manual Setup
    First make sure the system is up to date using the following commands.
    10 changes: 5 additions & 5 deletions bt-a2dp-autoinstall.sh
    Original file line number Diff line number Diff line change
    @@ -41,15 +41,15 @@ fi
    if [ -f /etc/bluetooth/main.conf ]; then
    mv /etc/bluetooth/main.conf /etc/bluetooth/main.conf.old
    fi
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/main.conf > /etc/bluetooth/main.conf
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/main.conf > /etc/bluetooth/main.conf

    #
    # Download and enable service files
    #
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/104a7aab866742d162926cc3082f2757574c1a92/a2dp-agent > /usr/local/bin/a2dp-agent
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/741c69d3f7e0c10b4b5b835a07b25936391df6ae/a2dp-playback.service > /etc/systemd/system/a2dp-playback.service
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/741c69d3f7e0c10b4b5b835a07b25936391df6ae/bt-agent-a2dp.service > /etc/systemd/system/bt-agent-a2dp.service
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/bluealsa.service > /etc/systemd/system/bluealsa.service
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/104a7aab866742d162926cc3082f2757574c1a92/a2dp-agent > /usr/local/bin/a2dp-agent
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/741c69d3f7e0c10b4b5b835a07b25936391df6ae/a2dp-playback.service > /etc/systemd/system/a2dp-playback.service
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/741c69d3f7e0c10b4b5b835a07b25936391df6ae/bt-agent-a2dp.service > /etc/systemd/system/bt-agent-a2dp.service
    curl https://gist.githubusercontent.com/qcasey/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/bluealsa.service > /etc/systemd/system/bluealsa.service
    systemctl enable bt-agent-a2dp.service
    systemctl enable a2dp-playback.service
    systemctl enable bluealsa.service
  6. @qcasey qcasey revised this gist Oct 8, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ Tested to be working on Armbian/Ubuntu/Debian images of the Orange Pi Zero, ODRO
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/a02665a5e3017e8855c1d9892fe4dec3ff3243c4/bt-a2dp-autoinstall.sh | sudo bash
    ```

    cURL-ing to bash *can be* dangerous, in the event of a hack. Please ensure what [you're downloading first](https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/e92e362eca6a12c3e9d46daa6d0e841ad57c4b7e/bt-a2dp-autoinstall.sh).
    cURL-ing to bash *can be* dangerous, in the event of a hack. Please ensure what [you're downloading first](https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/a02665a5e3017e8855c1d9892fe4dec3ff3243c4/bt-a2dp-autoinstall.sh).

    ## Manual Setup
    First make sure the system is up to date using the following commands.
  7. @qcasey qcasey revised this gist Oct 8, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ Tested to be working on Armbian/Ubuntu/Debian images of the Orange Pi Zero, ODRO
    ## Auto-Install Script

    ```
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/e92e362eca6a12c3e9d46daa6d0e841ad57c4b7e/bt-a2dp-autoinstall.sh | sudo bash
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/a02665a5e3017e8855c1d9892fe4dec3ff3243c4/bt-a2dp-autoinstall.sh | sudo bash
    ```

    cURL-ing to bash *can be* dangerous, in the event of a hack. Please ensure what [you're downloading first](https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/e92e362eca6a12c3e9d46daa6d0e841ad57c4b7e/bt-a2dp-autoinstall.sh).
  8. @qcasey qcasey revised this gist Oct 8, 2019. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions bt-a2dp-autoinstall.sh
    Original file line number Diff line number Diff line change
    @@ -35,6 +35,14 @@ if [ -f bluealsa.service ]; then
    mv bluealsa.service bluealsa.service.old
    fi

    #
    # Backup old bluetooth conf if required, then download new configuration
    #
    if [ -f /etc/bluetooth/main.conf ]; then
    mv /etc/bluetooth/main.conf /etc/bluetooth/main.conf.old
    fi
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/main.conf > /etc/bluetooth/main.conf

    #
    # Download and enable service files
    #
    @@ -53,20 +61,12 @@ systemctl restart bt-agent-a2dp.service
    systemctl restart a2dp-playback.service
    systemctl restart bluealsa.service

    #
    # Backup old bluetooth conf if required, then download new configuration
    #
    if [ -f /etc/bluetooth/main.conf ]; then
    mv /etc/bluetooth/main.conf /etc/bluetooth/main.conf.old
    fi
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/main.conf > /etc/bluetooth/main.conf

    #
    # Done!
    #
    printf "\nDone!\nYour default Alsa sound card looks like:\n"
    printf "\n/etc/asound.conf\n"
    cat /etc/asound.conf
    printf "\n\nBluetooth should be running. You may need to restart to take effect.\nIf your Alsa sound card is properly set (see asound.conf above) audio should output correctly.\n"
    printf "\n\nBluetooth should be running. Please restart to take effect.\nIf your Alsa sound card is properly set (see asound.conf above) audio should output correctly.\n"
    printf "\nBy default the device will appear as 'BluetoothSpeaker'. This can be changed in /etc/bluetooth/main.conf.\n"
    printf "\nHave a nice rest of your day :)\n\n"
  9. @qcasey qcasey revised this gist Oct 8, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -15,10 +15,10 @@ Tested to be working on Armbian/Ubuntu/Debian images of the Orange Pi Zero, ODRO
    ## Auto-Install Script

    ```
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/bc29e3f20c8d28cb40ae021816b668ec5893e760/bt-a2dp-autoinstall.sh | sudo bash
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/e92e362eca6a12c3e9d46daa6d0e841ad57c4b7e/bt-a2dp-autoinstall.sh | sudo bash
    ```

    cURL-ing to bash *can be* dangerous, in the event of a hack. Please ensure what [you're downloading first](https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/bc29e3f20c8d28cb40ae021816b668ec5893e760/bt-a2dp-autoinstall.sh).
    cURL-ing to bash *can be* dangerous, in the event of a hack. Please ensure what [you're downloading first](https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/e92e362eca6a12c3e9d46daa6d0e841ad57c4b7e/bt-a2dp-autoinstall.sh).

    ## Manual Setup
    First make sure the system is up to date using the following commands.
  10. @qcasey qcasey revised this gist Oct 8, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions bt-a2dp-autoinstall.sh
    Original file line number Diff line number Diff line change
    @@ -39,8 +39,8 @@ fi
    # Download and enable service files
    #
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/104a7aab866742d162926cc3082f2757574c1a92/a2dp-agent > /usr/local/bin/a2dp-agent
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/104a7aab866742d162926cc3082f2757574c1a92/a2dp-playback.service > /etc/systemd/system/a2dp-playback.service
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/104a7aab866742d162926cc3082f2757574c1a92/bt-agent-a2dp.service > /etc/systemd/system/bt-agent-a2dp.service
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/741c69d3f7e0c10b4b5b835a07b25936391df6ae/a2dp-playback.service > /etc/systemd/system/a2dp-playback.service
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/741c69d3f7e0c10b4b5b835a07b25936391df6ae/bt-agent-a2dp.service > /etc/systemd/system/bt-agent-a2dp.service
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/bluealsa.service > /etc/systemd/system/bluealsa.service
    systemctl enable bt-agent-a2dp.service
    systemctl enable a2dp-playback.service
  11. @qcasey qcasey revised this gist Oct 8, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,11 @@ Tested to be working on Armbian/Ubuntu/Debian images of the Orange Pi Zero, ODRO

    ## Auto-Install Script

    TBA
    ```
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/bc29e3f20c8d28cb40ae021816b668ec5893e760/bt-a2dp-autoinstall.sh | sudo bash
    ```

    cURL-ing to bash *can be* dangerous, in the event of a hack. Please ensure what [you're downloading first](https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/bc29e3f20c8d28cb40ae021816b668ec5893e760/bt-a2dp-autoinstall.sh).

    ## Manual Setup
    First make sure the system is up to date using the following commands.
  12. @qcasey qcasey revised this gist Oct 8, 2019. 1 changed file with 72 additions and 0 deletions.
    72 changes: 72 additions & 0 deletions bt-a2dp-autoinstall.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    #!/bin/sh
    #
    # Update, install prereqs
    #
    apt-get update
    apt-get -y install alsa git gcc make autoconf libtool blueman bluez bluetooth libbluetooth-dev libfdk-aac-dev libsbc-dev libasound2-dev libdbus-1-dev python-dbus glib-2.0-dev libperl-dev libgtk2.0-dev

    #
    # Clone and build bluez-alsa
    #
    cd /tmp
    git clone https://github.com/Arkq/bluez-alsa
    cd bluez-alsa/
    autoreconf --install
    mkdir build && cd build
    ../configure --enable-aac --enable-ofono --enable-debug
    make && make install

    #
    # Backup old service files, if they exist
    #
    if [ -f /usr/local/bin/a2dp-agent ]; then
    mv /usr/local/bin/a2dp-agent /usr/local/bin/a2dp-agent.old
    fi
    if [ -f a2dp-playback.service ]; then
    systemctl disable a2dp-playback.service
    mv a2dp-playback.service a2dp-playback.service.old
    fi
    if [ -f bt-agent-a2dp.service ]; then
    systemctl disable bt-agent-a2dp.service
    mv bt-agent-a2dp.service bt-agent-a2dp.service.old
    fi
    if [ -f bluealsa.service ]; then
    systemctl disable bluealsa.service
    mv bluealsa.service bluealsa.service.old
    fi

    #
    # Download and enable service files
    #
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/104a7aab866742d162926cc3082f2757574c1a92/a2dp-agent > /usr/local/bin/a2dp-agent
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/104a7aab866742d162926cc3082f2757574c1a92/a2dp-playback.service > /etc/systemd/system/a2dp-playback.service
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/104a7aab866742d162926cc3082f2757574c1a92/bt-agent-a2dp.service > /etc/systemd/system/bt-agent-a2dp.service
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/bluealsa.service > /etc/systemd/system/bluealsa.service
    systemctl enable bt-agent-a2dp.service
    systemctl enable a2dp-playback.service
    systemctl enable bluealsa.service
    chmod +x /usr/local/bin/a2dp-agent

    printf "\nStarting services...\n"
    systemctl restart bluetooth
    systemctl restart bt-agent-a2dp.service
    systemctl restart a2dp-playback.service
    systemctl restart bluealsa.service

    #
    # Backup old bluetooth conf if required, then download new configuration
    #
    if [ -f /etc/bluetooth/main.conf ]; then
    mv /etc/bluetooth/main.conf /etc/bluetooth/main.conf.old
    fi
    curl https://gist.githubusercontent.com/MrDoctorKovacic/5bd4943b27320e65a033948fafb86d19/raw/9b9d99cd59332c9ee6b77e3999670b04549407fe/main.conf > /etc/bluetooth/main.conf

    #
    # Done!
    #
    printf "\nDone!\nYour default Alsa sound card looks like:\n"
    printf "\n/etc/asound.conf\n"
    cat /etc/asound.conf
    printf "\n\nBluetooth should be running. You may need to restart to take effect.\nIf your Alsa sound card is properly set (see asound.conf above) audio should output correctly.\n"
    printf "\nBy default the device will appear as 'BluetoothSpeaker'. This can be changed in /etc/bluetooth/main.conf.\n"
    printf "\nHave a nice rest of your day :)\n\n"
  13. @qcasey qcasey revised this gist Oct 8, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bt-agent-a2dp.service
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ After=bluetooth.service
    Wants=bluetooth.service

    [Service]
    ExecStartPre=/bin/sh -c "echo discoverable on | bluetoothctl"
    ExecStartPre=/bin/sh -c "echo power on | bluetoothctl && echo discoverable on | bluetoothctl"
    ExecStart=/usr/bin/python -u /usr/local/bin/a2dp-agent
    StandardOutput=syslog
    StandardError=syslog
  14. @qcasey qcasey revised this gist Oct 8, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion a2dp-playback.service
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,6 @@ ExecStart=/usr/bin/bluealsa-aplay --profile-a2dp 00:00:00:00:00:00
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=A2DP-Playback
    User=pi

    [Install]
    WantedBy=multi-user.target
  15. @qcasey qcasey revised this gist Oct 7, 2019. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ mkdir build && cd build
    make && sudo make install
    ```

    ## Make Bluetooth Discoverable
    ### Make Bluetooth Discoverable
    Normally a Bluetooth device is only discoverable for a limited amount of time. Since this is a headless setup we want the device to always be discoverable.

    1. Set the DiscoverableTimeout in `/etc/bluetooth/main.conf` to 0
    @@ -59,7 +59,7 @@ discoverable on
    exit
    ```

    ## Install The A2DP Bluetooth Agent
    ### Install The A2DP Bluetooth Agent
    A Bluetooth agent is a piece of software that handles pairing and authorization of Bluetooth devices. The following agent allows the Raspberry Pi to automatically pair and accept A2DP connections from Bluetooth devices.
    All other Bluetooth services are rejected.

    @@ -88,7 +88,7 @@ AuthorizeService (/org/bluez/hci0/dev_94_01_C2_47_01_AA, 0000111E-0000-1000-8000
    Rejecting non-A2DP Service
    ```

    ## Install The A2DP Bluetooth Agent As A Service
    ### Install The A2DP Bluetooth Agent As A Service
    To make the A2DP Bluetooth Agent run on boot copy the included file **bt-agent-a2dp.service** to `/etc/systemd/system`.
    Now run the following command to enable the A2DP Agent service
    ```
    @@ -98,7 +98,7 @@ Thanks to @matthijskooijman for fixing up some issues in the Bluetooth Agent ser

    Bluetooth devices should now be able to discover, pair and connect to the Raspberry Pi without any user intervention.

    ## Testing Audio Playback
    ### Testing Audio Playback
    Now that Bluetooth devices can pair and connect with the Raspberry Pi we can test the audio playback.

    The tool `bluealsa-aplay` is used to forward audio from the Bluetooth device to the ALSA output device (sound card).
  16. @qcasey qcasey revised this gist Oct 7, 2019. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    ## About
    This gist will show how to setup a generic SBC Debian / Ubuntu install as a headless Bluetooth A2DP audio sink. This will allow your phone, laptop or other Bluetooth device to play audio wirelessly through a Rasperry Pi.

    This is forked from another gist specific to the Raspberry Pi on Stretch. Several required packages aren't in Ubuntu's repos, so in this gist we build them from scratch.
    ## Motivation

    This is forked from another [gist specific to the Raspberry Pi on Stretch](https://gist.github.com/mill1000/74c7473ee3b4a5b13f6325e9994ff84c). A required package isn't in Ubuntu's repos, so in this gist we build it from scratch.

    Tested to be working on Armbian/Ubuntu/Debian images of the Orange Pi Zero, ODROID XU4, ODROID N2, and Atomic Pi.

    ## Prerequisites
    * A linux SBC running Debian or Ubuntu
    * Bluetooth Dongle or integrated Bluetooth.
    * Sound card (internal or external) that is known to work with Alsa.
    * Sound card (internal or external) that has been set up to work with Alsa.

    ## Auto-Install Script

  17. @qcasey qcasey revised this gist Oct 7, 2019. No changes.
  18. @qcasey qcasey revised this gist Oct 7, 2019. 1 changed file with 20 additions and 8 deletions.
    28 changes: 20 additions & 8 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -7,15 +7,14 @@ Tested to be working on Armbian/Ubuntu/Debian images of the Orange Pi Zero, ODRO

    ## Prerequisites
    * A linux SBC running Debian or Ubuntu
    * Bluetooth Dongle or integrated Bluetooth. Sound card (internal or external) that is known to work with Alsa.
    * Bluetooth Dongle or integrated Bluetooth.
    * Sound card (internal or external) that is known to work with Alsa.

    # Auto-Install Script
    ## Auto-Install Script

    TBA

    # Manually

    ## Initial Setup
    ## Manual Setup
    First make sure the system is up to date using the following commands.
    ```
    sudo apt-get update
    @@ -25,7 +24,18 @@ Then reboot the device to ensure the latest kernel is loaded.

    Now install the required packages.
    ```
    sudo apt-get install bluealsa python-dbus
    sudo apt-get install alsa git gcc make autoconf libtool blueman bluez bluetooth libbluetooth-dev libfdk-aac-dev libsbc-dev libasound2-dev libdbus-1-dev python-dbus glib-2.0-dev libperl-dev libgtk2.0-dev
    ```

    Change over to your /tmp directory, and clone then build another requirement.
    ```
    cd /tmp
    git clone https://github.com/Arkq/bluez-alsa
    cd bluez-alsa/
    autoreconf --install
    mkdir build && cd build
    ../configure --enable-aac --enable-ofono --enable-debug
    make && sudo make install
    ```

    ## Make Bluetooth Discoverable
    @@ -76,8 +86,6 @@ AuthorizeService (/org/bluez/hci0/dev_94_01_C2_47_01_AA, 0000111E-0000-1000-8000
    Rejecting non-A2DP Service
    ```

    If the Raspberry Pi is not recognized as a audio device, ensure that the bluealsa package was installed as part of the [Initial Setup](#initial-setup)

    ## Install The A2DP Bluetooth Agent As A Service
    To make the A2DP Bluetooth Agent run on boot copy the included file **bt-agent-a2dp.service** to `/etc/systemd/system`.
    Now run the following command to enable the A2DP Agent service
    @@ -106,6 +114,10 @@ Now run the following command to enable A2DP Playback service
    ```
    sudo systemctl enable a2dp-playback.service
    ```
    We also need to install bluealsa as a service, copy that to `/etc/systemd/system` as well and enable it.
    ```
    sudo systemctl enable bluealsa.service
    ```

    Reboot and enjoy!

  19. @qcasey qcasey revised this gist Oct 7, 2019. 3 changed files with 115 additions and 21 deletions.
    32 changes: 11 additions & 21 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,37 +1,27 @@
    ## About
    This gist will show how to setup Raspbian Stretch as a headless Bluetooth A2DP audio sink. This will allow your phone, laptop or other Bluetooth device to play audio wirelessly through a Rasperry Pi.
    This gist will show how to setup a generic SBC Debian / Ubuntu install as a headless Bluetooth A2DP audio sink. This will allow your phone, laptop or other Bluetooth device to play audio wirelessly through a Rasperry Pi.

    ## Motivation
    A quick search will turn up a plethora of tutorials on setting up A2DP on the Raspberry Pi. However, I felt this gist was necessary because this solution is:
    * Automatic & Headless - Once setup, the system is entirely automatic. No user iteration is required to pair, connect or start playback. Therefore the Raspberry Pi can be run headless.
    * Simple - This solution has few dependencies, readily available packages and minimal configuration.
    * Up to date - As of December 2017. Written for Raspbian Stretch & Bluez 5.43
    This is forked from another gist specific to the Raspberry Pi on Stretch. Several required packages aren't in Ubuntu's repos, so in this gist we build them from scratch.

    Tested to be working on Armbian/Ubuntu/Debian images of the Orange Pi Zero, ODROID XU4, ODROID N2, and Atomic Pi.

    ## Prerequisites
    * Raspbian Stretch - I used the Lite version as this is a headless setup. See the [official guide](https://www.raspberrypi.org/learning/software-guide/quickstart/) if you need help.
    * [Bluez-alsa](https://github.com/Arkq/bluez-alsa) - Available in the Raspbian package repo. This software allows us to stream A2DP audio over Bluetooth without PulseAudio.
    * Raspberry Pi with Bluetooth - The Raspberry Pi 3 has integrated Bluetooth, however there is a [known bug](https://github.com/raspberrypi/linux/issues/1402) when the WiFi is used simultaneously. Cheap USB Bluetooth dongles work equally well.
    * A linux SBC running Debian or Ubuntu
    * Bluetooth Dongle or integrated Bluetooth. Sound card (internal or external) that is known to work with Alsa.

    ## Disabling Integrated Bluetooth
    If you are using a separate USB Bluetooth dongle, disable the integrated Bluetooth to prevent conflicts.
    # Auto-Install Script

    To disable the integrated Bluetooth add the following
    ```
    # Disable onboard Bluetooth
    dtoverlay=pi3-disable-bt
    ```
    to `/boot/config.txt` and execute the following command
    ```
    sudo systemctl disable hciuart.service
    ```
    TBA

    # Manually

    ## Initial Setup
    First make sure the system is up to date using the following commands.
    ```
    sudo apt-get update
    sudo apt-get upgrade
    ```
    Then reboot the Pi to ensure the latest kernel is loaded.
    Then reboot the device to ensure the latest kernel is loaded.

    Now install the required packages.
    ```
    13 changes: 13 additions & 0 deletions bluealsa.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    [Unit]
    Description=BlueALSA Agent
    After=bluetooth.service
    Wants=bluetooth.service

    [Service]
    ExecStart=/bin/sh -c "bluealsa -p a2dp-source -p a2dp-sink"
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=BlueALSA-Agent

    [Install]
    WantedBy=bluetooth.service
    91 changes: 91 additions & 0 deletions main.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,91 @@
    [General]

    # Default adaper name
    # Defaults to 'BlueZ X.YZ'
    Name = BluetoothSpeaker

    # Default device class. Only the major and minor device class bits are
    # considered. Defaults to '0x000000'.
    Class = 0x200414

    # How long to stay in discoverable mode before going back to non-discoverable
    # The value is in seconds. Default is 180, i.e. 3 minutes.
    # 0 = disable timer, i.e. stay discoverable forever
    DiscoverableTimeout = 0

    # How long to stay in pairable mode before going back to non-discoverable
    # The value is in seconds. Default is 0.
    # 0 = disable timer, i.e. stay pairable forever
    #PairableTimeout = 0

    # Automatic connection for bonded devices driven by platform/user events.
    # If a platform plugin uses this mechanism, automatic connections will be
    # enabled during the interval defined below. Initially, this feature
    # intends to be used to establish connections to ATT channels. Default is 60.
    #AutoConnectTimeout = 60

    # Use vendor id source (assigner), vendor, product and version information for
    # DID profile support. The values are separated by ":" and assigner, VID, PID
    # and version.
    # Possible vendor id source values: bluetooth, usb (defaults to usb)
    #DeviceID = bluetooth:1234:5678:abcd

    # Do reverse service discovery for previously unknown devices that connect to
    # us. This option is really only needed for qualification since the BITE tester
    # doesn't like us doing reverse SDP for some test cases (though there could in
    # theory be other useful purposes for this too). Defaults to 'true'.
    #ReverseServiceDiscovery = true

    # Enable name resolving after inquiry. Set it to 'false' if you don't need
    # remote devices name and want shorter discovery cycle. Defaults to 'true'.
    #NameResolving = true

    # Enable runtime persistency of debug link keys. Default is false which
    # makes debug link keys valid only for the duration of the connection
    # that they were created for.
    #DebugKeys = false

    # Restricts all controllers to the specified transport. Default value
    # is "dual", i.e. both BR/EDR and LE enabled (when supported by the HW).
    # Possible values: "dual", "bredr", "le"
    #ControllerMode = dual

    # Enables Multi Profile Specification support. This allows to specify if
    # system supports only Multiple Profiles Single Device (MPSD) configuration
    # or both Multiple Profiles Single Device (MPSD) and Multiple Profiles Multiple
    # Devices (MPMD) configurations.
    # Possible values: "off", "single", "multiple"
    #MultiProfile = off

    # Permanently enables the Fast Connectable setting for adapters that
    # support it. When enabled other devices can connect faster to us,
    # however the tradeoff is increased power consumptions. This feature
    # will fully work only on kernel version 4.1 and newer. Defaults to
    # 'false'.
    #FastConnectable = false

    Enable=Source,Sink,Media,Socket

    [Policy]

    # The ReconnectUUIDs defines the set of remote services that should try
    # to be reconnected to in case of a link loss (link supervision
    # timeout). The policy plugin should contain a sane set of values by
    # default, but this list can be overridden here. By setting the list to
    # empty the reconnection feature gets disabled.
    #ReconnectUUIDs=00001112-0000-1000-8000-00805f9b34fb, 0000111f-0000-1000-8000-00805f9b34fb, 0000110a-0000-1000-8000-00805f9b34fb

    # ReconnectAttempts define the number of attempts to reconnect after a link
    # lost. Setting the value to 0 disables reconnecting feature.
    #ReconnectAttempts=7

    # ReconnectIntervals define the set of intervals in seconds to use in between
    # attempts.
    # If the number of attempts defined in ReconnectAttempts is bigger than the
    # set of intervals the last interval is repeated until the last attempt.
    #ReconnectIntervals=1, 2, 4, 8, 16, 32, 64

    # AutoEnable defines option to enable all controllers when they are found.
    # This includes adapters present on start as well as adapters that are plugged
    # in later on. Defaults to 'false'.
    AutoEnable=true
  20. @mill1000 mill1000 revised this gist Jul 9, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion bt-agent-a2dp.service
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,11 @@ After=bluetooth.service
    Wants=bluetooth.service

    [Service]
    ExecStartPre=/bin/sh -c "echo discoverable on | bluetoothctl"
    ExecStart=/usr/bin/python -u /usr/local/bin/a2dp-agent
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=A2DP-Agent

    [Install]
    WantedBy=multi-user.target
    WantedBy=bluetooth.service
  21. @mill1000 mill1000 revised this gist Jul 9, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -94,6 +94,7 @@ Now run the following command to enable the A2DP Agent service
    ```
    sudo systemctl enable bt-agent-a2dp.service
    ```
    Thanks to @matthijskooijman for fixing up some issues in the Bluetooth Agent service.

    Bluetooth devices should now be able to discover, pair and connect to the Raspberry Pi without any user intervention.

  22. @mill1000 mill1000 revised this gist Apr 11, 2019. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -68,6 +68,8 @@ sudo chmod +x /usr/local/bin/a2dp-agent

    ### Testing The Agent
    Before continuing, verify that the agent is functional. The Raspberry Pi should be discoverable, pairable and recognized as an audio device.

    Note: At this point the device will not output any audio. This step is only to verify the Bluetooth is discoverable and bindable.
    1. Manually run the agent by executing
    ```
    sudo /usr/local/bin/a2dp-agent
    @@ -114,4 +116,7 @@ Now run the following command to enable A2DP Playback service
    sudo systemctl enable a2dp-playback.service
    ```

    Reboot and enjoy!
    Reboot and enjoy!

    ## Low Volume Output
    If you are experiencing low volume output, run `alsamixer` and increase the volume of the Pi's soundcard.
  23. @mill1000 mill1000 renamed this gist Dec 8, 2017. 1 changed file with 0 additions and 0 deletions.
  24. @mill1000 mill1000 renamed this gist Dec 8, 2017. 1 changed file with 0 additions and 0 deletions.
  25. @mill1000 mill1000 renamed this gist Dec 8, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  26. @mill1000 mill1000 revised this gist Dec 8, 2017. 2 changed files with 28 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions a2dp-playback.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    [Unit]
    Description=A2DP Playback
    After=bluealsa.service syslog.service
    Requires=bluealsa.service

    [Service]
    ExecStartPre=/bin/sleep 3
    ExecStart=/usr/bin/bluealsa-aplay --profile-a2dp 00:00:00:00:00:00
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=A2DP-Playback
    User=pi

    [Install]
    WantedBy=multi-user.target
    13 changes: 13 additions & 0 deletions bt-agent-a2dp.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    [Unit]
    Description=A2DP Bluetooth Agent
    After=bluetooth.service
    Wants=bluetooth.service

    [Service]
    ExecStart=/usr/bin/python -u /usr/local/bin/a2dp-agent
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=A2DP-Agent

    [Install]
    WantedBy=multi-user.target
  27. @mill1000 mill1000 revised this gist Dec 8, 2017. 1 changed file with 99 additions and 0 deletions.
    99 changes: 99 additions & 0 deletions a2dp-agent
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    #!/usr/bin/python

    from __future__ import absolute_import, print_function, unicode_literals

    import sys
    import dbus
    import dbus.service
    import dbus.mainloop.glib
    try:
    from gi.repository import GObject
    except ImportError:
    import gobject as GObject

    AGENT_INTERFACE = "org.bluez.Agent1"
    AGENT_PATH = "/test/agent"

    class Rejected(dbus.DBusException):
    _dbus_error_name = "org.bluez.Error.Rejected"

    class Agent(dbus.service.Object):
    exit_on_release = True

    def set_exit_on_release(self, exit_on_release):
    self.exit_on_release = exit_on_release

    @dbus.service.method(AGENT_INTERFACE,
    in_signature="", out_signature="")
    def Release(self):
    print("Release")
    if self.exit_on_release:
    mainloop.quit()

    @dbus.service.method(AGENT_INTERFACE,
    in_signature="os", out_signature="")
    def AuthorizeService(self, device, uuid):
    print("AuthorizeService (%s, %s)" % (device, uuid))
    if uuid == "0000110d-0000-1000-8000-00805f9b34fb":
    print("Authorized A2DP Service")
    return
    print("Rejecting non-A2DP Service")
    raise Rejected("Connection rejected")

    @dbus.service.method(AGENT_INTERFACE,
    in_signature="o", out_signature="s")
    def RequestPinCode(self, device):
    print("RequestPinCode (%s)" % (device))
    return "0000"

    @dbus.service.method(AGENT_INTERFACE,
    in_signature="o", out_signature="u")
    def RequestPasskey(self, device):
    print("RequestPasskey (%s)" % (device))
    return dbus.UInt32("password")

    @dbus.service.method(AGENT_INTERFACE,
    in_signature="ouq", out_signature="")
    def DisplayPasskey(self, device, passkey, entered):
    print("DisplayPasskey (%s, %06u entered %u)" %
    (device, passkey, entered))

    @dbus.service.method(AGENT_INTERFACE,
    in_signature="os", out_signature="")
    def DisplayPinCode(self, device, pincode):
    print("DisplayPinCode (%s, %s)" % (device, pincode))

    @dbus.service.method(AGENT_INTERFACE,
    in_signature="ou", out_signature="")
    def RequestConfirmation(self, device, passkey):
    print("RequestConfirmation (%s, %06d)" % (device, passkey))
    return

    @dbus.service.method(AGENT_INTERFACE,
    in_signature="o", out_signature="")
    def RequestAuthorization(self, device):
    print("RequestAuthorization (%s)" % (device))
    raise Rejected("Pairing rejected")

    @dbus.service.method(AGENT_INTERFACE,
    in_signature="", out_signature="")
    def Cancel(self):
    print("Cancel")

    if __name__ == '__main__':
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    bus = dbus.SystemBus()

    agent = Agent(bus, AGENT_PATH)

    obj = bus.get_object("org.bluez", "/org/bluez");
    manager = dbus.Interface(obj, "org.bluez.AgentManager1")
    manager.RegisterAgent(AGENT_PATH, "NoInputNoOutput")

    print("A2DP Agent Registered")

    manager.RequestDefaultAgent(AGENT_PATH)

    mainloop = GObject.MainLoop()
    mainloop.run()
  28. @mill1000 mill1000 revised this gist Dec 8, 2017. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    This gist will show how to setup Raspbian Stretch as a headless Bluetooth A2DP audio sink. This will allow your phone, laptop or other Bluetooth device to play audio wirelessly through a Rasperry Pi.

    ## Motivation
    A quick search will turn up a plethora of tutorials on setting up A2DP on the Raspberry Pi. However, I felt this gist was necessary beacuse this solution is:
    A quick search will turn up a plethora of tutorials on setting up A2DP on the Raspberry Pi. However, I felt this gist was necessary because this solution is:
    * Automatic & Headless - Once setup, the system is entirely automatic. No user iteration is required to pair, connect or start playback. Therefore the Raspberry Pi can be run headless.
    * Simple - This solution has few dependencies, readily available packages and minimal configuration.
    * Up to date - As of December 2017. Written for Raspbian Stretch & Bluez 5.43
    @@ -33,7 +33,7 @@ sudo apt-get upgrade
    ```
    Then reboot the Pi to ensure the latest kernel is loaded.

    Now install the per-requisite packages.
    Now install the required packages.
    ```
    sudo apt-get install bluealsa python-dbus
    ```
    @@ -58,16 +58,16 @@ exit
    ```

    ## Install The A2DP Bluetooth Agent
    A Bluetooth agent is a piece of software that handles pairing and authorization of Bluetooth devices. The following agent allows the Raspberry Pi to automatically pair and accept A2DP connection from Bluetooth devices.
    A Bluetooth agent is a piece of software that handles pairing and authorization of Bluetooth devices. The following agent allows the Raspberry Pi to automatically pair and accept A2DP connections from Bluetooth devices.
    All other Bluetooth services are rejected.

    Copy the included file a2dp-agent to `/usr/local/bin` and make the file executable with
    Copy the included file **a2dp-agent** to `/usr/local/bin` and make the file executable with
    ```
    sudo chmod +x /usr/local/bin/a2dp-agent
    ```

    ### Testing The Agent
    Before continuing, we will verify that the agent is functional, and that the Raspberry Pi is discoverable and recognized as an audio device.
    Before continuing, verify that the agent is functional. The Raspberry Pi should be discoverable, pairable and recognized as an audio device.
    1. Manually run the agent by executing
    ```
    sudo /usr/local/bin/a2dp-agent
    @@ -84,10 +84,10 @@ AuthorizeService (/org/bluez/hci0/dev_94_01_C2_47_01_AA, 0000111E-0000-1000-8000
    Rejecting non-A2DP Service
    ```

    If the Raspberry Pi is not recognized as a audio device, ensure that the bluealsa package was installed as documented in [Initial Setup](#Initial-Setup)
    If the Raspberry Pi is not recognized as a audio device, ensure that the bluealsa package was installed as part of the [Initial Setup](#initial-setup)

    ## Install The A2DP Bluetooth Agent As A Service
    To make the A2DP Bluetooth Agent run on boot copy the included file bt-agent-a2dp.service to `/etc/systemd/system`.
    To make the A2DP Bluetooth Agent run on boot copy the included file **bt-agent-a2dp.service** to `/etc/systemd/system`.
    Now run the following command to enable the A2DP Agent service
    ```
    sudo systemctl enable bt-agent-a2dp.service
    @@ -98,17 +98,17 @@ Bluetooth devices should now be able to discover, pair and connect to the Raspbe
    ## Testing Audio Playback
    Now that Bluetooth devices can pair and connect with the Raspberry Pi we can test the audio playback.

    The tool `bluealsa-aplay` is used to forward audio from the Bluetooth device and forward it to the ALSA output device (sound card).
    The tool `bluealsa-aplay` is used to forward audio from the Bluetooth device to the ALSA output device (sound card).

    Execute the following command to accept A2DP audio from any connected Bluetooth device.
    ```
    bluealsa-aplay -vv 00:00:00:00:00:00
    ```

    Play a song on the Bluetooth device and the Raspberry Pi should be output audio on either the headphone jack or the HDMI port. See [this guide](https://www.raspberrypi.org/documentation/configuration/audio-config.md) for configuring the audio output device of the Raspberry Pi.
    Play a song on the Bluetooth device and the Raspberry Pi should output audio on either the headphone jack or the HDMI port. See [this guide](https://www.raspberrypi.org/documentation/configuration/audio-config.md) for configuring the audio output device of the Raspberry Pi.

    ### Install The Audio Playback As A Service
    To make the audio playback run on boot copy the included file a2dp-playback.service to `/etc/systemd/system`.
    To make the audio playback run on boot copy the included file **a2dp-playback.service** to `/etc/systemd/system`.
    Now run the following command to enable A2DP Playback service
    ```
    sudo systemctl enable a2dp-playback.service
  29. @mill1000 mill1000 revised this gist Dec 8, 2017. 1 changed file with 25 additions and 6 deletions.
    31 changes: 25 additions & 6 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,9 @@ A quick search will turn up a plethora of tutorials on setting up A2DP on the Ra
    * Up to date - As of December 2017. Written for Raspbian Stretch & Bluez 5.43

    ## Prerequisites
    * Raspberry Pi - I used the Raspberry Pi 3. The Pi 3 has integrated Bluetooth, however there is a [known bug](https://github.com/raspberrypi/linux/issues/1402) when the WiFi is used simultaneously.
    * Raspbian Stretch Lite - See the offical guide on how to install the latest Raspbian OS: https://www.raspberrypi.org/learning/software-guide/quickstart/
    * Raspbian Stretch - I used the Lite version as this is a headless setup. See the [official guide](https://www.raspberrypi.org/learning/software-guide/quickstart/) if you need help.
    * [Bluez-alsa](https://github.com/Arkq/bluez-alsa) - Available in the Raspbian package repo. This software allows us to stream A2DP audio over Bluetooth without PulseAudio.
    * Raspberry Pi with Bluetooth - The Raspberry Pi 3 has integrated Bluetooth, however there is a [known bug](https://github.com/raspberrypi/linux/issues/1402) when the WiFi is used simultaneously. Cheap USB Bluetooth dongles work equally well.

    ## Disabling Integrated Bluetooth
    If you are using a separate USB Bluetooth dongle, disable the integrated Bluetooth to prevent conflicts.
    @@ -83,16 +84,34 @@ AuthorizeService (/org/bluez/hci0/dev_94_01_C2_47_01_AA, 0000111E-0000-1000-8000
    Rejecting non-A2DP Service
    ```

    If the Raspberry Pi is not recognized as a audio device, ensure that the bluealsa package was installed as documented in the Initial Setup heading.
    If the Raspberry Pi is not recognized as a audio device, ensure that the bluealsa package was installed as documented in [Initial Setup](#Initial-Setup)

    ### Install A2DP Agent Service
    To make the A2Dp Agent run on boot copy the included file bt-agent-a2dp.service to `/etc/systemd/system`.
    ## Install The A2DP Bluetooth Agent As A Service
    To make the A2DP Bluetooth Agent run on boot copy the included file bt-agent-a2dp.service to `/etc/systemd/system`.
    Now run the following command to enable the A2DP Agent service
    ```
    sudo systemctl enable bt-agent-a2dp.service
    ```

    Bluetooth devices should now be able to discover, pair and connect to the Raspberry Pi without any user intervention.

    ## Testing Audio Playback
    Now that Bluetooth devices can pair and connect with the Raspberry Pi we can test the audio playback.

    > Written with [StackEdit](https://stackedit.io/).
    The tool `bluealsa-aplay` is used to forward audio from the Bluetooth device and forward it to the ALSA output device (sound card).

    Execute the following command to accept A2DP audio from any connected Bluetooth device.
    ```
    bluealsa-aplay -vv 00:00:00:00:00:00
    ```

    Play a song on the Bluetooth device and the Raspberry Pi should be output audio on either the headphone jack or the HDMI port. See [this guide](https://www.raspberrypi.org/documentation/configuration/audio-config.md) for configuring the audio output device of the Raspberry Pi.

    ### Install The Audio Playback As A Service
    To make the audio playback run on boot copy the included file a2dp-playback.service to `/etc/systemd/system`.
    Now run the following command to enable A2DP Playback service
    ```
    sudo systemctl enable a2dp-playback.service
    ```

    Reboot and enjoy!
  30. @mill1000 mill1000 revised this gist Dec 8, 2017. 1 changed file with 51 additions and 11 deletions.
    62 changes: 51 additions & 11 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -7,52 +7,92 @@ A quick search will turn up a plethora of tutorials on setting up A2DP on the Ra
    * Simple - This solution has few dependencies, readily available packages and minimal configuration.
    * Up to date - As of December 2017. Written for Raspbian Stretch & Bluez 5.43

    ## Pre-requisites
    ## Prerequisites
    * Raspberry Pi - I used the Raspberry Pi 3. The Pi 3 has integrated Bluetooth, however there is a [known bug](https://github.com/raspberrypi/linux/issues/1402) when the WiFi is used simultaneously.
    * Raspbian Stretch Lite - See the offical guide on how to install the latest Raspbian OS: https://www.raspberrypi.org/learning/software-guide/quickstart/

    ## Disabling Integrated Bluetooth
    If you are using a separate USB Bluetooth dongle, disbale the integrated Bluetooth to prevent conflicts.
    If you are using a separate USB Bluetooth dongle, disable the integrated Bluetooth to prevent conflicts.

    To disable the integrated Bluetooth
    Add the
    To disable the integrated Bluetooth add the following
    ```
    # Disable onboard Bluetooth
    dtoverlay=pi3-disable-bt
    ```
    to ``/boot/config.txt`` and execute the following command
    to `/boot/config.txt` and execute the following command
    ```
    sudo systemctl disable hciuart.service
    ```

    ## Initial Setup
    First execute the following commands to make sure the system is up to date.
    First make sure the system is up to date using the following commands.
    ```
    sudo apt-get update
    sudo apt-get upgrade
    ```
    Then reboot the Pi to ensure the latest kernal is loaded.
    Then reboot the Pi to ensure the latest kernel is loaded.

    Now install the pre-requisite packages.
    Now install the per-requisite packages.
    ```
    sudo apt-get install bluealsa python-dbus
    ```

    ## Make Bluetooth Discoverable
    Normally a Bluetooth device is only discoverable for a limited amount of time. Since this is a headless setup we want the device to always be discoverable.

    * Set the DiscoverableTimeout in ``/etc/bluetooth/main.conf`` to 0
    1. Set the DiscoverableTimeout in `/etc/bluetooth/main.conf` to 0
    ```
    # How long to stay in discoverable mode before going back to non-discoverable
    # The value is in seconds. Default is 180, i.e. 3 minutes.
    # 0 = disable timer, i.e. stay discoverable forever
    DiscoverableTimeout = 0
    ```

    * Enable discovery on the Bluetooth controller
    2. Enable discovery on the Bluetooth controller
    ```
    sudo bluetoothctl
    power on
    discoverable on
    exit
    ```
    ```

    ## Install The A2DP Bluetooth Agent
    A Bluetooth agent is a piece of software that handles pairing and authorization of Bluetooth devices. The following agent allows the Raspberry Pi to automatically pair and accept A2DP connection from Bluetooth devices.
    All other Bluetooth services are rejected.

    Copy the included file a2dp-agent to `/usr/local/bin` and make the file executable with
    ```
    sudo chmod +x /usr/local/bin/a2dp-agent
    ```

    ### Testing The Agent
    Before continuing, we will verify that the agent is functional, and that the Raspberry Pi is discoverable and recognized as an audio device.
    1. Manually run the agent by executing
    ```
    sudo /usr/local/bin/a2dp-agent
    ```
    2. Attempt to pair and connect with the Raspberry Pi using your phone or computer.
    3. The agent should output the accepted and rejected Bluetooth UUIDs
    ```
    A2DP Agent Registered
    AuthorizeService (/org/bluez/hci0/dev_94_01_C2_47_01_AA, 0000111E-0000-1000-8000-00805F9B34FB)
    Rejecting non-A2DP Service
    AuthorizeService (/org/bluez/hci0/dev_94_01_C2_47_01_AA, 0000110d-0000-1000-8000-00805f9b34fb)
    Authorized A2DP Service
    AuthorizeService (/org/bluez/hci0/dev_94_01_C2_47_01_AA, 0000111E-0000-1000-8000-00805F9B34FB)
    Rejecting non-A2DP Service
    ```

    If the Raspberry Pi is not recognized as a audio device, ensure that the bluealsa package was installed as documented in the Initial Setup heading.

    ### Install A2DP Agent Service
    To make the A2Dp Agent run on boot copy the included file bt-agent-a2dp.service to `/etc/systemd/system`.
    Now run the following command to enable the A2DP Agent service
    ```
    sudo systemctl enable bt-agent-a2dp.service
    ```

    Bluetooth devices should now be able to discover, pair and connect to the Raspberry Pi without any user intervention.


    > Written with [StackEdit](https://stackedit.io/).