[juneau-lug] X10 PHP script
- From: Jamie <jamie@xxxxxxxxxxxxxxxxx>
- To: JLUG <juneau-lug@xxxxxxxxxxxxx>
- Date: Wed, 01 Mar 2006 10:01:11 -0900
X10 is an electrical control system for home automation. You plug your
light or whatever into an x10 switch box and control it by modulating a
signal on your house wiring. One linux program that interfaces to a
controller is called BottleRocket (br is the executable). So from the
command line you say something like: "br A10 on" or "br A16 off". Next
I wanted a web page that would issue the commands, but it was too big
for my web enabled cell phone. So it got shortened and the following is
the tiny working version of the script that my mobile phone can use to
switch electrical devices on and off in my home.
<?php
$thisfile = $_SERVER['PHP_SELF']; //Have to set this for heredoc
$A_form = <<< EOFORMA
<FORM METHOD="post" ACTION="$thisfile">
<SELECT name="codeA">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
</SELECT><br>
<INPUT type="submit" name="Button" value="ON"><br>
<INPUT type="submit" name="Button" value="OFF"><br>
</FORM>
EOFORMA;
function mainPage($message) {
$M_form = <<< EOFORMM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>X10</TITLE>
</HEAD>
<BODY>
<H2>X10</H2>
$message
</body>
</HTML>
EOFORMM;
echo $M_form;
};
function ExecCmd($c) {
global $thisfile;
$C_form = <<< EOFORMC
<HTML><HEAD>
<meta HTTP-EQUIV="REFRESH" content="2; url=$thisfile">
<TITLE>Exec X10 cmd</TITLE>
</HEAD>
<BODY>
<h2>$c</h2><br>
EOFORMC;
echo $C_form;
$c = "/usr/bin/br ".$c;
$res = system($c,$rc);
if ($rc <> 0 ) {
echo "<br><pre>Return Code=$rc</pre><br>";
echo "<pre>Message=$res</pre>";
};
echo "</body></html>";
}
//---------------- Form Control Branching ----------------------------------
if (!$_POST['Button'] ) {
// First time - show the A form
mainPage($A_form);
}
else ExecCmd( 'A' . $_POST['codeA'] .' '.$_POST['Button']);
?>
------------------------------------
The Juneau Linux Users Group -- http://www.juneau-lug.org
This is the Juneau-LUG mailing list.
To unsubscribe, send an e-mail to juneau-lug-request@xxxxxxxxxxxxx with the
word unsubscribe in the subject header.
- Follow-Ups:
- [juneau-lug] Re: X10 PHP script
- From: East Wind
Other related posts:
- » [juneau-lug] X10 PHP script
- » [juneau-lug] Re: X10 PHP script
- » [juneau-lug] Re: X10 PHP script
- » [juneau-lug] Re: X10 PHP script
- » [juneau-lug] Re: X10 PHP script
- » [juneau-lug] Re: X10 PHP script
- » [juneau-lug] Re: X10 PHP script
- » [juneau-lug] Re: X10 PHP script
- » [juneau-lug] Re: X10 PHP script
- » [juneau-lug] Re: X10 PHP script
- » [juneau-lug] Re: X10 PHP script
- [juneau-lug] Re: X10 PHP script
- From: East Wind