Loading...

Posts Tagged ‘AJAX’

iPhone Home Controller v1.4

Wednesday, October 1st, 2008

Note: if you have not set up your PC as a server with PHP and MySQL read the full tutorial here. After you have that done and have purchased x10 hardware to control you can go ahead with the iPHC 1.4 install as below.

Well iPHC version 1.4 is finally here. It is pretty much an entire overhaul of the guts of the system, really deserving of a 2.0 title. I am going to hold off on the 2.0 launch until I get this version skinned up nicely and bug free. You can download the 1.4 package here.

This version only requires uplading the SQL file to your computer (maybe using phpmyadmin) and placing the code and folders in your main folder on your server. The SQL file will create a database and 2 tables within it. Once you have that installed you can administrate the entire system from the iPHC interface. Add lights, create schemes, etc… There is still some kinks and I think more functionality is needed as well but it is a fairly good working system. The CSS (this version does not include images - CSS styling only) and HTML need cleaning up but I will just do that as I prepare the 2.0 release. As usual, I am not the most savvy Javascript or PHP guy so if there is anyone out there that would like to help clean up the code or has any suggestions on improvements or bugs please comment and let me know.

iPhone Home Controller v1.3

Tuesday, June 24th, 2008

All right everyone, I finally got a chance to post about version 1.3. If you are new to this site then check out the full tutorial here.

In this version I add MySQL to take care of light status and to ease the amount of coding needed for the interface. If you are a MySQL novice like I am you should probably use phpMyAdmin for easy database and table setup. Set up a database and import the sql file included in the 1.3 package. This will set up tables that correcspond to my current configuation at my house. You can of course set this up however your system requires. If you need to install MySQL, you can get version 5 which I used, here. If you want to check out a tutorial on how it all works with PHP and Apache check this tutorial.

The database is really just for having icons that reflect the status of the lights. It works fairly well except for the fact that a manual triggering of any light will not update the database and therefore the icon will be incorrect.

In this version I have also rewritten the JavaScript and CSS for the interface, opting to go for a custom look and smaller files rather than the bulky and clunky iUI script. There is no sliding windows in this version but I didn’t think it was really that needed.

If you check out this version you will also see that I have created a section to control my door. I bought a door lock that would typically be used where the door is unlocked with a buzzer. I am using a x10 relay module and a bit of PHP to send the “buzz” and then closing the connection with PHP (check tutorial 1 for more info on how this system works).

All in all the new system is lightweight and quite functional. Stay tuned for more as I have begun to collaborate with another developer with a better grasp on PHP and MySQL then I have… Should be good stuff.

Download: iPHC v1.3

iPhone Home Controller v1 - PHP and AJAX Breakdown

Sunday, December 9th, 2007

Welcome, if this is your first time here, check out the full tutorial on controlling your home using the iPhone and x10. If you already have set up an x10 interface using your home PC, Apache and PHP, then read on for an easy PHP and AJAX breakdown of the code that drives the interface.

After many hours of playing around with the Activehome Pro CM15a interface and re-writing the code that makes it work on the web about 100 times, I have come up with a very simple few bits of code that anyone, running the CM15a with PHP, and Apache installed on their computer, can use to turn a device, or series of devices on or off with X10 and an iPhone or iTouch, or any web browser, or using the NIntendo Wii (which I do sometimes for shits and giggles). My main goal was to create a simple on/off button that worked without a page refresh. That required AJAX. Here is the simplest breakdown I have been able to come up with for all the necessary code. I am not going to post any CSS files this time but I will post my latest version, CSS and all, here soon!

The HTML:

<a href=”javascript:void(0);” name=”a1 on” id=”a1″ onclick=”lightUp(this.name)”>Turn A1 On/Off</a>
<div id=”response”></div>

The JavaScript:

var xmlHttp
function lightUp(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert (”Browser does not support HTTP Request”)
return
}
var url=”test.php”
url=url+”?q=”+str
url=url+”&sid=”+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open(”GET”,url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState==”complete”)
{
var result= xmlHttp.responseText;
document.getElementById(’a1′).name = result;
var temp = new Array();
temp = result.split(’ ‘);
if (temp[1]==’off’){
document.getElementById(’response’).innerHTML = “you turned a1 0ff”;
}
else {
if (temp[1]==’on’){
document.getElementById(’response’).innerHTML = “you turned a1 0n”;
}
}
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject(”Msxml2.XMLHTTP”);
}
catch (e)
{
xmlHttp=new ActiveXObject(”Microsoft.XMLHTTP”);
}
}
return xmlHttp;
}

The PHP (test.php):

$q=$_GET["q"];
$send = “ahcmd.exe sendplc”;
if ($q==’a1 on’){
exec(”$send $q”);
echo “a1 off”;
}
else {
exec(”$send a1 off”);
echo “a1 on”;
}

That’s it. Pretty simple huh? If you come up with anything that you would like to share please comment here.

iPhone Home Controller - Project 1 v1.2

Wednesday, November 28th, 2007

iPhone Home Controller version 1.2

We have upgraded version 1.1 with a re-vamp of the AJAX form submit. Goodbye jQuery (for now). I was able to get all the same functionality (and more) out of a smaller script that required no additional JavaScript library to be available for it to work. Now, when a light is turned on/off, the form is posted with AJAX and then the appropriate style of light icon is pulled up and replaces its opposite. The script I made for this purpose is a bit repetitive and therefore bigger than I think it needs to be, but it works so I am happy with that for now. If anyone can suggest a better way to code this please let me know.

Another change in this version is the addition of a MySQL database to hold the status of the lights. This allowed me to combine the on and off buttons on all the lamps and pull in the current status of the lights when the page is first loaded (the rest is handled by the above mentioned script). It was fairly simple to set up the database and with a few tweaks to the PHP.ini file, I was up and running.

We are going to be starting a similar project with the same interface but a Basic Stamp and Parallax PINK server as the base so stay tuned for that. Until then, if you would like you can download the iPhone Home Controller v1.2 PHP, JavaScript and HTML files using the link in the sidebar to the right. Don’t forget that you will also need the iUI.js file found here. Peace!