Categories
Linux open source Raspberry Pi

Maintaining the Raspberry Pi Squeezebox server (aka Logitech Media Server)

I wrote earlier about the Logitech Media Server (LMS), open source software that I’ve used to turn a Raspberry Pi into a music server for my Squeezebox devices. I’m using my Raspberry Pi based Logitech Media Server a couple of months and I’ve grown very fond of it. What started as an experiment now has become a device I’m starting to rely on. I guess that eventually I have to replace the USB-HDD that I connected to the Raspberry Pi with a better one. In the meantime however I do need to maintain the LMS. In this blogpost I’ll explain how I add and remove music files from the LMS and create a simple backup of your music files. Finally I provide a tip to debug problems with the Logitech Media Server. All software that I used for this project is free and open source.

Adding, changing and deleting music files

When I buy a new CD I want to add it to my LMS. All the ripping is done using Asunder, a low resource ripper for Linux. Asunder has a simple interface but it has many options can encode to many different formats. It can also tag the files using CDDB but I use MusicBrainz Picard because does a much better job when it comes to tagging (in addition MusicBrainz can organize your digital music library). The tagger completes the metadata on the music files which is very convenient when uploading the files to the LMS. A simple example is that album art is added to the file.

Now about moving the encoded files to the LMS. At first I unmounted the USB hard disk from the LMS, removed it and connected it to the laptop and copied the albums. For adding new albums this proved to be be a clumsy method and I quickly found myself looking for an alternative.

I decided to use FTP to transfer files over the network to the Raspberry Pi. FTP is a network protocol to transfer files between a client and a server. The software that I’m using is either FileZilla or gFTP. They have basically the same functionality but gFTP is not available for Windows while FileZilla is available for GNU/Linux, OSX and Windows. Working with both is easy enough.

Later I also used the scp command (Linux, OSX) in the terminal and simply copy the music files on my PC to the music folder on my Raspberry Pi powered LMS.

Read this if you (like me) run into problems with file ownership on your Raspberry Pi. In the past I couldn’t set the ownership for the USB hard disk on the Raspberry Pi. Only root was able to write to the disk. The reason is a bit technical and maybe confusing but I had used the Windows FAT filesystem for the USB hard disk and when I mounted it on my Linux laptop (Puppy Linux distribution), ownership of all files was changed by Puppy Linux to root. At this point it was impossible to change ownership and permissions with chmod and chown from the media server. To solve this problem I had to first unmount and mount the USB hard disk. To mount the hard disk use the following general command is used:

mount device mount-point -o uid=foo -o gid=foo

or in my specific case

sudo umount ~/media/usb-drive

and then mount

sudo mount /dev/sda1 ~/media/usb-drive -o uid=pi -o gid=pi

This command sets the ownership of all files on the USB hard disk to pi instead of root enabling me to use FileZilla and gFTP to copy files from a remote PC to the Raspberry Pi.

Adding Podcasts to the server

Podcasts can be easily added to the Logitech Media Server and there is no need to subscribe to a service. First the Podcasts app must be added to myApps on the Squeezebox player or players. Next to add podcasts to the list a plugin needs to be installed. To do this open the web interface in your browser and type:

<your_Raspberry_Pi_ip_address:9000> (in my case 192.168.178.69:9000)

