Loading...

Posts Tagged ‘x10’

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 thanks to my man at http://www.iphone-home-automation.com/. 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.

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 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 - 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!

iPhone Home Controller - Project 1 v1.1

Tuesday, November 13th, 2007

iPhone Home Controller Project 1 v1.1Here is version 1.1 of the Home Controller project. In addition and revision to what I posted in “Control Your Home With Your iPhone“, I have incorporated the JavaScript and some of the CSS from the iPhone User Interface, aka iUI, project. The iUI gives some of the look and functionality, mainly the sliding panel navigation, of the iPhone’s internal apps to a webpage or webapp for the iTouch and iPhone.
Other than that I have decided to go with Safari’s native submit button style and simply changed the background colors to suit. The light interface now also includes a dim and brighten option for all light modules that support it.

  • HTML - some of the markup changed from the first project because of how the iUI works but everything is still forms and input buttons. The one other difference is that I am using the “bright” function now so lights can be turned up as well as down:

    You can view the HTML file here.

  • CSS - the new CSS file incorporates some of my original coding and some plucked from the iUI.

    View the complete CSS file here.

  • PHP - the markup has not changed since version 1. I am still wishing that I could get the ActiveHome SDK software’s “queryplc” function to poll devices and return on/off and dim status.
  • JavaScript - as I stated above I have used the iUI iUI, the iPhone user interfaceto achieve a interface that is more like the rest of the iPhone’s native applications. I didn’t change anything in the iUI script save for changing the slide rate from 20 to 90. With 20 as the slide rate my interface was quite clunky.

That’s it for now. The next update will be soon, once I get my doors to unlock with the system. And then on to the TV! I promise there will be a video demo soon. You can download the files for this version in the sidebar to the right. Peace!

Control Your Home With Your iPhone

Monday, November 5th, 2007

Photo of my iPhone with the home control interface web page up and workingProject 1

Note: this tutorial has been updated, as well as the download package. If this is your first time here browse the below info and then refer to this updated tutorial for the current iphc download and reference. For a better idea of what the process has been in making this system read all the posts if you have time.
Welcome. In this project we are going to set up a home automation scheme using x10 automation hardware and a Safari/iPhone/iTouch optimized web interface controller. The cost of this project is minimal, the only monetary input was for the x10 modules ($10 and up depending on what you buy), the ActiveHome Pro USB interface (CM15A - $50), and the not so minimal cost of the iPhone/iTouch (note: this project will serve a web page to any computer but the interface design is specific for the iPhone/iTouch). I bought a simple $100 kit that included the USB module, a lamp dimming module, an appliance module and an RF light socket module among several other parts. The little kit was enough for my tests since I was new to x10 and what it could do. Now the good part about all of this is the rest of this is 100% free outside of your cost in time. Here’s what you need to do it:

The Hardware and Software

  • ActiveHome Pro USB interface CM15A
  • The ActiveHome Pro SDK and ActiveHome Software: the software (that comes with the USB module) includes a driver for the module and an .exe file that allows communication to the USB module allowing developers to create interfaces in C++, VB, JavaScript, PERL and in my case PHP. The SDK includes the ActiveHome Scripting Interface document which goes through the various types of commands that can be sent/received through the interface.
  • PHP and Apache: in order to have a web page (accessible anywhere) as the control interface you need a server that has the USB module plugged into it. Since I am familiar with PHP I decided to go with an Apache install on my home PC to host my interface. Important: if you are installing Apache and PHP for this project use Apache 2.0 not 2.2. The latest version of PHP will work fine. Here is the tutorial I used for install. If you are opening your computer up to the internet like this please make sure you do it securely, and search around for ways to do this. Here is one of many tip lists out there.
  • At least one x10 module set to any address you choose.
  • iPhone/iTouch or any device that can view web pages

The Code - Please note that my mark-up is based on my basic understandings of PHP and JavaScript as well as the ActiveHome Scripting Interface. Please feel free to school me on better ways to accomplish what I have done here. Also, if anyone else is working on this or a similar project please comment below and share what you have done!

  • HTML - for this project, all that is needed to trigger an event is a form submit so the HTML markup is quite simple:

    Turn A1 On
    <form method=”post” action=”"><input name=”input” value=”a1 on” type=”hidden” /><input name=”onein” value=”1″ type=”hidden” /><input type=”submit” /></form>
    Turn A1 On and Dim A2 to 50%
    <form method=”post” action=”"><input name=”input” value=”a1 on” type=”hidden” /><input name=”input2″ value=”a2 dim 50″ type=”hidden” /><input name=”2in” value=”1″ type=”hidden” /><input type=”submit” /></form>

    View the example HTML file here.

  • CSS - of course you can skin your project however you like it but I will share what I did using the Apple iPhone Developer Center’s tips as a basis. I also incorporate YUI’s “reset.css” into all of my projects so it is included here as well.

    View the complete CSS file here.

  • PHP - I am not a PHP guru, so luckily the markup is pretty simple to get codes transmitted (if anyone has any suggestions or tips to make this better please let us know):

    One Input
    if (isset($_POST['onein'])){
    $cmdstring = $_POST['input'];
    exec(”ahcmd.exe sendplc $cmdstring”);
    }
    Two Inputs with 10 second pause between events
    if (isset($_POST['2in'])){
    $cmdstring = $_POST['input'];
    $cmdstring2 = $_POST['input2'];
    exec(”ahcmd.exe sendplc $cmdstring”);
    sleep(10);
    exec(”ahcmd.exe sendplc $cmdstring2″);
    }

    As you can see the code uses PHP’s exec() command to push the data that was input from the HTML form. The “sendplc” part is one of the commands that is included in the ActiveHome Scripting Interface. The other available codes are: sendrf - for sending x10 codes via RF, and queryplc - which is supposed to query the on/dim state of any given x10 module (unfortunately I cannot get this one to work and it seems it is broken according to the support forums - if anyone has any ideas on how to get this to work let me know as I would like the interface to be a bit more dynamic by visually representing which lights are on and off)

  • JavaScript - for this project I used the jQuery scripting library in order to submit data without a page refresh. jQuery’s AJAX form plugin worked great!

So that is pretty much all you need to know to get this done at your house. Please feel free to ask questions and make comments. I’ll add to this page as the project progresses and stay tuned for a video demo coming in the near future…
Peace!