Raspberry Pi‎ > ‎

Portable DLNA Media Server with a Raspberry Pi

posted Oct 25, 2015, 4:58 AM by Chris G   [ updated Dec 2, 2015, 2:12 AM ]
I wanted to configure a Raspberry Pi as a portable Media Server, to take with us and allow the kids to watch movies from their own portable devices.


One of the main reason to use a Raspberry Pi is the fact that these devices are so small and portable. However, if you want to be able to take one with you, you have to be able to connect to it when you are on the go.

For that, you can enable your device to act as a Wireless Access Point.


Step 1 - Configure the Raspberry Pi to act as a WiFi Access point

Unfortunately, using the Edimax EW-7811Un wireless adapter to work on my Raspberry Pi wasn't as easy as it should have been. While this Realtek RTL8188CUS chipset based adapter works right out of the box when you use it to connect to wireless networks, the default hostapd always displayed the following error:


$ sudo hostapd /etc/hostapd/hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf nl80211: 'nl80211' generic netlink not found Failed to initialize driver 'nl80211' rmdir[ctrl_interface]: No such file or directory


In order to make 
hostapd work with the Edimax WiFi Realtek RTL8188 adapter work as a Wireless access point with a Raspberry Pi, follow this post:

http://www.jenssegers.be/43/Realtek-RTL8188-based-access-point-on-Raspberry-Pi



Then, edit the configuration file by typing:


sudo nano /etc/hostapd/hostapd.conf 
Paste the following:
# Basic configuration

interface=wlan0
ssid=aaawifi
channel=1
#bridge=br0

# WPA and WPA2 configuration

macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=YourSecretPassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

# Hardware configuration

driver=rtl871xdrv
ieee80211n=1
hw_mode=g
device_name=RTL8192CU
manufacturer=Realtek
wmm_enabled=1
sa




issue connecting
wmm_enabled=1


sudo nano /etc/default/hostapd




DAEMON_CONF="/etc/hostapd/hostapd.conf"




hostapd -d /etc/hostapd/hostapd.conf





sudo chmod +x /home/pi/launch.py

sample script as laun


/etc/network/interfaces  

auto wlan0
iface wlan0 inet static
address 10.0.0.1
network 10.0.0.0
netmask 255.255.255.0
broadcast 10.0.0.255




sudo apt-get -y install dnsmasq

/etc/dnsmasq.conf 

interface=wlan0
expand-hosts
domain=local
dhcp-range=10.0.0.10,10.0.0.100,24h
dhcp-option=3,10.0.0.1



sudo update-rc.d dhcpd disable



sudo apt-get install minidlna
   35  sudo nano /etc/minidlna.conf
   36  service minidlna start






MiniDLNA is a lightweight media server designed to support the DLNA and UPnP protocols. This works pretty nicely with almost any device you may want to consume media content on and it's so lightweight it's an ideal match for the Pi.

So, let's get started. First, run a full update and then install the minidlna package.

# apt-get update
# apt-get upgrade
# apt-get install minidlna

Once installed, we'll go ahead and edit the configuration file as follows.

/etc/minidlna.conf
---
media_dir=A,/mnt/ext/Music
media_dir=P,/mnt/ext/Pictures
media_dir=V,/mnt/ext/Videos
friendly_name=Raspberry Pi
inotify=yes

Fairly self explanitory, I hope. Set your directories, set a name for your media server, and ensure that the media library is automatically refreshed.

Now we start minidlna and we should have a working media server!

# service minidlna start

Upon the fist run, the media library will be built. This may take a while depending on how many files you have, once it's done you shouldn't have to do it again though.

Finally, ask minidlna to start up automatically upon boot.

# update-rc.d minidlna defaults

In summary, the most reliable way to have MiniDLNA rescan all media files is by issuing the following set of commands:

$ sudo minidlna -R
$ sudo service minidlna restart



Button to shut down:


se to make your Pi speak:


#!/usr/bin/python


import RPi.GPIO as GPIO
import subprocess
import os



GPIO.setmode(GPIO.BCM)

GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)



def printFunction(channel):
	print("Goodbye...")
        subprocess.call(['sudo halt'], shell=True)



GPIO.add_event_detect(23, GPIO.RISING, callback=printFunction, bouncetime=300)


while True:
    time.sleep(1)




That's all, your Pi will now shut down when the button is pressed.