Install Pianobar (Pandora) on Raspberry Pi

Posted by Max Power | Posted in Raspberry Pi | Posted on 04-11-2014-05-2008

0

In this post we will install Pianobar, an application for streaming Pandora on the Raspberry Pi.

Install the Prerequisites

sudo apt-get -y install git pkg-config libevent-pthreads-2.0-5 libao-dev libgnutls28-dev libmad0-dev libfaad-dev libjson0-dev libgcrypt11-dev

Compile Pianobar

Now lets download Pianobar from github. Apparently the one from apt-get is out of date (reference).
git clone git://github.com/prattmic/pianobar.git
cd pianobar
make
sudo make install

Note: You may get it from https://github.com/PromyLOPh/pianobar as well (this one may be more up to date).

Configure Pianobar

Now lets configure pianobar. First create the Pianobar config file (or copy it from /usr/share/doc/pianobar/contrib/config-example).
mkdir -p .config/pianobar
Navigate to the new directory and create the config file
cd ~/.config/pianobar
sudo nano config

Copy the following into the config file:
# This is an example configuration file for pianobar. You may remove the # from
# lines you need and copy/move this file to ~/.config/pianobar/config
# See manpage for a description of the config keys
#
# User
user = YOUR_EMAIL_ADDRESS
password = YOUR_PASSWORD
# or
#password_command = gpg --decrypt ~/password
#
# Proxy (for those who are not living in the USA)
#control_proxy = http://127.0.0.1:9090/
#
# Keybindings
act_help = ?
act_songlove = +
act_songban = -
act_stationaddmusic = a
act_stationcreate = c
act_stationdelete = d
act_songexplain = e
act_stationaddbygenre = g
act_songinfo = i
act_addshared = j
act_songmove = m
act_songnext = n
act_songpause = p
act_quit = q
act_stationrename = r
act_stationchange = s
act_songtired = t
act_upcoming = u
act_stationselectquickmix = x
act_voldown = (
act_volup = )
#
# Misc
#audio_quality = low
#autostart_station = 123456
#
#event_command = /home/pi/.config/pianobar/scripts/eventcmd.sh
#fifo = /home/pi/.config/pianobar/ctl
#sort = quickmix_10_name_az
#love_icon = [+]
#ban_icon = [-]
volume = -30
#
# Format strings
format_nowplaying_song = SONG: %t | %a | %l
format_nowplaying_station = STATION: %n | %i
format_msg_time = TIME: %s
# No special prefix on songs, stations or info
format_msg_nowplaying = %s
format_msg_info = %s
#
# high-quality audio (192k mp3, for Pandora One subscribers only!)
#audio_quality = high
#rpc_host = internal-tuner.pandora.com
#partner_user = pandora one
#partner_password = TVCKIBGS9AO9TSYLNNFUML0743LH82D
#device = D01
#encrypt_password = 2%3WCL*JU$MP]4
#decrypt_password = U#IO$RZPAB%VX2
#
tls_fingerprint = 2D0AFDAFA16F4B5C0A43F3CB1D4752F9535507C0

Replace the following lines with your username and password for Pandora
user = YOUR_EMAIL_ADDRESS
password = YOUR_PASSWORD

Note: If you get the error “Login… Network error: TLS handshake failed.”, Pandora may have changed the tls_fingerprint (it is correct as of 12/3/2014). Or your login credentials may be wrong. You can get the current tls_fingerprint following these steps…

First create a file (placement of the file is not important)
cd
sudo nano pandora_tls