Choose Settings at the bottom right of the web browser and then choose the Plugins tab. Now enable the Podcasts (v2.0) plugin and reboot the Raspberry Pi for the changes to take effect. The Podcasts plugin is now active and can be entered through a new tab in the Settings menu. In this tab new feeds can be entered that will immediatly be available on the Squeezebox players. To find a certain feed look for the rss feed of your favorite podcast and copy the link into ‘add a new feed’ in the podcast tab of the Settings menu mentioned above (e.g. http://feed.thisamericanlife.org/talpodcast for This American Life).

Creating a backup of the music collection

I invested a lot of time in ripping my CD collection so it would be a shame if I lost my music files due to a hard disk crash. I therefore use a very simple backup method, largely copied from the Raspberrypi.org website to ensure that my files are safe. First make sure that there’s enough harddisk space available with df -h. Next do:

tar -cvf backup.tar.gz ~/media/usb-drive

This creates a file ‘backup.tar.gz’ that contains files in /media/usb-drive, the mounting point of my USB drive and places it in the same map. Next I use (again) Filezilla to move the backup file to my desktop computer. Alternatively the ripped files on the PC they were ripped on can serve as a backup.

Debug problems with the Logitech Media Server

I didn’t encounter much problems with the LMS but if you do take a look into the log file of the server. This can be done opening a terminal on your PC and login into the Rasperry Pi with:

ssh pi@<your_network_ip_address_of_the_server>
cat /var/log/squeezeboxserver/server.log

The sudo ssh command prompts for the password of the Raspberry Pi. Now look for anything suspicious in the log, copy it and do an internet search with your preferred search engine. Chances are someone already encountered the same problem.

Categories
Linux open source Raspberry Pi

Creating a Raspberry Pi Squeezebox Server

If you, like me, own one or more Squeezebox players you can either choose between the service mysqueezebox.com, that streams music from the internet, or set up the Squeezebox Server on your own network. The Squeezebox Server software (aka Logitech Media Software, aka Slimserver) being free and open source software guarantees that you’ll take control of your Squeezebox players and the music that you’re streaming.

There many hardware options for the Squeezebox Server software but I decided to use the Raspberry Pi 2 that I had lying around because of it’s small footprint and massive support for the Pi. Within a couple of hours I had the Logitech Squeezebox Server up an running with my music playing.

Below I’ll show how to set up the Logitech Squeezebox Server on a Raspberry Pi in five steps. I got some important steps from the Variax Firmation website but I tested everything successfully.

Raspberry Pi 2 with a USB-harddrive connected to my network with a (yellow) ethernet cable.
Raspberry Pi 2 with a USB-harddrive connected to my network with a (yellow) ethernet cable.

Step 1: Ripping CD’s and writing them on an HDD (choosing an audio format)

For this project I used a small USB-HDD that was also lying around. I formatted the HDD. Next I collected all my music CD’s and ripped them. As ripping software I used the Asunder software on my Linux laptop but I guess that there are good alternatives (fre:ac appears to be an free and open source alternative that is also available for OSX and Windows). As audio format I choose MP3. If I buy a larger drive I’ll probably move to FLAC.

Step 2: Installing Raspberry Pi OS

Next install Raspberry Pi OS (previously called Raspbian) on the Raspberry Pi by first downloading the image and writing the image to the micro SD card using these instructions for OSX (or these instructions for Windows and Linux). I chose the Lite version of Raspberry Pi OS because I don’t need the desktop software and it makes the server as lightweight as possible. I had no problems booting the Raspberry Pi and connecting it to my network using Ethernet. To avoid potential problems connect the Pi to a monitor with an HDMI cable and make sure that it boots properly.

NOTE: If you do install the Lite version of the OS make sure to enable SSH via raspi-config. This enables you to access the Pi remotely later on.

Step 3: Mount the HDD on the Raspberry Pi

Now with Raspberry Pi OS installed I mounted the HDD that we prepared in step 1. For this first connect the HDD to the Raspberry Pi (in my case I connected the HDD through a USB port of the Raspberry Pi), login remotely and retrieve the name of the drive. To login remotely we need another computer (Windows, Linux or OSX). Open a terminal (Windows users either need to install Putty or for Windows 10 users enable the SSH client) and type:

sudo ssh pi@Raspberry_Pi_ip_address (in my case 192.168.178.69)

The default password is raspberry. Then type:

sudo fdisk -l 

Then look for the HDD that is just connected. This was /dev/sda1 in my case (but this may differ in yours). To make the files on the HDD accessible to the Raspberry Pi we need mount the drive. But before that we need to make a mounting point (in this example at ~/media/usb-drive).

sudo mkdir ~/media/usb-drive 

and mount

 sudo mount /dev/sda1 ~/media/usb-drive

You should hear some HDD activity. Now type:

cd ~/media/usb-drive && ls -l

and a list of your music should be visible.
To unmount the HDD do:

sudo umount ~/media/usb-drive
 The list of folders with albums that I ripped. In this stage I only ripped a few albums to test the system.
The list of folders with albums that I ripped. In this stage I only ripped a few albums to test the system (click to enlarge).

Step 4: Installing Logitech Media Center on the Raspberry Pi

First we need to install a library to play audio files. Since you want mp3 only do:

sudo apt-get install -y libsox-fmt-all

This installs SoX, a command line utility that, among other things, plays various types of audio files. If you want to add flac support you’ll probably need to do this

sudo apt-get install -y libsox-fmt-all libflac-dev

Now with the audio libraries in place the Logitech Media Software can be downloaded. We want the latest version which at the moment of this writing is 7.9.3.

sudo wget -O logitechmediaserver_all.deb $(wget -q -O - "http://www.mysqueezebox.com/update/?version=7.9.3&revision=1&geturl=1&os=deb")

Now install the server software with:

sudo dpkg -i logitechmediaserver_all.deb

And reboot. With all the software installed we’re ready to go.

NOTE: with a recent fresh install of both Raspberry Pi OS (formerly Raspbian) and Logitech Media Server 7.9.3 a problem occurred. Apt complained about some unmet dependencies. However after apt –fix-missing update all problems were solved and after a reboot the server worked as before.

Step 5: Working with Logitech Media Center

To enter the web interface of the Logitech Media Center on the Pi we need a computer and a browser. In the browser URL we type:

<your_Raspberry_Pi_ip_address:9000> (in my case 192.168.178.69:9000)

The Logitech Media Center is started for the first time and a script is started to set it up. Important is that the mounting point of the HDD (in my case ~/media/usb-drive) is entered. This way the Media Center is able to retrieve all the music files. This is done in the web interface by entering the path of the mounting point under Media Settings under Media Folders.

The Media Settings page of the web interface. Enter the path of the mounting point under Media Folders.
The Media Settings page of the web interface. Enter the path of the mounting point under Media Folders (click to enlarge).

The Logitech Media Server is now ready and every time the Raspberry Pi boots the Logitech Media Server is automatically started however the HDD is not automatically mounted so we need to change that. This is done by editing (with nano) the fstab system configuration file that can be found at /etc/fstab

sudo nano fstab

and add the following line

/dev/sda1 /media/usb-drive vfat& defaults 0

Save the file and exit nano. Reboot the Raspberry Pi. Now the installation is complete.

The music can be controlled from the web interface (see above), with the remote controls that come with the Squeezebox devices, with apps for Android such as this one or with iPeng for iOS. The Squeezebox Radio and the Squeezebox Boom also have controls on the device to play the music. So, plenty of options.

Webinterface of the Logitech Media Server (click to enlarge).

Step 6: Change the web interface to Material Skin (optional)

The default web interface of the Logitech Media Server looks outdated. Luckily, thanks to the plugin architecture, the server and its user interface are highly customizable. In the list of third party plugins of the default web interface you’ll find the Material Skin plugin (an excellent community effort led by CDrummond). Enable this plugin, select it and voila the web interface looks awesome.

Logitech Media Server with the beautiful Material Skin (click to enlarge).

What’s next

In a future blog entry I’ll explain how to maintain the Logitech Media Server e.g how to add music to the server remotely.

Categories
amplifier electronics Linux Raspberry Pi

Adding radio streams to the cooler with a Raspberry Pi

Introduction

In my previous blog post I finished my audio cooler. It’s a small cooler with a tiny audio system that nevertheless sounds good. The only way to control the audio is through a wired connection. It would be a nice addition to have some kind of remote control either by WiFi or Bluetooth. While testing the cooler I’ve got the idea to connect a Raspberry Pi A+, that was still unused, to the cooler and stream audio over WiFi to the Pi.  This could be useful for a garden party or BBQ where WiFi is available and I don’t want to attach the smartphone to the cooler. In this blog post I’ll share my experience with installation and operating the software needed for this project on the Pi.

P1020957
Raspberry Pi A+ (in it’s Pimoroni Pibow case) connected with the headphone jack to the cooler. The Pi has a small Edimax Wifi adapter.

Installing music software on the Raspberry Pi

Since I run the Raspberry Pi headless I use SSH login to the Pi. SSH is available for most operating systems with the notable exception of Windows. I already had Raspbian installed on the Pi so first I updated the OS.

Categories
Raspberry Pi woodworking

Plywood housing for the homemade surveillance camera

In the last two weeks I have built a Raspberry Pi surveillance camera. For the time being I used a crude housing made out of MDF. This was ok for testing purposes but now I wanted something more permanent. Something that I could attach to my window frame and that is able to pan and tilt to get the best angle at my backyard. I could buy of camera housing such as the ModMyPi Nwazet Pi Camera or buy a dummy camera and build the surveillance camera in it. However building it myself would be more fun. I decided on a housing made out of plywood since it is cheap, strong and durable.

The Raspberry Pi surveillance camera keeping an eye on my backyard.

The housing is rectangular box that nevertheless looks like a camera due to the round placeholder of the camera. I used 1/2 inch thick plywood for the body of the housing and 1/4 inch thick plywood for the lid and bottom plate. The camera module is placed between two pieces of plywood, that keep it in place. The two pieces are tight together with two machine screws. I used spacers to prevent the module from being squeezed when tightening the machine screws.

Housing of the surveillance camera
The front of the housing lifted showing the Raspbery Pi B mounted on the 1/4 inch plywood bottom.  
The camera module is easily removed from the front.

I left an opening in the camera housing to have easy access to the micro-USB connector and the SD-card.
the Raspberry Pi camera module between two pieces of 1/4 inch plywood kept together with two machine screws.

The camera housing is connected to a plywood frame that enables me to pan and tilt it. The frame is also made out of 1/2 inch thick plywood. The three pieces are glued together and two 1/4 inch machine screws (one on the top of the housing and one on the bottom) connect the frame with the housing. Two wing nuts are used to tighten the camera enabling the camera to pan. The frame is connected to the wall with cylindrical piece of wood (from a broom stick). Two pieces of plywood at the end of this pieces of wood enable the camera to tilt (see image below).

The finished surveillance camera. The mount will be fitted to our window frame. The camera can be panned and tilted to get the best view of my backyard.

With the housing and mount complete my Raspberry Pi surveillance camera is finished. Motion has been very stable on the Pi. I haven’t had a crash or malfunction in three weeks. And thanks to crontab the camera doesn’t need a lot of maintenance. Is there something left to be desired? Yes. The camera is not usable at night (I need the NoIr camera and IR lights for that) and I have false positives e.g. when it rains (the raindrops on the window are causing this) other than that I’m pleased with the result.

Categories
Linux Raspberry Pi

Raspberry Pi security camera, first experience

Introduction

Last week I wrote about the Raspberry Pi, the camera module and Motion acting as a surveillance camera. I’ve been testing my Raspberry Pi surveillance camera for a week now and the results are satisfying although there are also some problems. I think much of the succes of the camera comes down to finding the best settings of the /etc/motion.conf file of Motion for a given scenario. The motion.conf file enables you to setup the Motion program. Everything from camera settings to motion detection can be changed in this file.

Image from a motion video. If someone (in this case my son) is entering our backyard it is perfectly recorded by Motion.

Threshold

I want my surveillance camera to record anyone entering my backyard but this sounds easier than it is. If the threshold parameter in motion.conf is too low all kinds of events are recorded that are completely irrelevant. E.g. on a rainy day raindrops falling on the window are recorded. With higher threshold values I might miss something relevant. After experimenting with different values of the threshold I found that a value of 1500 works best in my case.

Lens flare

On a sunny day bright sunlight can fall onto the camera lens causing lens flare. This reduced contrast and color saturation (see image below). More importantly the Motion program detect changes in lens flare as motion and records them. I think problem can easily be solved with some kind of lens hood.

Lens flare caused by sunlight reducing contrast and color saturation.

 

Night

A whole different problem is motion detection at night. My camera, the regular Raspberry Pi camera module, is just not up to this task. For detection at night I’ll need the NoIR Pi camera. This camera has no infrared filter. As a consequence colours at daylight look odd but you’re able to record at night, but only with infrared light illuminating the subjects. Several add-on boards for the NoIR Pi camera are on the market that do just that. These boards fit right over the camera module.

The regular Raspberry Pi camera module is useless at night.

Proper file permissions

I created a directory /home/pi/Camera on the Raspberry Pi. I want all my video files to be stored in this place however before Motion is able to do this I had to change the permissions. Motion (the Program) creates it’s own user motion so this user needs proper permission in the home/pi/Camera folder (that is created by the user pi). To do this I first changed the group ownership of the folder:

chgrp motion /home/pi/Camera

And next give the group the proper permission:

chmod g+rwx /home/pi/Camera 

Scheduled tasks

The number of motion video’s that are stored on the Pi increase rapidly over the days. My backyard is quiet but not that quiet (not to mention the false positive that I described above). Since the Raspberry Pi stores the files on an SD card I will easily run out of storage space. So I need a method to remove the files automatically e.g after five days. Cron is perfect for this since it let me schedule commands or scripts periodically. I wrote a shell script that removes avi files created by Motion older than five days and added this to my crontab file to be executed daily. The key command in this script is:

find /home/pi/Camera -mtime +5 -name “*.avi” -exec rm {} ;

Copying files to a PC

Whenever I want to check the motion files (e.g after one day) I copy them to my iMac using scp from the OSX terminal and then created a playlist in VLC by dragging all the files into it. The harvest of that one day is then displayed.

scp pi@192.168.178.27:Camera/*.avi to/destination/folder

What’s next

Next I’ll test the surveillance camera further until I’m satisfied with the settings and build a proper housing for the camera. Possibly I will switch from the regular camera module to the NoIR camera.

Categories
Linux Raspberry Pi

Homemade security camera with a Raspberry Pi

One week ago we’ve had a burglar in our house. Of course I immediately started improving the security of our home. After improving the usual stuff I felt the need for some kind of security camera. This camera could provide me a good view of the backyard which is a very quiet place and therefore preferred by burglars. Because I like to make things myself I thought it was a good idea to use a Raspberry Pi and it’s camera module. I used them in the past for time-lapse video’s of scenery but I hadn’t used it much lately.

The goal that I had set was a camera that detects and records motion and that I could access through our local network preferably a browser. I also wanted the camera to give decent images by day and night.

Hardware.

The heart of the system is a Raspberry Pi B with the Raspberry camera module. Furthermore I use an Edimax dongle for my Wi-Fi connection and a micro-USB power supply (1A). Initially I use an MDF case that I made to fit the camera and the Pi. It isn’t pretty but it protects both the camera and the Pi. If everything works as planned I probably built it into a dummy camera such as this one or may make a wooden enclosure myself.

Initially I had some problems connecting to the Pi through SSH. I discovered that this was caused by the Edimax dongle (8192cu Wi-Fi chip) that apparently goes into sleep mode after a period of inactivity. This was solved with a command line fix that disables power saving (see here on page 17 how to fix this).

Raspberry Pi in DIY camera case made of MDF.

Software

On top of Raspbian I installed Motion. Motion is a Linux program that monitors the video signal from camera’s and, very important to me, is able to detect motion. Motion is widely used and there is plenty of good information on it on the internet. A simple tutorial how to install Motion specifically on the Raspberry Pi and get it to work with the Raspberry camera module can be found on here (go to step 7 for software installation). However Motion has far more possibilities and it is worthwhile to explore these once you start using it.

Configuring and testing the system

Motion can support multiple camera’s but I’ll stick to one camera for now. Configuration of Motion for the Raspberry Pi and it’s camera module is done in the /etc/motion.conf file (not in the /etc/motion/motion.conf file). There is a very good YouTube tutorial on configuring Motion for Linux here and here. At this point I made only a few changes to the motion.conf file such as camera width and height, directory where the video is stored on the Pi and some camera specific variables.

The camera works great. The image quality is good and the system appears to be stable. I can open a stream of the security camera in my browser by entering the URL of the Raspberry Pi and the selected port (default 8081). My motion files are stored as avi’s on the Raspberry Pi. I can play them with VLC media player on my iMac. Next I’ll experiment with the settings of Motion (e.g. sensitivity of motion detection, resolution of the camera), test in under different circumstances (indoor, outdoor, night and day) and build a proper housing for the security camera.

The finished security camera