Raspberry-Car-Pi

Building a mobile stand-alone media server

Hans Weda
The Startup
10 min readJan 16, 2021

--

Image by tookapic from Pixabay

Early 2006, Las Vegas — Nevada, USA, I listened to the keynote speech of an innovation manager from the BBC. He spoke at ICCE conference, which precedes the famous Consumer Electronics Show (CES) in Las Vegas. Unfortunately I forgot the manager’s name, but I haven’t forgotten his message.

He talked about the importance of professionally made media content, which, according to him, would never be surpassed by amateur video content, vlogs, etc. To illustrate his point he referred to his observation when flying towards Las Vegas. Some time before touchdown, you pass one of Nature’s most marvelous wonders: The Grand Canyon. The BBC manager rightfully noticed that most air passengers nevertheless watched their inflight entertainment system instead of enjoying the aerial view of the largest canyon on earth. He obviously used that to stress the importance of — professional — TV content.

Inflight entertainment beats Nature wonders

How do I translate that to my personal life? Easy, to keep my family happy on the road to the holiday destination I need an on-car entertainment system.

Obviously one could buy one of the many car-entertainment systems on sale or buy a new car with build in entertainment directly. But what fun is that? I instead opted for building my own entertainment system. For that I purchased a raspberry Pi 3B and a large battery pack, and reused a hard disk that was still lying around.

The purpose is to set-up a wireless media-server on the Raspberry Pi that provides access to the media files on the hard disk. Since my car has no wifi network, the Raspberry Pi should also act as stand-alone wifi access point. My family members can subsequently use a mobile device of their choice, connect through wifi to the Raspberry Pi access point, and enjoy the video and audio by means of the media-server on the Raspberry Pi.

Set-up with Raspberry Pi, large battery, and harddisk.

Such projects have been built before, as can be learned from these links bradshack213, Vermeulen, Gav’s World. Below I describe my approach, which differs at some points, and is more up to date. Therefore it may proof helpful to others who want to keep their family happy on the road as well.

Hardware

Raspberry Pi 3 Model B+
  • Raspberry Pi 3 Model B+
  • Battery, Capacity 10000 mAh, Output DC 5V — 2.1A (max)
  • usb-storage device, such as a usb-stick, containing music, video, audiobooks.

Set-up operating system

Before you can start working with your Raspberry Pi, you need to install an operating system. How that is done is detailed on many webpages, such as this one. I have used the Raspberry Pi Imager software to download and burn the Raspberry Pi OS onto an SD-card, as explained on this webpage.

Subsequently you insert the SD-card in the Raspberry Pi, connect a screen, mouse and keyboard, and finally connect the power. The installation happens basically automatically. I prefer connecting a screen directly instead of a head-less setup such that I can follow the process roll along.

I find it most easy to connect the Raspberry Pi to my wifi-network so I can install extra packages from the internet and I can connect to the Raspberry Pi from another computer. Since I have a screen and keyboard connected anyway, I prefer using the Raspberry Pi desktop menu options to connect to the wifi. Additionally I adjust the standard password ‘pi’ for safety reasons and allow connection over SSH.

Media server

For the next steps I prefer to access the Raspberry Pi through SSH from behind the comfort of my desktop. To do so you need to find the IP-address from the Raspberry. That can be done in many ways; I’ve done so by using the Fing app. Subsequently you can connect to the Raspberry by ssh pi@[ip-number] and entering your password.

But I suppose you could also progress by directly working on the Raspberry Pi without using ssh, in that case you need to open a terminal window.

If you have used the Imager software you probably already have the latest versions. Anyway, it is always a good idea to start with:

Next, we need to install the media server software. Minidlna is a simple, lightweight option that serves our purpose well, which can be installed as:

The media files will be placed in the directory ~/media/pi; this directory should already be there. Just to be sure, we create it, make sure minidlna can find the files by setting the proper ownership and access parameters:

Next we need to configure minidlna by editting the minidlna.conf file which can be found in the ~/etc directory. You need to make sure to change the following parameters in this file:

Obviously you can change the ‘friendly_name’ into whatever you like.

Now we have installed MiniDLNA, we need to start it up and make sure it rescans all media files. That is most reliably be done by issuing the following set of commands:

Now you can check http://[ip-address]:8200/ in a webserver: the files on the usb-device should be visible now.

It is rather cumbersome to start minidlna manually. Therefore we need to make sure that the commands above are executed when the Raspberry boots, such that minidlna finds the files. This can be done by creating a file called startup.sh. This file can be created by using nano or any other file editor in Linux. In this file we make sure we wait for 30 seconds to allow the system to mount the usb-drive properly. Then we force a rescan by minidlna and a restart.

This file can be placed in the home directory and we have to make sure it can be executed by sudo chmod 755 startup.sh.

Now we need to make sure this shell script is invoked. This can be done by adding ./startup.sh to ./lib/systemd/system/ as a new service. In my experience this works more robustly than adding the shell script to ./.bashrc, which would be an alternative way of starting the media server.