Now copy in this code (refrence: https://gist.github.com/r35krag0th)
#!/bin/bash
##
## A simple little shell script that will return the current
## fingerprint on the SSL certificate. It's crude but works :D
##
## Author: Bob Saska (r35krag0th) <git@r35.net>
##
openssl s_client -connect tuner.pandora.com:443 < /dev/null 2> /dev/null | \
openssl x509 -noout -fingerprint | tr -d ':' | cut -d'=' -f2

Then run the script
sudo bash pandora_tls
It will then return to you the latest tls_fingerprint and you can replace the one in the config file with that one.

Run Pianobar

Now lets launch Pianobar
cd
pianobar

Note: The volume may be low. Use “)” to increase the volume and “(” to reduce the volume. Use “q” to quit. The other commands are shown below.  If you need to change the audio source to the 3.5mm jack, run the following command…
sudo amixer cset numid=3 1

Keyboard Controls

act_help = ?
Show keybindings.

act_songlove = +
Love currently played song.

act_songban = –
Ban current track. It will not be played again and can only
removed using the pandora.com web interface.

act_stationaddmusic = a
Add more music to current station. You will be asked for a
search string. Just follow the instructions. If you’re clueless
try ‘?’ (without quotes).

act_bookmark = b
Bookmark current song or artist.

act_stationcreate = c
Create new station. You have to enter a search string and select
the song or artist of your choice.

act_stationdelete = d
Delete current station.

act_songexplain = e
Explain why this song is played.

act_stationaddbygenre = g
Add genre station provided by pandora.

act_history = h
Show history.

act_songinfo = i
Print information about currently played song/station.

act_addshared = j
Add shared station by id. id is a very long integer without “sh”
at the beginning.

act_songmove = m
Move current song to another station

act_songnext = n
Skip current song.

act_songpause = p
Pause/Continue

act_quit = q
Quit pianobar.

act_stationrename = r
Rename currently played station.

act_stationchange = s
Select another station.

act_songtired = t
Ban song for one month.

act_upcoming = u
Show next songs in playlist.

act_stationselectquickmix = x
Select quickmix stations.

audio_format = {aacplus,mp3,mp3-hifi}
Select audio format. aacplus is default if both libraries (faad,
mad) are available. mp3-hifi is available for Pandora One
customers only.

autostart_station = stationid
Play this station when starting up. You can get the stationid by
pressing i or the key you defined in act_songinfo.

control_proxy = http://host:port/
Non-american users need a proxy to use pandora.com. Only the
xmlrpc interface will use this proxy. The music is streamed
directly.

event_command = path
File that is executed when event occurs. See section EVENTCMD

history = 5
Keep a history of the last n songs (5, by default). You can rate
these songs.

password = plaintext_password
Your pandora.com password. Plain-text.

proxy = http://host:port/
Use a http proxy. Note that this setting overrides the
http_proxy environment variable.

sort = {name_az, name_za, quickmix_01_name_az, quickmix_01_name_za,
quickmix_10_name_az, quickmix_10_name_za}
Sort station list by name or type (is quickmix) and name.
name_az for example sorts by name from a to z,
quickmix_01_name_za by type (quickmix at the bottom) and name
from z to a.

user = your@user.name
Your pandora.com username.

*taken from http://manpages.ubuntu.com/manpages/maverick/man1/pianobar.1.html

Refrences

  • https://learn.adafruit.com/pi-wifi-radio/raspberry-pi-setup-2-of-3
  • http://www.instructables.com/id/Wireless-Raspberry-Pi-Radio-Pianobar/?ALLSTEPS

Install Shairport on Raspberry Pi

Posted by Max Power | Posted in Android, Raspberry Pi | Posted on 04-11-2014-05-2008

0

This post will walk the user through the process of installing Shairport on the Raspberry Pi.  The following instructions assume that you are using the standard Raspbian (Debian Wheezy) install, it is installed and running, and you are connected to the internet.

Once you have Shairport installed and running, you will be able to stream audio from your Apple or Android device to the Raspberry Pi.  AllStream Cast+AirPlay+DLNA and AirPlay DLNA SONOS Chrome Roku are two applications for Android that will allow you to stream audio from you device to an AirPlay device or multiple devices.  Sonos replacement????

Update Packages

First make sure that your packages are up to date
sudo apt-get update && sudo apt-get upgrade

Install Prerequisites

Install the prerequisite packages
sudo apt-get install build-essential libssl-dev libcrypt-openssl-rsa-perl libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config git libssl-dev libavahi-client-dev libasound2-dev libpulse-dev libmodule-build-perl

Optional
sudo apt-get install chkconfig

Update Firmware

Make sure that your firmware is up to date, this will hopefully avoid the popping noise when the audio is selected
sudo git clone git://github.com/Hexxeh/rpi-update.git
sudo rpi-update/rpi-update

Reboot to activate the new firmware
sudo reboot

Install Perl Net-SDP

Apparently a change in IOS 6 requires this module to be installed or else shairport will crash.
sudo git clone https://github.com/njh/perl-net-sdp.git perl-net-sdp
cd perl-net-sdp
sudo perl Build.PL
sudo ./Build
sudo ./Build test
sudo ./Build install
cd ..

ALSA

To avoid the error “Unknown PCM cards.pcm.front”, modify the ALSA config (refrence: http://cagewebdev.com/index.php/raspberry-pi-getting-audio-working/)
sudo nano /usr/share/alsa/alsa.conf
Change the line “pcm.front cards.pcm.front” to “pcm.front cards.pcm.default”

avahi-daemon

Now we will modify the avahi-daemon init.d script to fix the issue with avahi-daemon that gives the “avahi-daemon disabled because there is a .local domain” on many networks.
sudo nano /etc/init.d/avahi-daemon
Modify the line DISABLE_TAG=”/var/run/avahi-daemon/disabled-for-unicast-local and change it to DISABLE_TAG=”/var/run/avahi-daemon/disabled-for-unicast-local-DISABLE
Restart the avahi-daemon
sudo service avahi-daemon restart

Shairport

Install Shairport
sudo git clone -b 1.0-dev git://github.com/abrasive/shairport.git
cd shairport
sudo ./configure
sudo make
sudo make install

Start Shairport and test it to see if it is working
./shairport -a 'AirPlay'
Now using one of the Andriod apps listed above or iTunes you should be able to see this device and stream music to it. If you have speakers connected to the 3.5mm jack you may have to make that the default output for audio (see the audio setup below).

We are done in this folder
cd ..

Audio Setup

The following command will set the output to the 3.5mm jack (by default it is set to the HDMI)
sudo amixer cset numid=3 1
Adjust the audio level with the following command
alsamixer
*Note: If you get one of these errors: ‘amixer: Control default open error: No such file or directory’ or ‘cannot open mixer: No such file or directory’, the following command should fix things (Ref)
sudo modprobe snd_bcm2835

Starting Shairport on boot

Next we will set Shairport to launch on boot, first we will copy the startup script
sudo cp scripts/debian/init.d/shairport /etc/init.d/shairport

I want the start up script to use the pi user and not the admin user as it is setup to by default, therefore I need to edit the start up script
sudo nano /etc/init.d/shairport
Edit the following lines to read (reference: https://gist.github.com/khromov/6398615)
DAEMON=/usr/local/bin/shairport
USER=root
GROUP=nogroup
Note: The name of the device is set by default to the name of the Raspberry Pi. If you don’t want that, you can change AP_NAME and give it the name you want.

cd /etc/init.d
sudo chmod a+x shairport
sudo update-rc.d shairport defaults

Shairport Watchdog

We want to make sure that avahi-daemon starts before shairport otherwise shairport will fail.  The script will use pgrep so we need to install those packges
sudo apt-get install pcregrep pgrep
Now we will write a script called shairport-watchdog.sh in /root
sudo nano /root/shairport-watchdog.sh
that contains the following code (reference: https://github.com/abrasive/shairport/issues/242)
# find service pids
pgrep shairport
#if we get no pids, service is not running
if [ $? -ne 0 ]
then
service shairport start
echo "shairport started or restarted."
fi

Now edit the /etc/crontab file
sudo nano /etc/crontab
and add the following line
* * * * * root /bin/sh /root/shairport-watchdog.sh > /dev/null
Final cleanup
sudo chown -R pi:pi /home/pi/

References

  • http://snippets.khromov.se/raspberry-pi-shairport-build-instructions/
  • http://www.raywenderlich.com/44918/raspberry-pi-airplay-tutorial
  • http://adrianmejia.com/blog/2014/02/15/cheap-airplay-receiver-with-raspberry-pi/

Raspberry Pi Error – Entering kdb (current=0xce82ac80, pid 1) due to Keyboard Entry kdb>

Posted by Max Power | Posted in Raspberry Pi | Posted on 25-09-2013-05-2008

1

Saw the following error when trying to boot my Raspberry Pi:

Entering kdb (current=0xce82ac80, pid 1) due to Keyboard Entry kdb>

I determined that it was an error with the SD card and this is how I fixed it.  I took the SD card and put it in a USB SD card reader and plugged it into my Windows 7 machine that has a Mythbuntu (64 bit) Virtual Machine running in Oracle VM Virtualbox.  I mounted the USB drive in the VM and used GParted to determine what the mount path was.  In this case it was “/dev/sdc2”.  I then launched the terminal application and used the following command:

sudo e2fsck -f -v /dev/sdc2

After quite a while and answering yes a million times the process was done.  I then unmounted the card, put it back in the RPi and it booted fine.

Hopefully this is helpful to someone else out there (and hopefully this will help me to remember what I did to fix the problem last time).

FTDI on WGT634u Running OpenWRT Backfire

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 24-04-2012-05-2008

0

In this post I will document the modules that installed to get a WGT634u running OpenWrt Backfire to recognize a DFRobot.com FTDI (http://www.dfrobot.com/index.php?route=product/product&filter_name=ftdi&product_id=147).  In order to trouble shoot this better I am connected to the router via a usb to serial TTL cable.  Instructions on how to build one can be found here.

First we need to install the USB modules. This router seems to support usb2 and ohci so these are the ones that I installed.

opkg update
opkg install kmod-usb2
opkg install kmod-usb-ohci

Note: You can use the following command to see what usb is supported (uhci or ohci):

cat /proc/bus/usb/devices

Next we will install the modules for the FTDI:

opkg update
opkg install kmod-usb-serial-ftdi

Note that when you plug the FTDI into the Arduino you should connect the tx to tx, rx to rx, and gnd to gnd. It seems that the usb on my router does not have the output to power the Arduino through the FTDI so I am powering it separately with a 9v DC adapter.

Netgear WGT634u as a Wireless Client Running OpenWRT Backfire

Posted by Max Power | Posted in Netgear WGT634u | Posted on 14-04-2012-05-2008

0

In this post I will show how to configure your Netgear WGT634u, running OpenWRT Bsckfire, as a wireless client.  This means that it will allow devices connected to its LAN to be connected to a wireless router LAN.

  1. First you will have to enable the wireless as shown in this post.
  2. On the LuCI>Network>wifi>wifi0 device info set the network to “WAN” and mode to “client“.

Here are my config files for reference (/etc/config/):

Wireless

config 'wifi-device' 'wifi0'
	option 'type' 'atheros'
	option 'channel' 'auto'
	option 'diversity' '0'
	option 'disabled' '0'
 
config 'wifi-iface'
	option 'device' 'wifi0'
	option 'ssid' 'ssid'
	option 'network' 'wan'
	option 'mode' 'sta'
	option 'encryption' 'wep'
	option 'key' '******************'

Network

config switch eth0
	option enable 1
 
config switch_vlan eth0_0
	option device "eth0"
	option vlan 0
	option ports "0 1 2 3 5"
 
config switch_vlan eth0_1
	option device "eth0"
	option vlan 1
	option ports "4 5"
 
config interface loopback
	option ifname "lo"
	option proto static
	option ipaddr 127.0.0.1
	option netmask 255.0.0.0
 
config interface lan
	option type bridge
	option ifname "eth0.0"
	option proto static
	option ipaddr 192.168.1.1
	option netmask 255.255.255.0
 
config interface wan
	option ifname "eth0.1"
	option proto dhcp

Python Interface for Arduino Uno Using a Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 29-11-2011-05-2008

0

Edit:  I abandoned this method in favor of a simpler method.  I am using a FTDI to communicate and just executing serial commands with PHP.  You can see how I am doing this in this post.  I left this up thinking that it may be useful to someone else.  However, keep in mind it may not be complete.

In this post I will show you how I was able to communicate with my Arduino Uno connected to my Netgear WGT634u running OpenWrt Backfire.  This is a baby step toward being able to control the Arduino Uno from a website hosted by the Netgear WGT634u.

Setup

First we will install Python (python_2.6.4-3_brcm47xx.ipk) :

opkg update
opkg install python

Next we will install the PySerial module (pyserial_2.4-1_brcm47xx.ipk):

opkg update
opkg install pyserial

Now we need to edit the PySerial module to disable DTR, I discus this a bit (here):

cd /usr/local/lib/pythonX.Y/site-packages/serial
rm serialwin32.pyc
vi serialwin32.py

Change the following line:

self._dtrState = win32.DTR_CONTROL_ENABLE

to:

self._dtrState = win32.DTR_CONTROL_DISABLE

Now lets create a sample script and test it. First make a folder to put the python script in:

mkdir /python

Create the sample script:

vi /python/arduino_com.py
import sys
import arduino
 
ser = arduino.Serial('/dev/ttyACM0',9600)
 
if (len(sys.argv) &gt;; 1):
print sys.argv[1]
ser.write(sys.argv[1])

Now lets test it.. To test the script I am using the LED example included with the Arduino software. Using your computer, upload the PhysicalPixel sketch from File > Examples > Communication > PhysicalPixel to the Arduino. After you upload the sketch, plug it into the WGT634u and lets test it out. In this example when we send a “H” the LED on the Arduino will light and when we send a “L” the LED will go off.

Turn the LED on:

/python/arduino_com.py H

Turn the LED off:

/python/arduino_com.py L

You can call you script from a webserver using cgi. Place the following file in your bin-cgi folder:

#!C:\Python27\python.exe -u
#!/usr/bin/env python
import cgi
import cgitb; cgitb.enable() # for troubleshooting
import arduino # For serial com (modified pyserial)
 
print "Content-type: text/html"
print
 
print """
Sample CGI Script

Sample CGI Script

"""
 
form = cgi.FieldStorage()
arg = form.getvalue("arg")
 
print """
str value: %s
""" % cgi.escape(arg)
 
ser = arduino.Serial('\dev\ttyACM0',9600)
ser.write(arg)

Visit it with your web browser using http://localhost:8080/cgi-bin/arduino_com.py?arg=H to turn the light on and http://localhost:8080/cgi-bin/arduino_com.py?arg=L to turn it off.

You can also call it from a webserver using PHP:

#button {
	font-weight: bold;
	border: 2px solid #fff;
}

How to Disable Serial COM Auto Reset on Arduino Uno

Posted by Max Power | Posted in Arduino | Posted on 29-11-2011-05-2008

2

Edit:  I gave up on trying to disable the auto reset through software.  The capacitor method works but is cumbersome.  The easiest solution is to use an external FTDI as I show in this post.

To test the following solutions I am using the LED example included with the Arduino software to test it. Using your computer, upload the PhysicalPixel sketch from File > Examples > Communication > PhysicalPixel to the Arduino.  After you upload the sketch, plug it into the WGT634u and lets test it out.  In this example when we send a “H” the LED on the Arduino will light and when we send a “L” the LED will go off.  However, you might notice that the LED blinks a bunch of times and does not stay light.  This is because the serial port resets.  When we are trying to communicate with it via the COM port this is annoying.  However there are ways to fix this.

Hardware Solution

Here are some hardware solutions that you might want to try: http://www.arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection.  I was able to make it work by adding a 10uF capacitor between the RESET and GND.  One note though, you need to plug in the Arduino first to let it start, then you can add the capacitor.  If you have the capacitor connected before you connect the USB cable it will not work.  Here is a reference: http://tushev.org/articles/electronics/38-preventing-arduino-from-auto-reset-when-com-port-openscloses

Software Solution

The other option is to set Data Terminal Ready (DTR) to false or disabled for the port that hosts your Arduino.

Python

Here is an example of how to do this in Python.  I downloaded the pySerial package and modified it as follows:

  1. Copy the folder c:\Python27\Lib\site-packages\serial to c:\Python27\Lib\site-packages\arduino
  2. In the arduino folder, delete the file serialwin32.pyc
  3. Edit the file serialwin32.py, replace the line self._dtrState = win32.DTR_CONTROL_ENABLE to say self._dtrState = win32.DTR_CONTROL_DISABLE
  4. Save the file and use import arduino to use the modified package

Here is the code that I am using to turn on the LED on pin 13.  This uses the PhysicalPixel sketch mentioned above.

import arduino
ser=arduino.Serial('COM4',9600)
ser.write('L')

Arduino Uno Forward Serial to Telnet With ser2net on Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 29-11-2011-05-2008

1

This is how I used a WGT634u running OpenWrt Backfire to forward the serial port with the Arduino Uno to a telnet port.  This could be used as a cheap alternative to an ethernet shield or connecting the USB to your computer.  I was able to send commands to my Arduino via telnet over wireless network with the WGT634u in client mode.

Setup

Install ser2net:

opkg update
opkg install ser2net

Start ser2net:

ser2net -C "8082:raw:600:/dev/ttyACM0:9600 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS"

Now you should be able to communicate with your Arduino on port 8082.  Open up a telnet window and connect to your router.

Start on Boot

Next I will show you how to set it up so that ser2net will run on boot.

Edit the conf file:

vi /etc/ser2net.conf

Comment everything out and add this line at the bottom:

8082:raw:600:/dev/ttyACM0:9600 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS

Edit the startup file:

#!/bin/sh /etc/rc.common
START=10
STOP=15
start(){
ser2net
}
stop(){
killall ser2net
}

Enable the service:

/etc/init.d/ser2net enable

Arduino Uno Connected Via USB to Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 28-11-2011-05-2008

2

In this post I will show you how I connected an Arduino Uno to my Netgear WGT634u running OpenWrt Backfire via the USB port.  One thing to note is that it is much easier to trouble shoot if you are connected to the router with a serial cable.  I have another post (here) that outlines the process for building and connecting to the router with a serial cable.

Setup

First we need to make sure that we have the USB drivers that we need:

opkg update
opkg install kmod-usb-ohci

Next we will install the drivers package that will support the Arduino:

opkg update
opkg install kmod-usb-acm

Now when you plug the Arduino into the WGT634u, you should see that it is recognized (you will only see this if you are connected to the router with the serial cable):

usb 2-1: new full speed USB device using ohci_hcd and address 3
usb 2-1: configuration #1 chosen from 1 choice
cdc_acm 2-1:1.0: ttyACM0: USB ACM device

We should be able to find a new addition for the Arduino in the following location:

/dev/ttyACM0

Testing

Now that we have the Arduino installed, lets test it to see if we can send serial commands to it.  We can use the LED example included with the Arduino software to test it. Using your computer, upload the PhysicalPixel sketch from File > Examples > Communication > PhysicalPixel to the Arduino.  After you upload the sketch, plug it into the WGT634u and lets test it out.  In this example when we send a “H” the LED on the Arduino will light and when we send a “L” the LED will go off.

Turn off the led:

echo "L" &gt; /dev/ttyACM0

Turn on the led:

echo "H" &gt; /dev/ttyACM0

If this does not work for you, don’t fret…  It didn’t work for me either.  I appears that the older Arduino Uno boards reset the serial connection and so the light will flash but will not stay light.   I have a post (here) about how to fix this.

Summary

So now you have successfully connected your Arduino Uno to your Netgear WGT634u via the USB port and demonstrated that you can communicate with it via serial commands.

Webserver with PHP and Streaming Webcam on Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Netgear WGT634u | Posted on 17-11-2011-05-2008

0

In this post I will outline the process I used to setup a streaming usb webcam with a web server running php on a Netgear WGT634u running OpenWrt Backfire.

Webcam

First we will setup the webcam and make sure that we can view the stream on the lan.  Check out my other post (http://wp.yellowkazoo.com/?p=57) for details.  Note: When you setup the webcam make sure that you set it up on a different port than the one that you want the web server on.  I put the webcam on port 8081 and the web server on port 8080.  You can do this by editing the following file:

 /etc/config/mjpg-streamer
Config mjpg-streamer core
    option device "/dev/video0"
    option resolution "640x480"
    option fps "5"
    option port "8080"
    option enabled "true"

Web Server

Next we will install a web server,  I used lighttpd.

opkg update
opkg install lighttpd lighttpd-mod-cgi

Now lets edit the configuration file:

/etc/lighttpd/lighttpd.conf

Enable the mod_cgi module:

server.modules = (
    [..]
    "mod_cgi"
    [..]
}

Allow index.php as index:

index-file.names = ("index.html","default.html","index.htm","default.htm","index.php")

Set the server root directory:

server.document-root = "/www/pub_www/"

Set the server port:

server.port = 8080

Under CGI Module add:

cgi.assign = (".php => "/usr/bin/php")

Create a new folder for the document root:

mkdir /www/pub_www

Start lighttpd:

/etc/init.d/lighttpd start

Or have lighttpd start on startup:

/etc/init.d/lighttpd enable

PHP Server

Now lets setup the php server.  I installed PHP4 because it is a much smaller package.

opkg update
opkg install php4 php4-cgi

Edit the config file:

/etc/php.ini

Setup the root folder:

doc_root = /www/pub_www

To test the php setup we will create the file /www/pub_www/phpinfo.php with the following content:

<?php php phpinfo() ?>;

Now restart the server:

/etc/init.d/lighttpd restart

Browse to the phpinfo.php page (http://192.168.1.1:8080/phpinfo.php)

PHP Webcam Page

Now we will create a php page that includes the webcam stream.  Check out this post to see how I setup the webcam.

<?php
/* Usage: <img src="thisfile.php"> */
$server = "localhost"; // camera server
$port = 8081; // camera server port
$url = "/?action=stream"; // url on camera server
$fp = fsockopen($server, $port, $errno, $errstr, 30);
if( !$fp ){
    echo "$errstr ($errno)<br />\n";
}else{
    $urlstring = "GET ".$url." HTTP/1.0\r\n\r\n";
    fwrite( $fp, $urlstring );
    while( $str = trim( fgets( $fp, 4096 ) ) )header( $str );
    fpassthru( $fp );
    fclose( $fp );
}
?>

Firewall Setup

Once the server is all setup we will configure the firewall so that it is accessible from the wan.

config redirect
    option src wan
    option src_dport 80
    option dest lan
    option dest_ip 192.168.1.1
    option dest_port 8000
    option proto tcp
config rule
    option src wan
    option dest_port 8000
    option target ACCEPT
    option proto tcp

Now restart the firewall:

/etc/init.d/firewall restart