Baby Monitor Ferris Wheel Web Control

In a previous blog, I demonstrated how to control a 6ft Knex ferris wheel from a raspberry pi command line. Now we will build on that to show web control.

In order to follow this blog, please read the previous blogs on how to setup the baby monitor as all of the prerequisite steps are documented there.

First, create a web page called ferris3.html in /var/www/html wwhich looks as follows

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
<link rel="stylesheet" type="text/css" href="css/style2.css">
 <TITLE>ferris Wheel Page</TITLE>
 <meta http-equiv="refresh" content="300">
 </HEAD>

 <BODY>
<h1 style="text-align: center;">Ferris Wheel Page</h1>
<a href="./playfile.php?run=true&argument1=00_fair0.mp3">Play Fairground Music</a><br>
<a href="./playfile.php?run=true&argument1=00_fair1.mp3">Play Alternate Fairground Music</a><br>
<a href="./ferris.php?run=true&argument1=180&argument2=none">Start Ferris Wheel For 3 min</a><br>
<a href="./ferris.php?run=true&argument1=0&argument2="none">Stop Ferris Wheel</a><br>
</BODY>
</HTML>

 

I have already documented the playfile.php so read all of the Baby Monitor blogs. Then create a file called /var/www//html/ferris.php which looks as follows:

<?php

function isCommandLineInterface()
{
 return (php_sapi_name() === 'cli');
}

if (isCommandLineInterface()==TRUE)
{
 $argument1 = $argv[1];
 exec("/usr/bin/python /var/www/html/knexon.py $argument1");
}
else
{
 if ($_GET['run'])
 {
 $argument1 = $_GET['argument1'];
 # This code will run if ?run=true is set.
 $output=exec("/usr/bin/python ./knexon.py $argument1");
 echo "<pre>$output</pre>";
 header("Location: ./ferris2.php");
 }
}
?>

Ensure that both scripts are owned by www-data as follows:

sudo chown www-data:www-data ferris.php ferris3.html

lastly edit /etc/rc.local and add the following 2 lines for the exit 0 at the end

chmod o+rw /dev/mem
chmod o+rw /dev/gpiomem

sudo nano /etc/rc.local

(and use cntrl-x to save and exit)

Now use your browser to get to your raspberry pi web server web page (ferris3.html)

Dont believe is that simple ? Check out this youtube video

WhereThingsAreBorn 🙂

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s