Now that I have two switches for my garage door, I need to put them to use on my web site. The original posting by Tod had images for open and closed. I wanted to add a half-open image and also wanted to create .gif images that actually showed the door moving as the real door was moving. So I have these:
and (click each to see them move)
So, with a few changes to the PHP code, I was able to get the door to look like it is opening on the iPhone, or Driod, or iPad, or Mac, or whatever runs a webbrowser. Here is the code:
<?php
define(SERVER, “www.example.com”);
define(DEST, “192.168.1.6″);
define(PORT, “2000″);
define(DOORTIME, 15);
// this function will send a command to the device and get the results back function
wiflyExecute($commands) { $script = ‘log_user 0; spawn telnet ‘.DEST.’ ‘.PORT.’; expect -exact “*HELLO*”; send — “\$\$\$\r”; expect -exact “CMD\r”; ‘.$commands.’; expect -exact “> “; send_user $expect_out(buffer)”; send — “close\r”; expect eof;’; exec(“/usr/bin/expect -c’”.$script.”‘”, $stdout); return($stdout); }
// Get the door state. It could be open, closed or in between.
$doorState = wiflyExecute(‘send — “show io\r”;’);
$s1 = ((hexdec($doorState[4]) & hexdec(“0×4000″)) == 0 ? 0 : 1);
$s2 = ((hexdec($doorState[4]) & hexdec(“0×0010″)) == 0 ? 0 : 1);
if ($s1 == 0)
{
$doorState = “closed”;
}
elseif (($s1 == 1) && ($s2 == 1))
{
$doorState = “half”;
}
else
{
$doorState = “open”;
}
// Get the garage temperature and convert it to fahrenheit
$doorTempC = wiflyExecute(‘send — “show q 5\r”;’);
$doorTempC = (((hexdec($doorTempC[4]) & hexdec(“0xfffff”)) * 3.3) / 10000);
$doorTempF = (($doorTempC * 9) / 5) + 32;
$doorTempF = round($doorTempF);
if (isset($_POST["control"]) && $_POST["control"] == “activate”)
{
$status = ($doorState == “closed” ? “opening” : “closing”);
wiflyExecute(‘send — “set sys output 0×0080 0×0080\r”; sleep .5; send — “set sys output 0×0000 0×0080\r”;’);
header(‘Location: http://’.SERVER.’/garage-door.php?status=’.$status);
}
else
{
print(“<html><head>\n”);
print(“<meta name=’viewport’ content=’width=device-width; initial-scale=1.0; maximum-scale=1.0;’>\n”);
if (isset($_GET["status"]))
{
print(“<meta http-equiv=’refresh’ content=’”.DOORTIME.”;url=http://”.SERVER.”/garage-door.php’>\n”);
$doorState = $_GET["status"];
}
print(“</head><body>\n”);
print(“<form action=garage-door.php method=POST>\n”);
print(“<input type=hidden name=control value=activate>\n”);
print(“<table align=center border=0 cellpadding=5 style=’border-collapse:collapse;’>\n”);
print(“<tr>\n”);
print(” <td align=center><img src=’images/garage-”.$doorState.”.gif’></td></tr>\n”);
print(“<tr>\n”);
print(” <td align=center><input type=submit value=’Open / Close’ style=’font-size:14pt;width:170px;height:35px;’></td></tr>\n”);
print(“<tr>\n”);
print(” <td align=center><br><b><big><big><big>$doorTempF °F</b></big></big></big></td></tr>\n”);
print(“</table>\n</form>\n”);
print(“</body></html>\n”);
}
?>
You should also be able to see the temperature reading and conversion from Celsius to Fahrenheit. The temperature is displayed below the opener in an easy to read size. The temperature is not working correctly right now. This is something that I am still working on. I may have to send a message to the maker of the WiFly to get a few questions answered. The problem is that the ADC is not reporting the correct voltage on the input pin. I measure something like .23 volts (which is 23° C) but the ADC reports .062136 volts. The offset is not linear either, so I need to read more documentation or ask the manufacturer as to what I am doing wrong.
I think that is pretty good progress, so maybe I can relax a little bit this weekend.





