From: Mike Brady Date: Sun, 11 Mar 2018 18:12:49 +0000 (+0000) Subject: Update CAR INSTALL.md X-Git-Tag: 3.2d29~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf68cc7bc29c2b63702853e5867f22b32b3a36a0;p=thirdparty%2Fshairport-sync.git Update CAR INSTALL.md --- diff --git a/CAR INSTALL.md b/CAR INSTALL.md index f022f7b0..8b0e6149 100644 --- a/CAR INSTALL.md +++ b/CAR INSTALL.md @@ -1,14 +1,9 @@ # Shairport Sync for Cars - -At the moment, this is just a mess of notes, probably omitting some important steps, with some slightly incorrect information... More later... - -If your car audio has an AUX IN, you can get AirPlay in your car using Shairport Sync. AirPlay and an iPhone gives you access to internet radio, YouTube, Apple Music, Spotify, etc. on the move. While it's no substitute for CarPlay, the audio quality delivered by Sahirport Sync is often much better than Bluetooth. Your passengers can enjoy movies using the car audio for the sound track. You can even listen to Siri's traffic directions on your car audio. - -In this example, we are assuming that a Raspberry Pi Zero W and a Pimoroni PHAT DAC are used. +If your car audio has an AUX IN, you can get AirPlay in your car using Shairport Sync. AirPlay and an iPhone gives you access to internet radio, YouTube, Apple Music, Spotify, etc. on the move. While Shairport Sync is not a substitute for CarPlay, the audio quality is often much better than Bluetooth. Your passengers can enjoy movies listening to th soound track on the car audio. You can even listen to Siri's traffic directions on your car audio. The Basic Idea ===== -The basic idea is to use the Pi to create an isolated local WiFi network for the car and to run Shairport Sync on it to provide an AirPlay service. The audio goes via the DAC to the AUX IN of your car stereo. +The basic idea is to use a small Linux computer to create an isolated WiFi network for the car and to run Shairport Sync on it to provide an AirPlay service. The audio goes via a DAC to the AUX IN of your car stereo. The car network is isolated and local to your car, and since it isn't connected to the internet, you don't really need to secure it with a password. Likewise, you don't really have to use a password to connect to the AirPlay service. @@ -17,46 +12,124 @@ This means it can connect to internet radio, YouTube, Apple Music, Spotify, etc. Note that Android devices can not, so far, do this trick of using the two networks simultaneously. -Details +Example ===== -* Install Stretch Lite -* Update & Upgrade -* Install `hostapd`, `isc-dhcp-server`, `htop` -* Configure the network interfaces to disable the wpa supplicant and to add a static definition for `wlan0`: +In this example, we are using a Raspberry Pi Zero W and a Pimoroni PHAT DAC are used. This combination has been tested for well over a year. Please note that some of the details of setting up networks are specific to the version of Linux used. In particular, Stretch's treatment of networks is different from Jessie. +* Download the latest version of Raspbian Lite -- this is Stretch Lite of 2017-11-29 at the time of writing -- and install it onto an SD Card. +* Mount the card on a Linux machine. Two drives should appear -- a `boot` drive and a `rootfs` drive. Both of these need a little modification. +* Enable SSH service by creating a file called `ssh` on the boot drive. To do this, mount the drive and CD to its `boot` partiton (since my username is `mike`, the drive is at `/media/mike/boot`): +``` +$ touch ssh +``` +* Also in the `boot` drive, edit the `config.txt` file to add the overlay needed for the sound card. This may not be necessary in your case, but in this example, a Pimoroni PHAT is being used, and it needs the following entry to be added: +``` +dtoverlay=hifiberry-dac +``` +* Next, some modifications need to be done to the `rootfs` drive to make the Pi connect to your main WiFi network. )This is a temporary measure to enable you to connect the Pi to your main network so that you can do all the software installation and updating of the software necessary. Later, the Pi will be configured to start its own isolated network.) Edit the file `/etc/wpa_supplicant/wpa_supplicant.conf` (you'll need root priviliges) and add the name and password of your main WiFi network (substitute your own network name and password in, but keep the quotation marks): ``` -allow-hotplug wlan0 -#iface wlan0 inet manual -# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf +network={ + ssid="Network Name" + psk="Password" +} -allow-hotplug wlan1 -#iface wlan1 inet manual -# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf +``` +Close the file and carefully dismount and eject the two drives. Remove the SD card from the Linux machine, insert it into the Pi and reboot. After a short time, the Pi should appear on your network and you can SSH into it. To check that it has appeared on the network, try to ping it at `raspberrypi.local`. It may take a minute or so to appear. Once it has appeared on your network you can SSH into it and configure it. -... +First thing to do on a Pi would be to use the `raspi-config` tool to expand the file system to use the entire card. It might be useful to change the `hostname` too. Next, do the usual update and upgrade: +``` +# apt-get update +# apt-get upgrade +# rpi-update +``` +Next, install Shairport Sync. Install the packages needed by Shairport Sync: +``` +# apt-get install build-essential git xmltoman autoconf automake libtool libdaemon-dev libpopt-dev libconfig-dev libasound2-dev avahi-daemon libavahi-client-dev libssl-dev +``` +Next, download Shairport Sync, configure it, compile and install it: +``` +$ git clone https://github.com/mikebrady/shairport-sync.git +$ cd shairport-sync +$ autoreconf -fi +$ ./configure --sysconfdir=/etc --with-alsa --with-avahi --with-ssl=openssl --with-systemd +$ make +$ sudo make install +``` +This is a stripped-down set of options. In particular, SoX interpolaton is not included, as the Pi Zero would not be fast enough. *Do not* enable Shairport Sync to autormatially start at boot time -- startup will be taken care of differently. -iface wlan0 inet static -address 10.0.10.1 -netmask 255.255.255.0 -#gateway +Here are the important options for the Shairport Sync configuration file at `/etc/shairport-sync.conf`: ``` -* Configure hostapd by editing `/etc/hostapd/hostapd.conf` +// Sample Configuration File for Shairport Sync for Car Audio with a Pimoroni PHAT + +// General Settings +general = +{ + name = "BMW Radio"; + ignore_volume_control = "yes"; + volume_max_db = -3.00; +}; + +// These are parameters for the "alsa" audio back end, the only back end that supports synchronised audio. +alsa = +{ + output_device = "hw:1"; // the name of the alsa output device. Use "alsamixer" or "aplay" to find out the names of devices, mixers, etc. + output_format = "S32"; // can be "U8", "S8", "S16", "S24" or "S32", with be LE or BE depending on the processor, but the device must be capable of it +}; + +``` +Two `general` settings are worth noting. First, the option to ignore the sending device's volume control is enabled -- this means that the car audio's volume control is the only one that matters. Of course this is a matter of personal preference. +Second, the maximum output offered to the AUX port of the radio can be reduced if it is overloading the circuits. Again, that's a matter for personal selection and adjustment. + +The `alsa` settings are specific to the Pimoroni PHAT -- it does not have a hardware mixer and it does have a 32-bit capability which is worth enabling. + +Next, a number of packages that will enable the Pi to work as a WiFi base station are needed: + +``` +# apt-get install hostapd isc-dhcp-server +``` +Disable both of these services from starting at boot time (this is because we will launch them sequentially later on): +``` +# systemctl disable hostapd +# systemctl disable isc-dhcp-server +``` +Now, allow `wlan0` to be configurred with a static IP number by first removing it from the control of the `dhcpcp` service. Edit `/etc/dhcpcp.conf` and insert the following line at the start: + +``` +denyinterfaces wlan0 +``` + +* Configure DHCP server in the follwing two steps. +First, replace the contents of `/etc/dhcp/dhcpd.conf` with this: -(From https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/) ``` +subnet 10.0.10.0 netmask 255.255.255.0 { + range 10.0.10.5 10.0.10.150; + #option routers ; + #option broadcast-address ; +} +``` + +Second, modify the INTERFACESv4 entry at the end of the file `/etc/default/isc-dhcp-server` to look as follows: +``` +INTERFACESv4="wlan0" +INTERFACESv6="" +``` +Configure `hostapd` by creating `/etc/hostapd/hostapd.conf` with the following contents to give an open network with the name BMW. You might wish to change the name: + +``` # This is the name of the WiFi interface we configured above interface=wlan0 # Use the nl80211 driver with the brcmfmac driver driver=nl80211 -# This is the name of the network -ssid="Shairport Sync on Tour" +# This is the name of the network -- yours might be different +ssid=BMW # Use the 2.4GHz band hw_mode=g # Use channel 6 -channel=3 +channel=9 # Enable 802.11n ieee80211n=1 @@ -71,46 +144,56 @@ wmm_enabled=1 macaddr_acl=0 # Use WPA authentication -auth_algs=1 +#auth_algs=1 # Require clients to know the network name ignore_broadcast_ssid=0 # Use WPA2 -wpa=2 +#wpa=2 # Use a pre-shared key -wpa_key_mgmt=WPA-PSK +#wpa_key_mgmt=WPA-PSK # The network passphrase -wpa_passphrase=roadgoing +#wpa_passphrase=none # Use AES, instead of TKIP -rsn_pairwise=CCMP -``` - -* Configure dhcp server by editing `/etc/dhcp/dhcpd.conf` to look like this: - -``` -subnet 10.0.10.0 netmask 255.255.255.0 { - range 10.0.10.5 10.0.10.150; - #option routers ; - #option broadcast-address ; -} -``` +#rsn_pairwise=CCMP -* Edit `/etc/default/isc-dhcp-server` and add: ``` -INTERFACES="wlan0" +Next add commands to `/etc/rc.local` to start the `hostapd` service and then to start `shairport-sync` automatically after startup. Its contents should look like this: ``` +#!/bin/sh -e +# +# rc.local +# +# This script is executed at the end of each multiuser runlevel. +# Make sure that the script will "exit 0" on success or any other +# value on error. +# +# In order to enable or disable this script just change the execution +# bits. +# +# By default this script does nothing. + +# Print the IP address +_IP=$(hostname -I) || true +if [ "$_IP" ]; then + printf "My IP address is %s\n" "$_IP" +fi -Build Shairport Sync in the normal way, and do the `# make install` step, but do not enable it to autostart -- -it will be started by a command in `/etc/rc.local` after the other services it needs have been started up. - -Add the following into `/etc/rc.local`: - -``` /usr/sbin/hostapd -B -P /run/hostapd.pid /etc/hostapd/hostapd.conf -/usr/sbin/dhcpd -q -cf /etc/dhcp/dhcpd.conf -pf /var/run/dhcpd.pid wlan0 +/sbin/ifconfig wlan0 10.0.10.1 netmask 255.255.255.0 +sleep 1 +/bin/systemctl start isc-dhcp-server +sleep 2 /bin/systemctl start shairport-sync + +exit 0 ``` +As you can see, the effect of these commands is to start the WiFi transmitter, give the base station the IP address `10.0.10.1`, start a DHCP server to give devices a local IP number in the range 10.0.10.5 to 10.0.10.150 and finally start the Shairport Sync service. + +Install the Raspberry Pi in your car. It should be powered from a source that is switched off when you leave the car, otherwise the slight current drain will eventually flatten the battery. + +When the power source is switched on, typically when you start the car, it will take maybe a minute for the system to boot up.