Headless - project-owner/PeppyPlayers.doc GitHub Wiki
Here is the description of the Headless Mode.
This disk image has the following software and configuration:
-
Raspbian Lite OS (release date depends on player release)
-
pip3 Python3 package management utility.
-
Eject Linux utility, required for CD Player.
-
Audio signal level set to 80% using amixer.
-
Pygame library, required for UI.
-
Patched libsdl1.2 to fix touchscreen issues.
-
RPi.GPIO library, required for Rotary Encoders, python3-serial for serial interface, python3-smbus for I2C interface.
-
Tornado Web Server (required for Web UI). Web Server enabled by default.
-
ALSA Plugin peppyalsa, required for VU Meter and Spectrum Analyzer screensavers.
-
LIRC/PyLIRC, patched for using with Python 3, configured for using with WD TV Live IR remote control, disabled in /boot/config.txt
-
Library discogs_client, required for retrieving CD album art.
-
Library bluealsa, required for configuring Bluetooth devices as ALSA devices.
-
Library pynanosvg, required for displaying SVG vector images.
-
Library libasound2-plugin-equal, required for Equalizer functionality.
-
Library feedparser, required for parsing podcasts feeds.
-
Library pexpect, required for connecting Bluetooth devices.
-
Library Pillow, required for image manipulations.
-
Version control system git, required for installing software from GitHub.
-
The following media players were installed and configured:
- vlc - VLC media player 3.0.8 Vetinari. This is the default player.
- mpd - Music Player Daemon 0.21.5. Configured for pi user.
- mpv - mpv 0.29.1
-
shairport-sync, required to support streaming via AirPlay.
-
raspotify, required to support streaming via Spotify Connect.
-
sqlite3 - command line tool for SQLite database.
-
rpi-backlight - this library allows to control DSI Display Backlight.
-
pyudev - the library for handling USB disks mounting/unmounting.
-
udisks2 - the library to poweroff USB hard drives.
-
pyown, Python binding for the OpenWeather API, required for the Weather Screensaver.
-
samba, samba-common-bin - the libraries for the file sharing functionality.
-
youtube-dl - the library for handling YouTube data.
-
pafy - the library for fetching information from YouTube video metadata.
-
psutil - the library for collecting host computer information (CPU, Memory, Disks etc.).
-
yahooquery - the library for the Yahoo! Finance API.
-
python3-serial - the library for devices connected through serial interface.
-
sounddevice - the dependency library for Vosk.
-
vosk - the voice assistant library.
-
beautifulsoup4 - the library for parsing HTML pages (required for the Horoscope screensaver).
-
internetarchive - the official API library for the Internet Archive.
-
The patched version of the ALSA library libasound.so.2.0.0 was built and installed. The patch allows to enable VU Meter screensavers.
-
Peppy Player configured to start as a service. Peppy Player configured to work in Headless Mode. In this mode it can be controlled from Web UI, IR remote control and voice commands.
Hardware required for the Headless Disk Image:
- Any computer or mobile device with Web Browser to control Peppy Player via Web UI.
Here are the steps which were used to create the Headless Disk Image.
- Download the latest Raspberry Pi OS Lite disk image from the Raspberry Pi web site.
- Write downloaded disk image to 8GB MicroSD card.
- Copy empty file 'ssh' to the root of the boot folder.
- Insert a MicroSD card to a Raspberry Pi, power on, login using putty (user: pi, password: raspberry)
Run commands:
sudo apt-get update
sudo apt-get upgrade
sudo reboot
Run raspi-config utility:
sudo raspi-config
Select and configure the following options (can be different location/wording):
- System Options / Password
- System Options / Boot/Auto Login / Console Autologin
- System Options / Network at Boot
- Advanced Options/ Expand Filesystem
- Interface Options/I2C Enable/Yes
reboot
- Run 'alsamixer'
- Set Headphone to 20
- Connect powered speakers to audio output (3.5mm connector)
- Run command:
speaker-test -t wav
or
aplay -D hw /usr/share/sounds/alsa/Side_Left.wav
aplay -D hw /usr/share/sounds/alsa/Side_Right.wav
This step is required to fix the bug in the ALSA library. Without this fix there is about 40 seconds delay between stations when peppyalsa plugin is in use. More details can be found here. The bug will be fixed in ALSA version 2.1.
Run the following command to define the ALSA version:
$ aplay --version
aplay: version 1.1.8 by Jaroslav Kysela <[email protected]>
Run the following commands for ALSA 1.8 to setup ALSA project:
sudo apt-get install libasound2-dev libncursesw5-dev -y
wget ftp://ftp.alsa-project.org/pub/utils/alsa-utils-1.1.8.tar.bz2
tar xvjf alsa-utils-1.1.8.tar.bz2
cd alsa-utils-1.1.8
./configure --disable-alsaconf --disable-bat --disable-xmlto --with-curses=ncursesw
make && sudo make install
cd ..
wget ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.1.8.tar.bz2
tar xvjf alsa-lib-1.1.8.tar.bz2
cd alsa-lib-1.1.8
./configure
Change the lines starting at line#1101 in file src/pcm/pcm_meter.c from:
if (size < 0)
size += spcm->boundary;
to:
if (size < 0) {
s16->old = meter->now;
return;
}
Run commands:
make
sudo make install
sudo mv /usr/lib/libasound.so.2.0.0 /usr/lib/arm-linux-gnueabihf/
speaker-test -t wav
cd ..
rm -rf alsa*
These steps are required to run the player under pi user instead of root user.
Add user pi to the tty group:
sudo usermod -a -G tty pi
Change access rights:
sudo nano /lib/udev/rules.d/50-udev-default.rules
from:
SUBSYSTEM=="tty", KERNEL=="tty[0-9]*", GROUP="tty", MODE="0620"
to
SUBSYSTEM=="tty", KERNEL=="tty[0-9]*", GROUP="tty", MODE="0660"
sudo apt-get install python3-pip
sudo apt-get install vlc
pip3 install python-vlc
sudo apt-get install mpd
sudo apt-get install mpc
sudo service mpd stop
sudo update-rc.d mpd disable
sudo systemctl disable mpd
sudo systemctl disable mpd.socket
sudo systemctl disable mpd.service
sudo rm /usr/lib/systemd/user/mpd.service
sudo rm /etc/xdg/autostart/mpd.desktop
sudo chown pi /usr/bin/mpd
sudo chgrp audio /usr/bin/mpd
mkdir -p /home/pi/.config/mpd/playlists
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/mpd.conf
mv mpd.conf ~/.config/mpd
sudo apt-get install mpv
sudo apt-get install libmpv1
pip3 install python-mpv
sudo iwconfig wlan0 power off
sudo apt-get install build-essential git xmltoman autoconf automake libtool libpopt-dev libconfig-dev libasound2-dev avahi-daemon libavahi-client-dev libssl-dev libsoxr-dev libglib2.0-dev
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 --with-metadata --with-dbus-interface
make
sudo make install
cd ..
rm -rf shairport-sync
sudo apt install python3-gi
Edit the configuration file:
sudo nano /etc/shairport-sync.conf
Edit the following parameters:
name = "Peppy Player"; // name of the client
enabled = "yes"; // set this to yes to get Shairport Sync to solicit metadata from the source and to pass it on via a pipe
include_cover_art = "yes";
cover_art_cache_directory="" // to disable image caching
output_device = "hw:Headphones"; // the name of the alsa output device. Use "alsamixer" or "aplay" to find out the names of devices, mixers, etc.
mixer_control_name = "Headphone"; // the name of the mixer to use to adjust output volume. If not specified, volume in adjusted in software.
Stop service:
sudo systemctl stop shairport-sync
sudo systemctl disable shairport-sync
Change User and Group from 'shairport-sync' to 'pi' in file /usr/lib/systemd/system/shairport-sync.service:
[Service]
ExecStart=/usr/local/bin/shairport-sync
User=pi
Group=pi
Change user from 'shairport-sync' to 'pi' in file /etc/dbus-1/system.d/shairport-sync-dbus.conf:
<!-- Allow users "root" and "shairport-sync" to own the Shairport Sync service -->
<policy user="root">
<allow own="org.gnome.ShairportSync"/>
</policy>
<policy user="pi">
<allow own="org.gnome.ShairportSync"/>
</policy>
curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
Edit configuration file:
sudo nano /etc/default/raspotify
Set properties:
DEVICE_NAME="Peppy Player"
BITRATE="320"
Stop service:
sudo systemctl stop raspotify
sudo systemctl disable raspotify
sudo apt-get update
sudo apt-get install samba samba-common-bin
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudo systemctl stop smbd
sudo systemctl disable smbd
sudo apt-get install python-dbus
wget https://gist.githubusercontent.com/mill1000/74c7473ee3b4a5b13f6325e9994ff84c/raw/104a7aab866742d162926cc3082f2757574c1a92/a2dp-agent
wget https://gist.githubusercontent.com/mill1000/74c7473ee3b4a5b13f6325e9994ff84c/raw/104a7aab866742d162926cc3082f2757574c1a92/bt-agent-a2dp.service
sudo mv a2dp-agent /usr/local/bin
sudo mv bt-agent-a2dp.service /etc/systemd/system
sudo systemctl enable bt-agent-a2dp.service
sudo systemctl start bt-agent-a2dp.service
sudo systemctl stop bt-agent-a2dp.service
Create the file:
sudo nano /etc/machine-info
with content:
PRETTY_HOSTNAME=Peppy Player
Run the command:
rfkill unblock bluetooth
sudo apt-get install python3-pygame
wget https://www.dropbox.com/s/0tkdym8ojhcmbu2/libsdl1.2debian_1.2.15+veloci1-1_armhf.deb
sudo dpkg -i libsdl1.2debian_1.2.15+veloci1-1_armhf.deb
sudo apt-get -f install
rm libsdl1.2debian_1.2.15+veloci1-1_armhf.deb
sudo apt-get install libasound2-plugin-equal
git clone https://github.com/project-owner/peppyalsa.git
cd peppyalsa
sudo apt-get install build-essential autoconf automake libtool libasound2-dev libfftw3-dev
aclocal && libtoolize
autoconf && automake --add-missing
./configure && make
sudo make install
cd ..
rm -rf peppyalsa
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/alsa-config/.asoundrc
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/alsa-config/.asoundrc-equal
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/alsa-config/.asoundrc-equal-peppyalsa
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/alsa-config/.asoundrc-multi
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/alsa-config/.asoundrc-peppyalsa
sudo apt-get install eject
sudo apt-get install bluealsa
sudo apt-get install sqlite3
sudo apt-get install udisks2
sudo apt install python3-smbus
sudo apt-get install python3-serial
pip3 install tornado
pip3 install RPi.GPIO
pip3 install discogs_client
pip3 install pynanosvg
pip3 install feedparser
pip3 install mutagen
pip3 install pexpect
pip3 install Pillow
pip3 install rpi-backlight
pip3 install pyudev
pip3 install pyowm
pip3 install youtube-dl==2020.12.2
pip3 install pafy
pip3 install numpy -U
pip3 install psutil
pip3 install yahooquery
pip3 install vosk sounddevice
pip3 install beautifulsoup4
pip3 install -U requests
pip3 install internetarchive
To avoid root user for rpi-backlight:
echo 'SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rulesecho 'SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rules
Create named pipes:
mkfifo myfifo
mkfifo myfifosa
Create folders:
mkdir /home/pi/music
mkdir /home/pi/podcasts
mkdir /home/pi/collection
mkdir /home/pi/playlists
git clone https://github.com/project-owner/Peppy.git
Enable the Headless mode:
nano Peppy/config.txt
set property:
headless = True
Copy changed file to the defaults:
cp Peppy/config.txt Peppy/defaults/
Get the service file from Github:
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/peppy.service
Move the service file to the system folder:
sudo mv peppy.service /etc/systemd/system
Refresh service daemon and enable player as a service:
sudo systemctl daemon-reload
sudo systemctl enable peppy.service
sudo nano /boot/config.txt
Add the line:
#dtoverlay=gpio-poweroff,active_low,gpiopin=4
sudo mkdir /usr/lib/alsa-lib/
sudo cp /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_equal.so /usr/lib/alsa-lib/
sudo cp /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_ctl_equal.so /usr/lib/alsa-lib/
sudo cp /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_bluealsa.so /usr/lib/alsa-lib/
sudo apt-get install lirc
Edit LIRC configuration file:
sudo nano /etc/lirc/lirc_options.conf
Change properties:
driver = default
device = /dev/lirc0
Edit system configuration file:
sudo nano /boot/config.txt
Add property:
dtoverlay=gpio-ir,gpio_pin=23
Copy configuration files and poweroff:
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/lircd.conf
sudo mv lircd.conf /etc/lirc/lircd.conf.d
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/hardware.conf
sudo mv hardware.conf /etc/lirc
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/lircrc
sudo mv lircrc /etc/lirc
sudo poweroff
Switch power off and connect IR sensor to GPIO2 (+5v) connector pin #2, GPIO6 (GND) connector pin #14 and GPIO23 (signal) connector pin #16. To test run the command and press buttons on the remote control:
sudo mode2 -d /dev/lirc0
sudo apt-get install python3-dev
sudo apt-get install liblircclient-dev
wget https://files.pythonhosted.org/packages/a9/e1/a19ed9cac5353ec07294be7b1aefc8f89985987b356e916e2c39b5b03d9a/pylirc2-0.1.tar.gz
tar xvf pylirc2-0.1.tar.gz
cd pylirc2-0.1
rm pylircmodule.c
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/pylircmodule.c
sudo python3 setup.py install
sudo mv /usr/local/lib/python3.7/dist-packages/pylircmodule.cpython-37m-arm-linux-gnueabihf.so /usr/local/lib/python3.7/dist-packages/pylirc.cpython-37m-arm-linux-gnueabihf.so
cd ..
sudo rm -rf pylirc*
To test:
wget https://raw.githubusercontent.com/project-owner/Peppy.doc/master/files/test-pylirc.py
python3 test-pylirc.py
After test:
rm test-pylirc.py
Edit the system configuration file to disable LIRC:
sudo nano /boot/config.txt
Comment out the property:
#dtoverlay=gpio-ir,gpio_pin=23
Power off
sudo poweroff