Loading...

Posts Tagged ‘MySQL’

iPhone Home Controller 2.0 - Release and Mini-Tutorial

Thursday, October 2nd, 2008

Okay, I have stabilized the code and skinned the project a bit nicer. In this release there is an admin area that allows for adding modules and creating macros or, as I call them, schemes. The attempt in this release is to make the whole process of getting this system up and running as smooth and easy as possible. With that in mind I am going to list the simplest way to get the iPHC going on your iPhone or iTouch.

  • X10 Hardware - You will need at least the ActiveHome Pro CM15a USB module plugged into your computer and into the wall, and one x10 module. There is a driver that should come with the module that will need to be installed as well (not sure if it is mac compatible).
  • Apache/MySQL/PHP - The easiest way to get these up on your computer is XAMPP. I have not tried it (yet) but I think the lite version should be sufficient for these purposes and may or may not already contain PhpMyAdmin. Or you can do it all yourself using this tutorial.
  • PhpMyAdmin - You will need this or something like it to upload the iPHC SQL file to create the database and tables. Be sure to change the settings in the connect.php file to reflect your database settings (if you upload the included SQL file the database will be called “fonhome”).
  • The iPHC 2.0 Code - The package comes with everything needed to run the system. Move all the files in the iPHC2 folder into your root web folder and upload the SQL file. Once you access the system you can begin adding modules in the admin area.
  • If you want to know more about the iPHC system and how it works check out the other tutorials and posts in the sidebar. The earlier posts go into the nuts and bolts of how everything functions.

Well that is about it. If you have any questions or comments please leave them here. I plan on doing a more invloved admin area for the 2.1 release so stay tuned for that. Peace.

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.

Control Your Home From Your iPhone 2.0 - Full Tutorial

Wednesday, July 2nd, 2008

To celebrate the release of the iPhone 2.0 this post is an expansion of my original tutorial and goes through everything you need to do, step by step, to control your lights, doors, etc… using x10 and PHP technology all from your iPhone 2.0/iTouch. This tutorial assumes that you have a working knowledge of HTML, CSS and PHP, and have downladed the iPHC v1.3 files.

Step One: Web enabled device - any device that can connect to the Internet will work once you have everything set up. (Note: The iphc1.3 package includes an iPhone/iTouch specific interface, but still looks good in a web browser on a PC.)

Step Two: Web Server with PHP - You’ll need a web server that has PHP installed on it. Most likely it will be an install on your home PC because you have to have the ActiveHome x10 USB module plugged into the computer controlling the house. The module comes with a driver download which will be necessary as well. My install is on Windows XP running Apache, PHP and MySQL. The interface can work without MySQL but it is cooler with it so I have included an SQL file in the iphc1.3 download.  This is the tutorial I used for Apache, PHP, and MySQL install on a Windows PC. I also suggest installing phpMyAdmin to make working with your databse(s) and uploading the iphc1.3 SQL file easier. You will need to create a database (I called mine “fonhome” - haha) before uploading the SQL file btw.

If your install goes well you should be able to replace the contents of htdocs with the files from the iphc1.3 download, open your browser and type in localhost, and see the interface. Download the iPHC version 1.3 here (the code is not well commented yet but I will be adding more comments soon). If you are using a router you will have to configure it before you can connect to your interface from the Internet via your ip. I am not sure if this is possible for every isp but it works for me.

Look up your computer’s ip address in the command prompt by typing ipconfig. Allow that address on port 80 in your router and you should be able to get through to your interface through any web enabled device using the ip address that is currently provided to your by your isp (check your ip address here). Do this carefully! There are tons of tips on doing a safe and protected Apache install using the .htaccess and Apache’s htpasswd so check them out. Opening your computer to the public can be risky guy.

Step Three: The Hardware - There are many different modules out there that accept incoming x10 signals. For this tutorial you will need at least the ActiveHome Pro USB module plugged into your computer running PHP and into the wall, and one x10 module. I bought a package that included several modules (most importantly the USB one) that was perfect for testing. I also purchased a x10 Universal Module and Schlage Electric Door Strike for unlocking my door remotely (the code for which is included in iphc1.3).

Step Four: The Code - At this point you should at least be able to view “localhost” in your web browser and manipulate the pages in your main web folder.

The way the interface works is quite simple. There is an .exe file (ahcmd.exe) that is available in the ActiveHome SDK for the ActiveHome Pro that allows x10 signals to be sent through your house using PHP functions to trigger the events (I have included the exe file in the iphc1.3 package but not the full SDK documentation). This file will need to be included in your main web folder where your index is located (or at least somewhere that you can point to it).
The PHP: This is the line of PHP code that turns any x10 module set to address A1, off:

exec(”ahcmd.exe sendplc a1 off”);

ahcmd.exe accepts several commands, sendplc being one of them. There is more documentation on the accepted commands here but this system uses sendplc exclusively. The function is carries out by PHP’s exec command which you can learn more about here. In addition to the “off” function there is also “on” (duh), dim and bright.

The most efficient way to trigger an event using HTML and PHP is AJAX ( or AJAH more appropriately depending on who you ask). Either way, I decided to go with that in the iphc1.3 code and also featured it in my “iphc PHP and AJAX Breakdown” post which you can view here.

Macros: To make a series of x10 events, you really only need to copy the above code for as many events as is needed and change the addresses/statuses. I have found that using PHP’s sleep function to put a second or two (or more depending) between events makes for a more reliable macro. Once again, my full code is included in the iphc1.3 download.

The CSS, Javascript, HTML: I have used some Javascript to make the navigation buttons work, as well as to hide the navigation bar on the iPhone. The css provided is a “green” theme including several icons that can easily be swapped out. The HTML is well, HTML. If you think it is messed up, let me know. Everything is set up to look spiffy on the iPhone 2 interface.

That’s all folks! Let me know if you have any questions.

PS - I am still working on a little video to show the interface in action, and a iPHC version 2.0. Stay tuned.

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!