The new service should start as the very last; when all other services have already been executed. Let’s call this service amazingVideo.service; this file is stored at./lib/systemd/system/, and it’s content is as follows:

The Type=idle option makes sure this service starts when all other services have been executed. See here for other options for creating services.

We need to make sure the access and execution rights are properly set by the command:

Now we have created the service, we need to actually add and enable the new service. This is done by the following set of commands:

Now we can check the status of this service by issuing systemctl status amazingVideo, which should return something like:

which means we have successfully created a media server which automatically starts up when the Raspberry Pi is booted.

If you need to debug the process during booting, I would recommend using dmesg; it allows to follow all messages during reboot of the system.

WiFi access point

The media server we have created now works on the network that the Raspberry Pi is on — the one that you added in setting up the Raspberry Pi operating system. This network is obviously out of reach when you are traveling. To still make use of out media server on-the-go, we should enable the Raspberry Pi to act as a standalone access point.

How to do this is extensively described as example in the Raspberry Pi documentation. This approach is somewhat to elaborate for what we actually need. Therefore I will shortly describe the minimum set of commands and changes you need to make below.

First we need to install hostapd and make sure it starts when the Raspberry Pi is booted. The package hostapd lets us create a wireless hotspot using a Raspberry Pi. This is done by:

Next, we need to install dnsmasq, which is an easy-to-use DHCP and DNS server. This is needed to provide network services to the devices that connect to the Raspberry Pi.

Now we need to configure the DHCP settings by sudo nano /etc/dhcpcd.conf . At the very end of this file you need to add the following lines:

We also need to adapt the DNS settings. The existing configuration file is quite elaborate. It is recommended to change the name of the original file and create a new dnsmasq.conf file. First, let’s move the original file:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

Then, create a new file by sudo nano /etc/dnsmasq.conf with the following content:

Finally, we need to configure the hostapd settings. This is done by creating a new file sudo nano /etc/hostapd/hostapd.conf; and adding the following lines to this file:

As is also stated in the documentation, please note the following:

  • The country_code needs to be adapted to the correct country code of your country. This makes sure the correct wireless frequencies are used. You can find the ISO 3166–1 country codes here. Interestingly, when I traveled abroad, I didn’t have to adept this line. My family’s mobile devices that connect to the Raspberry are probably set to the same country code and wireless frequencies. That is probably the reason I didn’t experience any difficulties crossing the border.
  • The network name is specified by ssid and is set to RaspBerry in this example. You may choose your own name.
  • The password is specified by wpa_passphrase. Obviously you are free to choose your own password.

Now everything is set-up, we can reboot the system sudo systemctl reboot, or even reboot the Raspberry Pi sudo reboot. The Raspberry Pi acts as stand-alone access point, and it is no longer available on your home network. To connect to the Raspberry Pi, you need to switch your device to the WiFi-network with name RaspBerry, and with wifi-password: AardvarkBadgerHedgehog. The Raspberry Pi is then available at ip-address192.168.4.1 and/or you can connect through ssh by ssh pi@gw.wlan. If you need to specify a gate, it is this: gate 22.

Raspberry-car-pi in action

Now we can finally hit the road. Once you connect the Raspberry Pi to the battery, it starts up. You can sit back and relax. The Raspberry Pi boots automatically. After all services are executed, the amazingVideo.service starts, which launches the media server through the startup.sh shell script. After 30 seconds of sleep, the media server searches the directories for new content. So, after a minute or so, you can grab your mobile device (phone, tablet, whatever you prefer) and connect to the wifi network called RaspBerry (password AardvarkBadgerHedgehog).

To consume the media content you need to install and start a media player on your mobile device. There are many media players available; for example, you could use VLC for Android, AllConnect, or MediaHouse. Connect to the media server, select what you want to watch or listen too, and enjoy!

Once you have reached your destination, you have to properly shut down the Raspberry Pi. It is risky to just unplug the battery; this may corrupt the operating system. A better approach is to use this app: RasPi Check. I use this app to send the ‘halt’ command to the Raspberry Pi. After a few seconds the Raspberry Pi has neatly shut down, which can be noticed by the disappearing RaspBerrywifi network.

Apps mentioned in this blog, from left to right: Fing, RasPi check, VLC, AllConnect, MediaHouse.

It would be more convenient to have a on/off button on the Raspberry itself for proper shutting down and starting up. Such button can be added by following an approach such as described here. Another neat approach would be to use a Raspberry Pi case that includes an on/off button such as provided by Argon Forty. But I leave that option for another rainy afternoon.

I have tried the system for quite a few trips already. The used battery provides enough energy for about one day of driving; and forms a stable and reliable source.

Closing words

The storage capacity of mobile devices rapidly increases at decreasing costs. At the same time mobile data coverage through wifi, 4G or 5G quickly expands. These trends will quickly obfuscate my DIY car-entertainment system. However, until that time is there, it has been a joyful learning experience setting up the system. And, I feel, the innovation manager of the BBC would nod and approve!

--

--