Feb 102013

So, I figured out why wlan0 doesn’t get an IP address when hostapd starts up.
ifplugd messes about with the interfaces when they go up and down, so the simplest solution is to disable ifplugd for wlan0 !
in /etc/default/ifplugd, the default configuration is this

ARGS="-q -f -u0 -d10 -w -I"

Simply changing it to this

ARGS="-q -f -u0 -d10 -w -I"

will ensure that wlan0 will not lose it’s static IP address that’s configured in /etc/network/interfaces when wlan0 goes up.

Feb 102013

As a follow up this this post, the script that I used had a few issues running on the server that I was using it on.
For some reason, on my server, the http interface would randomly die on me and then the script would not be able to stop or start motion.

So I modified the old one to this one, but it necessitated some modifications to the startup script for motion as trying to start motion via a shell script did not work due to the paths used within the startup script.

In the startup script /etc/init.d/motion, the full path is not used for start-stop-daemon. This means that when motion is started from a shell script, the command start-stop-daemon is not found. To rectify this, add /sbin/ to all instances of start-stop-daemon. The following example shows one of the instances of start-stop-daemon. The example begins on line 50, and the start-stop-daemon command is the last line of the example.

case "$1" in
if check_daemon_enabled ; then
if ! [ -d /var/run/motion ]; then
mkdir /var/run/motion
chown motion:motion /var/run/motion

log_daemon_msg "Starting $DESC" "$NAME"
if /sbin/start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid motion ; then

In the updated script, I have added a few checks to ensure that the http interface is still running, and if it isn’t the script will kill motion altogether, and then restart motion to get everything up and running again.

The updated script is below –

people=( )

wget -o getlog -O /usr/scripts/status http://localhost:8080/0/detection/status
if [ -f /usr/scripts/status ]; then
echo "SettingMotion"
MotionStarted=`cat /usr/scripts/status | sed -e 's/<[^>]*>//g' | tail -n 3 | head -n -2`
echo "Status file not available"
echo "Attempting to start motion"
/etc/init.d/motion start

sleep 5

if [ -f /usr/scripts/status ]; then
echo Checking Size
StatusSize=$(stat -c%s /usr/scripts/status)
if [[ $StatusSize -eq 0 ]]; then
echo Size is zero
MotionStarted=`pidof motion | wc -l`
if [[ $MotionStarted -eq 1 ]]; then
echo Motion web interface failed. Restarting motion
killall -9 motion
echo "HTTP interface has failed. killing motion and restarting" | mail -s 'Motion killed'
/etc/init.d/motion restart
echo Motion not started.
echo Starting Motion
/etc/init.d/motion start
echo "Status file not available"

for ip in "${people[@]}"; do
PersonAround=`ping -c 1 $ip | grep '64 bytes' | wc -l`
if [[ PersonAround -eq 1 ]]; then

if [[ $PeopleAround -eq 1 ]]; then
if [[ "$MotionStarted" =~ "ACTIVE" ]]; then
wget -O /usr/scripts/pause
echo "People around, stopping motion" | mail -s 'Motion stopped'
echo "People around, stopping motion"
if [[ "$MotionStarted" =~ "PAUSE" ]]; then
wget -O /usr/scripts/start
echo "No One around, Starting motion" | mail -s 'Motion started'
echo "No One around, Starting motion"
if [ -e /usr/scripts/status ]; then
rm /usr/scripts/status

Feb 082013

As a continuation this post, I have completed the first version of the RaspAP WebGUI. I have yet to decide on a good name for it though.

If you would like to download it to try it out, the links to the PHP script and supporting files are here –
Zip Version
tar.gz Version

Specific instructions to install the supported software are in the post linked at the beginning of this post.
For a quick run through, read on !
The Packages required for the WebGUI are –

  • lighttpd (I have version 1.4.31-2 installed via apt)
  • php5-cgi (I have version 5.4.4-12 installed via apt)

along with their supporting packages, php5 will also need to be enabled via the following command and lighttpd restarted.

sudo lighty-enable-mod fastcgi-php
/etc/init.d/lighttpd restart

/etc/sudoers will also need to be updated with the following line –

www-data ALL=(ALL) NOPASSWD:/sbin/ifdown wlan0,/sbin/ifup wlan0,/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf,/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf,/sbin/wpa_cli scan_results,/sbin/wpa_cli scan,/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf,/etc/init.d/hostapd start,/etc/init.d/hostapd stop,/etc/init.d/dnsmasq start,/etc/init.d/dnsmasq stop,/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf

Once those modifications are done, unzip the files to /var/www and it should be up and running !

Keep in mind that this is a very very first alpha version of this.
In testing, it worked for me, but if you have issues or feedback, please feel free to contact me or comment on this post πŸ™‚ I look forward to hearing back from anyone who has tried this out πŸ™‚

Feb 062013

After some experimentation with the RaspAP, I decided to write up a simple web interface for it so that when hostapd started broadcasting, I could use a simple web page rather than ssh to control the wifi and hostapd on the Raspberry Pi. The distribution I used was Raspbian Server Edition once again.

I started off by installing lighttpd and php5

apt-get install lighttpd php5-cgi

After that, I enabled php for lighttpd and restarted it for the settings to take effect.

sudo lighty-enable-mod fastcgi-php
/etc/init.d/lighttpd restart

Now, comes the fun part.
For security reasons, the www-data user which lighttpd runs under is not allowed to start or stop daemons, or run commands like ifdown and ifup, all of which I wanted my page to do.
So what I have done, is added the www-data user to the sudoers file, but with restrictions on what commands the user can run.
The line appears in /etc/sudoers like this –

www-data ALL=(ALL) NOPASSWD:/sbin/ifdown wlan0,/sbin/ifup wlan0,/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf,/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf,/sbin/wpa_cli scan_results,/sbin/wpa_cli scan,/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf,/etc/init.d/hostapd start,/etc/init.d/hostapd stop,/etc/init.d/dnsmasq start,/etc/init.d/dnsmasq stop,/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf

Notice I’ve restricted the www-data user to only be able to run the exact commands in the sudoers file
This means that the www-data can only take down, bring up, and show the configuration of wlan0 for example.

After the sudoers file has been modified, the script can now do what it needs to do.
I have a very very rough version written up so far, but it’s not available to download yet.

Here are some screenshots of what it’ll be able to do though ! πŸ™‚

WiFi Information screen

WiFI Client connection screen

WiFi Hotspot setup screen

I’m in the process of prettying up the GUI but in the meantime, this is functional enough πŸ™‚
I’ll get the demo up and running soon enough too ! πŸ™‚

I have released the PHP files for this – Please check this post for details.