Music server in a car
- Install Raspberry Pi OS Lite
- Config
- Test a MP3 sound sample
- OwnTone
- OwnTone and Pulseaudio
- Setting up a Raspberry Pi as a routed wireless access point
- AirPlay audio player
- Shutdown via web
- Debug
- Install Raspberry Pi OS using Raspberry Pi Imager (ISO is downloaded with the app)
- Raspberry Pi Documentation
- Setting up a Raspberry Pi headless
- SSH (Secure Shell)
- Copy
./boot/ssh
file to the SD Card/boot
folder alias rpi='ssh [email protected]'
alias xcarlink='ssh [email protected]'
- Connection (default password:
raspberry
) - SSH USING iOS
- Copy
Custom aliases
(host) scp ./home/pi/.bash_aliases [email protected]:~/.bash_aliases
Updating and upgrading Raspberry Pi OS
sudo apt update
sudo apt full-upgrade
sudo apt install vim
sudo raspi-config
- System Options
- S2 Audio: 3.5mm jack
- S3 Password: ChangeMe
- S4 Hostname: xcarlink
- Localisation Options
- L2 Timezone: Europe/Paris
- L4 WLAN Country: FR
- Advanced Options
- A1 Expand Filesystem
- Update
sudo apt autoremove
sudo reboot
- Install package to read mp3
sudo apt update && sudo apt install mpg123
- Copy sound sample
mkdir -p ~/music
(host) scp ./srv/music/*.mp3 [email protected]:~/music
sudo mv ~/music /srv/music
sudo chown -R root:root /srv/music
- Test sound
mpg123 /srv/music/sample.mp3
- Add repository key
wget -q -O - http://www.gyfgafguf.dk/raspbian/owntone.gpg | sudo apt-key add -
- Add this line to
/etc/apt/sources.list
sudo cp /etc/apt/sources.list /etc/apt/sources.list.org
echo "deb http://www.gyfgafguf.dk/raspbian/owntone/ buster contrib" | sudo tee -a /etc/apt/sources.list
- Run
sudo apt update && sudo apt install owntone
- Edit the configuration file to suit your needs
sudo cp /etc/owntone.conf /etc/owntone.conf.org
sudo vim /etc/owntone.conf
L32 admin_password = ""
L76 name = "My Music on XCarlink"
L227 nickname = "XCarlink"
L230 type = "pulseaudio"
L235 server = "localhost"
- Start or restart the server
sudo service owntone restart
sudo service owntone status
- Wait for the library scan to complete. You can follow the progress with
tail -f /var/log/owntone.log
If you are going to use a remote app, pair it by going to http://owntone.local:3689 and find the settings
System Mode with Bluetooth support
- Install packages
sudo apt update && sudo apt install pulseaudio pulseaudio-module-bluetooth ofono
- Remove client execution
sudo cp /etc/pulse/client.conf /etc/pulse/client.conf.org
sudo vim /etc/pulse/client.conf
L25 autospawn = no
mkdir -p $HOME/.config/pulse
cp /etc/pulse/client.conf $HOME/.config/pulse/client.conf
- Start Pulseaudio on boot
sudo vim /etc/systemd/system/pulseaudio.service
Copy/Paste ./etc/systemd/system/pulseaudio.service
- Bluetooth support, add lines
sudo cp /etc/pulse/system.pa /etc/pulse/system.pa.org
sudo vim /etc/pulse/system.pa
#### Enable Bluetooth
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover autodetect_mtu=yes
.endif
- Make Pulseaudio communicates with the Bluetooth daemon through D-Bus
sudo adduser pulse audio
sudo adduser pulse bluetooth
- Edit and change the policy for
<policy context="default">
fromdeny
toallow
sudo cp /etc/dbus-1/system.d/bluetooth.conf /etc/dbus-1/system.d/bluetooth.conf.org
sudo vim /etc/dbus-1/system.d/bluetooth.conf
L40 <allow send_destination="org.bluez"/>
Add lines:
<policy context="default">
<allow send_destination="org.ofono"/>
</policy>
- Restart the bus
sudo service dbus restart
sudo service dbus status
- Enable system mode on boot
sudo systemctl --user stop pulseaudio.service pulseaudio.socket
sudo systemctl --global disable pulseaudio.service pulseaudio.socket
sudo systemctl enable bluetooth
sudo systemctl enable ofono
sudo systemctl enable pulseaudio
sudo reboot
- Check that the Bluetooth module is loaded
pactl list modules short | grep -i bluetooth
- Add the user the server is running
sudo adduser root pulse-access
sudo adduser pulse pulse-access
- Restart and check the logs
sudo service pulseaudio restart
sudo service pulseaudio status
journalctl -u pulseaudio.service
To connect with the device, run bluetoothctl
and then:
power on
agent on
scan on
**Note MAC address of BT Speaker**
pair [MAC address]
**Type Pin if prompted**
trust [MAC address]
connect [MAC address]
Now the speaker should appear. You can also verify that Pulseaudio has detected the speaker with
pactl list sinks short
- Install the access point and network management software
sudo apt update && sudo apt install hostapd
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo apt update && sudo apt install dnsmasq
sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent
- Set up the network router
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.org
sudo vim /etc/dhcpcd.conf
Add lines:
interface wlan0
static ip_address=10.0.0.1/8
nohook wpa_supplicant
- Enable routing and IP masquerading (Skipped)
- Configure the DHCP and DNS services for the wireless network
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.org
sudo vim /etc/dnsmasq.conf
Copy/Paste ./etc/dnsmasq.conf
- Test configuration file
dnsmasq --test -C /etc/dnsmasq.conf
- Restart service
sudo service dnsmasq restart
sudo service dnsmasq status
- Ensure wireless operation
sudo rfkill unblock wlan
- Configure the access point software
sudo vim /etc/hostapd/hostapd.conf
Copy/Paste ./etc/hostapd/hostapd.conf
- Run your new wireless access point
sudo service hostapd restart
sudo service hostapd status
Debug mode
sudo systemctl stop hostapd
sudo hostapd -dd /etc/hostapd/hostapd.conf
- Configure and Update
sudo apt update && sudo apt upgrade
- Turn Off WiFi Power Management
sudo iwconfig wlan0 power off
- Remove Old Copies
which shairport-sync
sudo rm /usr/local/bin/shairport-sync
sudo rm /etc/systemd/system/shairport-sync.service
sudo rm /lib/systemd/system/shairport-sync.service
sudo rm /etc/init.d/shairport-sync
sudo rm /etc/dbus-1/system.d/shairport-sync-dbus.conf
sudo rm /etc/dbus-1/system.d/shairport-sync-mpris.conf
- Reboot after Cleaning Up
sudo reboot
- Build and Install
sudo apt install --no-install-recommends build-essential git xmltoman autoconf automake libtool libpopt-dev libconfig-dev libasound2-dev avahi-daemon libavahi-client-dev libssl-dev libsoxr-dev
cd && mkdir -p src && cd src
git clone https://github.com/mikebrady/shairport-sync.git && cd shairport-sync
autoreconf -fi
./configure --sysconfdir=/etc --with-alsa --with-soxr --with-avahi --with-ssl=openssl --with-systemd
make
sudo make install
- Configure
sudo vim /etc/shairport-sync.conf
// Sample Configuration File for Shairport Sync on a Raspberry Pi using the built-in audio DAC
general =
{
volume_range_db = 60;
};
alsa =
{
output_device = "hw:0";
mixer_control_name = "PCM";
};
- Start Shairport Sync on boot
sudo service shairport-sync enable
sudo service shairport-sync start
sudo service shairport-sync status
- Install packages
sudo apt update && sudo apt install lighttpd php-cgi
sudo lighty-enable-mod fastcgi fastcgi-php
sudo service lighttpd force-reload
- Edit the sudoers file
sudo visudo
# Add the following line below "pi ALL etc." and exit the visudo editor:
www-data ALL = NOPASSWD: /sbin/shutdown
(^s, ^x)
- Create index.html
sudo vim /var/www/html/index.html
# Absolute minimum contents of the index.html file:
<html><a href="shutdown.php">Shutdown XCarlink NOW</a></html>
- Create php function to shutdown
sudo vim /var/www/html/shutdown.php
# Absolute minimum contents of the shutdown.php file:
<?php system('sudo /sbin/shutdown -h now'); ?>
- Test
(host) curl xcarlink.local/shutdown.php
- Services
sudo service owntone status
sudo service pulseaudio status
sudo service shairport-sync status
sudo service dbus status
sudo service dnsmasq status
sudo service hostapd status
- Logs
tail -f /var/log/owntone.log
journalctl -u pulseaudio.service
- Check that no pulseaudio in user mode is running
sudo ps -aux | grep pulse
- Pulseaudio in debug mode
sudo service pulseaudio stop
sudo pulseaudio -vvvv
sudo service pulseaudio restart