Skip to content

Instantly share code, notes, and snippets.

@ggirou
Last active April 30, 2020 20:08
Show Gist options
  • Save ggirou/78b5705a4bc3384617c39544a8f9628d to your computer and use it in GitHub Desktop.
Save ggirou/78b5705a4bc3384617c39544a8f9628d to your computer and use it in GitHub Desktop.
Raspberry pi bluetooth speaker
hciconfig
hciconfig hci0 up
hciconfig hci0 reset
# Scan for Bluetooth devices
hcitool scan
sudo apt-get update
# RPI non-Zero
sudo apt-get install -y bluez pulseaudio pulseaudio-module-bluetooth
# RPI Zero
sudo apt-get install bluealsa mpg123
sudo service bluealsa start
sudo bluetoothctl
# in console [bluetooth]#
agent on
default-agent
scan on
# wait for your device to show and make it discoverable
trust YOURMACADR
pair YOURMACADR
connect YOURMACADR
quit
# RPI non-Zero
pulseaudio -k
pulseaudio -D
# look for bluez card
pacmd list-cards
# look for bluez card
pacmd set-default-sink bluez_sink.xx_xx_xx_xx_xx_xx
pacmd set-card-profile bluez_sink.xx_xx_xx_xx_xx_xx a2dp_sink
# RPI Zero
# aplay -D bluealsa:HCI=hci0,DEV=XX:XX:XX:XX:XX:XX,PROFILE=a2dp /usr/share/sounds/alsa/*
cat <<EOF > ~/.asoundrc
defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "XX:XX:XX:XX:XX:XX"
defaults.bluealsa.profile "a2dp"
defaults.bluealsa.delay 10000
EOF
aplay -D bluealsa /usr/share/sounds/alsa/*
# mpg123 -a bluealsa test.mp3
#!/bin/bash
MAC_ADDRESS=78:44:05:96:3D:EE
MAC_ADDRESS_=`echo $MAC_ADDRESS | tr ':' '_'`
# a2dp_sink, headset_head_unit, off
PROFIL=a2dp_sink
bluetoothctl <<-EOF
agent on
default-agent
trust $MAC_ADDRESS
pair $MAC_ADDRESS
connect $MAC_ADDRESS
EOF
sleep 2
pacmd list-cards
pacmd set-card-profile bluez_card.$MAC_ADDRESS_ $PROFIL
pacmd set-default-sink bluez_sink.$MAC_ADDRESS_.$PROFIL
pacmd set-default-source bluez_source.$MAC_ADDRESS_.$PROFIL
@ggirou
Copy link
Author

ggirou commented Oct 27, 2017

Pulseaudio comes with one modulo to switch automagically to last device connected.

Try to gives this command to pulseaudio (or enable it in pulse.conf)

pactl load-module module-switch-on-connect.

I think KODI must be set to Alsa device output (or pulse)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment