Daniel, 2017-09-10

Lichee Pi Zero - Adding Audio Output and a webserver


Shortly after having written the last post, I noticed the missing support for SMB/Cifs which turned out to come from missing kernel features. So I downloaded the linaro cross-compile toolchain and cloned the Lichee Pi linux git, added support for Cifs and ALSA, compiled the kernel and copied it over to the Lichee Pi. The kernel version running is now 4.10.15.

To temporarily get around the missing 3.5mm audio jack I soldered one on using 2.54mm pins as spacers. This will be removed later in order to add an audio amplifier. Due to the Lichee Pi's 1.27mm pin spacing it is possible to solder one half of pins facing downwards and the other facing upwards. This little pcb is very space-efficiently designed, it is even breadboard compatible.

All the compiled kernel features work without problems. The SMB share through the local LAN is mounted at boot, audio could be played after creating /etc/asound.conf as follows:


pcm.!default {
type hw
card 1
device 0
}
ctl.!default {
type hw
card 1
}



After adding the pi user to the audio group it was possible to play music through the CLI using MPlayer. Time to install a webserver (lighttpd) alongside PHP and MySQL, a basic LLMP stack. After running


apt-get install lighttp php5-cgi php5-mysql



and verifying that the website is served and PHP if working (with phpinfo()), the only missing piece was the mysql server. It installed fine with


apt-get install mysql-server-5.5



but wouldn't start successfully. Lacking RAM was obviously the first suspect, and my suspicion was confirmed when I had a look at the mysql logs. After several adjustments to /etc/mysql/my.cnf it still wouldn't start, even with innodb disabled and MyISAM used instead. I decided not to waste more time on it and installed sqlite3, which will be more than enough to hold song and playlist tables.


PHP up and running



Controlling playback and song choices is possible with MPlayer by starting it in slave mode with a FIFO to simply write commands to a file in order to pass them on to MPlayer. After creating a FIFO with


mkfifo /tmp/mplayer
mplayer -slave -quiet -input file=/tmp/mplayer



it is time to get to the meat of the project: An attractive and responsive music player interface with SMB/CIFS support, playlists and possibly some scraping for album arts etc. This will be covered in the next post(s). I will have to see what is possible and what not, the very limited RAM might cause more trouble in the future. In normal operation I have around 6MB RAM and 100MB swap available, this could be improved by removing unneeded components, but websites were much simpler when 64MB RAM were the norm.