Loading...

Archive for the ‘iphone’ Category

iPHC 2.5beta

Friday, May 3rd, 2013

Hi all! It’s been awhile since I made any changes to the iPHC code, so 2.5beta is a complete rewrite of the javascript and php. I’m using Jquery 1.9 on this one and have reduced the entire package size a bit. The “modules” SQL table is now different from before and therefore the beta package is NOT FOR UPGRADES.

If you are doing a fresh install or have some coding (mysql,php) abilities you can check this release out and let me know if there are any issues etc… Once I have a package that will allow upgrading from old versions to new i’ll take 2.5 out of beta and release the upgrade package.

The look of 2.5 is the same, its just the framework that has been redone. Should be leaner and a bit quicker. http://iphonehomecontroller.com/examples/iphc2_5beta.rar

Guide: iPHC on Ubuntu Linux

Friday, February 22nd, 2013

NOTE: This is a copy from http://somethinginteractive.com/blog/2009/05/06/guide-x10-cm15a-ubuntu/

Here is a step-by-step guide to getting the X10 CM15A USB module to work under Ubuntu on a personal home computer, and then to further get the iPhone Home Controller web-based interface to connect with that module. For those that know what all that means, great! For those that don’t, well in the simplest of terms, it allows me to turn the lights in my house on/off or dimmed – just by accessing a website via my iPhone or computer.

This process requires several different packages of files and programs, etc. so follow the steps very carefully!

I use the sudo command a lot in the Terminal, go here to find out what sudo does, and means.

Step 1:

You need to have a flavour of Linux installed on your PC with Apache, MySQL and PHP setup correctly. I used the Ubuntu Server Edition (Jaunty Jackalope). If you are unsure of how to set this up I suggest reading up about it here first (this is a guide for the previous version of Ubuntu, but should still apply to the current version).

NOTE: Please write down ALL of the passwords and usernames you make/use in the installation process of Ubuntu as you will need these to perform certain commands and/or access certain applications throughout the rest of this guide.

Step 2:

After you have installed Ubuntu Server Edition, you may not be savvy with a command line interface for operating the system. As servers go, it’s not recommended to run a GUI on them, however if it makes it easier for you (and it did with me in this process), venture here to learn how to install one.

Step 3:

Unfortunately, I still recommend using a command line interface to compile the drivers and the interface, so get to know the Terminal application within the GUI (under the Ubuntu OS menubar: Application > Accessories ). It will allow you to run commands and install additional applications down the road.

With that said, you need to now install the latest sources of the gcc compiler library. Load up Terminal and type the following at the command line and press enter:

sudo apt-get install gcc build-essential

If this command asks you to enter the password (as it did with installing the GUI for Ubuntu), then enter it.

Let the computer do its thing, and if it asks to install a certain amount of megabytes of programs, agree to it and continue.

Step 4:

Once that is all completed, you should now be all set up to start installing the drivers and controllers.

There are a number of attempts at people trying to program a driver to communicate with the CM15A USB transceiver out there, but the only one that seemed to still be actively developed (as of today), where the developer actually managed to work with me on the implementation, and whose programming code I had the pleasure of compiling successfully was/is by Jim at Eclipse Home Automation. His controller requires the stabilized USB library and also the Compatibility layers required for the USB library. The controller interfaces with the USB library, which in turn sends commands to the transceiver.

Load up your browser (the default browser in Ubuntu is Firefox) and download the following files to your desktop on Ubuntu:

libusb-1.0 from Sourceforge

libusb-compat-0.1 from Sourceforge

Jim’s CM15A demo controller from his site

Step 5:

After those have been downloaded, you’ll see a number of tar.bz2/tar.gz files on your desktop. These are compressed files packages that contain the driver libraries and controllers. Decompress these packages by double clicking on them and extracting the files to appropriately named directories (aka “folders”) for each package so as to not merge their contents with each other.

Step 6:

Now within Terminal, navigate to the directory that contains the libusb-1.0 files.

Within the Ubuntu GUI, you can use Nautilus (a similar application to Windows File Explorer or Apple Mac’s Finder) to see all of the files within the directory on your computer, however some tasks cannot or should not be performed with Nautilus. Go here for tips on how to navigate the files and directories in Terminal).

Within that directory you should have a series of sub files and sub-directories related to the USB library. We need to now configure, build and install this library. To do this begin typing this at the Terminal command prompt:

sudo ./configure

Once that has been completed, type the next command:

sudo make

And after that has completed, install the library with this command:

sudo make install

Step 7:

In my case, all three previous commands performed flawlessly. So the next step is to install the compatibility layer for the USB Library. Navigate in your Terminal to the directory that contains your extracted compatibility layer files. And again, you should notice another set of files and directories that contain the source files. To install the compatibility layer, we perform the exact three same commands in Terminal as we used for the USB library:

sudo ./configure

After completed, type the next command:

sudo make

Now install:

sudo make install

Step 8:

With any luck, Step 6 and 7 should have installed the USB library. Now it’s time to install the CM15A controller. Navigate in Terminal to your directory that contains Jim’s CM15A interface controller source files. All we have to do is compile the source files for this one, and this can be done by typing at the Terminal command prompt:

sudo make

The compiler will create a new file called cm15ademo within the same directory as the source files. Check to see if it is there by doing a directory listing ( dir ) at the Terminal command prompt. If the file is there, then everything worked properly. If not, I would see to make sure you are in the right directory and I would review all of the previous steps just to make sure you followed everything I’ve outlined here.

Step 9:

Congratulations if everything above went properly, you’re computer should now be able to start sending commands to the CM15A transceiver to turn on/off/dim the lights!

Before we any further, we should test to see if all of the steps above were performed correctly. If you know the dial-code for some of the plugged-in light modules/switches in your house and have your CM15A USB transceiver plugged into your computer and into an electrical outlet, then lets begin by testing a couple commands on the interface at the Terminal command prompt – the format for this is as follows:

sudo ./cm15ademo xx cmnd

Where xx stands for the dial-code of the light module/switch. In my case most of my modules are set up as:

a1 a2 a3 a4 a5 a6 etc.

The cmnd stands for the commands you can send to the light modules as follows:

on

off

dim ##

bri ##

In the case for dim and bri, the ## represents a unit of decrease or increase (out of 100 units total) to the brightness of the light.

So in my case, to turn on my kitchen ceiling lights I would use the following command:

sudo ./cm15ademo a4 on

To turn my kitchen lights off I used:

sudo ./cm15ademo a4 off

To dim my kitchen lights by a degree of 40 units:

sudo ./cm15ademo a4 dim 40

To brighten my kitchen lights by a degree of 10 units:

sudo ./cm15ademo a4 bri 10

Try modifying the codes above and turning on and off your light/switch modules in your house with the above command.

Step 10:

Step 9 should confirm that your computer is communicating with the CM15A USB transceiver. We can now install the iPhone Home Controller (iPHC) web-based interface.

Because the iPHC was scripted to run on a Windows-based system with the Apache web server with MySQL and PHP (aka WAMP or XAMPP Server), I had to make some small modifications to the scripts to get it to work on Ubuntu’s Linux web-server (LAMP). I have packaged up my modifications into tar.bz compressed file that you can easily download from my server with your web browser:

iPHC Tarball

You can use Nautilus to find and decompress this tar.bz2 file into its own directory (aptly named “iPHC”).

Now within the iPHC directory you should see three sub-directories and a bunch of php files. You need to place the main iPHC directory onto the system file-tree that Apache serves the web pages from. The default location for the Apache file-tree on my Ubuntu installation was found here:

/var/www/

And your iPHC directory of files should copied to and reside here:

/var/www/iPHC/

You can change the name of your iPHC directory to whatever you like, and for security reasons, I suggest that you later change it to a different name altogether.

Step 11:

iPHC is a wonderful little web-application that allows us to create list of buttons for all of lights within your x10 house configuration and name them appropriately. It remembers all of the names and the dial-codes of the light-modules by storing that information in a database within your web-server’s MySQL. Now you don’t have to know how to install MySQL (as it should be already installed and configured with the Server Edition of Ubuntu), but you will need to install PHPMyAdmin onto your server so that you can easily configure the database for iPHC.

To install PHPMyAdmin onto your system, go to your Terminal and enter the following:

sudo apt-get install phpmyadmin

Now you should be able to log into your PHPMyAdmin from your web browser by visiting this address:

http://localhost/phpmyadmin/

In my case I had to set up the access users for PHPMyAdmin, and initially started with the username root – I left the password blank and logged in. Later I created a password for the root account so that no-one could log in without knowing my password for the root user. As well, I also created a new user to separately access the iPHC database and that would have administrator permissions to create databases and access them. You can use the username iPHC and set a unique password that is different from the root user’s password you just set (for security purposes). Don’t forget to write your iPHC username and password – you will need this shortly.

If you have any problems with installing, logging in or setting database permissions with PHPMyAdmin, the following three links may help glean some helpful tips:

PHPMyAdmin Documentation on Ubuntu

Forum Post re PHPMyAdmin Initial Login

User Management and Authentication on PHPMyAdmin Wiki

Finally, make sure you log out of root user in PHPMyAdmin when you are done setting it up.

Step 12:

Now log into PHPMyAdmin using the iPHC user and password. You should see a menu along the top.

Click the button that says “Import”.

We are now going to import the fonehome.sql file within your iPHC folder within the /var/www/iPHC directory. Let PHPMyAdmin import the file with the default settings on that import page.

Completing that means that we have successfully set up the database for iPHC, and you can now log out of PHPMyAdmin by clicking the little square “Exit” button under the PHPMyAdmin logo on the left of the webpage.

Step 13:

Now we need to connect the iPHC web-interface to the database we just created in MySQL. To do this we need to edit the connect.php file within the iPHC folder at /var/www/iPHC/. Type the following command at the Terminal prompt and press the Enter key:

sudo gedit /var/www/iPHC/connect.php

This should momentarily bring up a new application on your screen. This program is called GEdit, and it is a simple text editor that is useful for editing text files and PHP script files.

Change the text YOUR USER NAME and YOUR PASSWORD with the ones you created in PHPMyAdmin for the iPHC database. Save the file and close the GEdit application.

Step 14:

If everything so far has been completed properly you should be able to see the iPHC web-interface and utilize its functions by visiting the following address:

http://localhost/iPHC/

Select admin at the top of the screen and use the form to add a new module. Name and enter the address of your test module and click add. Once you have entered all of your modules, you may notice them also show up in a list when you select module at the top of the screen too.

Don’t get too excited, they don’t work quite yet! We have one last step to perform before they are operational.

Step 15:

One of the best parts about Linux, is the amount of security that is embedded into the system. It can save people a lot of headaches because they aren’t normally allowed to change or run certain files on the system and make mistakes that might cripple the computer/server altogether. Only users that are administrators can temporarily operate as a super user (also known as the root user) and access and run anything.

Unfortunately this also makes it very hard for our iPHC web-interface running on Apache, to access and use the cm15ademo controller application we compiled earlier. Why?!? Because the Apache web-server in Ubuntu doesn’t run as a root user (for good reason), and we need invoke the commands on cm15ademo as a super user.

One might think, “well why not just use sudo???” Well, aren’t they smart!!! But there’s a hitch: sudo asks for a password when it is invoked from a shell command, and PHP is not programmed to create a command-line session so that it can provide a response/reply with the sudo password.

Fortunately, there is a way to use sudo without having to provide a password in Linux – AND if configured correctly, you can specifically limit a “password-less” sudo command to which users, from where on the network, to which folder on the system and on what application.

This is done by modifying the sudo users (aka sudoers) list, by accessing it with the Terminal application called visudo.

Let’s begin by typing the following in your Terminal prompt:

sudo visudo

The Terminal screen will then change content that takes up the entire Terminal window. In this screen is a list of codes that comprise the default sudo users list, as follows:

# /etc/sudoers

#

# This file MUST be edited with the 'visudo' command as root.

#

# See the man page for details on how to write a sudoers file.

#

Defaults env_reset

# Uncomment to allow members of group sudo to not need a password

# %sudo ALL=NOPASSWD: ALL

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification

root ALL=(ALL) ALL

# Members of the admin group may gain root privileges

%admin ALL=(ALL) ALL

We need to add the following code to the line below the root user privelege specification:

www-data ALL=(ALL) NOPASSWD: /var/www/iPHC/cm15ademo

And your file should look like this:

# /etc/sudoers

#

# This file MUST be edited with the 'visudo' command as root.

#

# See the man page for details on how to write a sudoers file.

#

Defaults env_reset

# Uncomment to allow members of group sudo to not need a password

# %sudo ALL=NOPASSWD: ALL

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification

root ALL=(ALL) ALL

www-data ALL=(ALL) NOPASSWD: /var/www/iPHC/cm15ademo

# Members of the admin group may gain root privileges

%admin ALL=(ALL) ALL

Make sure that you DO NOT modify anything else!! Now quit visudo by pressing the keyboard keys CTRL and x at the same time. Visudo will ask you if you want to save the modified buffer, and type ‘y’ or yes, then hit enter twice.

Visudo will return you to the Terminal command prompt and if there were any errors it will tell you in the above lines in Terminal. That means that you did not enter the above information correctly and will have to redo the above step to fix it.

I’m going to hear some flack from someone out there, that this way is very risky if not implemented properly, and why not use some other PHP method like suPHP. The problem is that suPHP is known to take a huge performance hit on the system being up to 25 percent slower. The “password-less” allowance for sudo in my implementation restricts the Apache user www-data to the specific location and specific file of cm15ademo on the server, and nothing else.

As well, if your apache installation is running a different user other than www-data, you can find that out typing ps -ef|grep -v root|grep apache all in one line at the Terminal prompt, noting the the name of the user running instances of Apache on your system. From this you will have to change the www-data to the name of that user.

Step 16:

Okay.

You’ve made it this far, and I hope you have had luck following this guide from Step 1 through 15, and that it took you a fraction of time it took me to figure this all out.

Load up the following link:

http://localhost/iPHC/

Go to the ‘Modules’ page of the iPHC controller. Click the center buttons of the modules that you have listed in your house to turn off and on your lights, and the side buttons to dim or brighten your lights.

Step 17:

>Portions of Step 17 & 18 are reused from the iPhone Home Controller Website<

To get this to work on your iPhone you will need to find out what IP address your computer address has.

At the Terminal prompt type the following:

sudo /sbin/ifconfig

It should provide you with your IP address on your computer. Go here to find out more information on deciphering the IP address from all that mumbo-jumbo spit out with the /sbin/ifconfig command.

If you don’t have a router with a firewall or anything else in the way like an internal firewall then you should be able to paste the IP address you found above into your browser address window to get to the main Apache homepage that your computer is serving.

In my case I do have a router and have to open up port 80 on it, as well as set my computer’s firewall to allow Apache and MySQL. You will have to perform a search on Google for your specific router and firewall setup.

Step 18:

If everything works out you should be able to enter the your IP address with the iPHC sub-directory in your iPhone’s Safari browser (or any other web enabled mobile device for that matter) and access your system.

For example, it may look like the following:

http://192.168.1.34/iPHC/

In Conclusion

I hope this worked out for everyone interested in setting this up. This took me a while to figure out and a lot of thanks goes to Jim for providing the LibUSB connector to operate the CM15A USB device.

While everything seems pretty straight forward, there might be some errors in this guide.

iPhone Home Controller 2.1 Release and XAMPP Lite Tutorial

Sunday, February 15th, 2009

The 2.1 iPHC release is here. Not too much as far as styling changes but I have fixed some of the html and css. The application now uses jQuery at its core for event handling. This allowed me to, as is the jQuery way, “write less and do more.” The iPHC package should work a little faster now as jQuery can speed things up a bit. If you already have the iPHC system running, you can simply delete the old files and copy in the new ones (leave your connect.php file intact - there is no need to change it). The database settings have not changed so the switchover should be seamless.

For iPHC newbies, here is a step by step guide of how I got the system up and running at my house using Windows XP, XAMPP Lite, iPHC v2.1, the x10 cm15a, and an x10 module for testing.

1. Purchase the cm15a x10 transmitter. You will need at least one x10 module to control as well (also available from x10.com).

2. Install the cm15a driver/ActiveHome interface. (you should be able to download it here or) A link to download it comes in an email after you purchase the cm15a. Plug the cm15a into a usb port that is on the computer you will be installing the iPHC system on. Then plug the cm15a into the wall.

3. Download XAMPP lite. There is a zip file or an exe file to grab. Either one is fine. I placed the main xampp folder in my “program files” folder.

4. Open the xampplite folder and click setup_xampp.bat. After you see the success message you can close the window.

5. Download and unzip iPHC2.1. Copy the iPHC2.1 folder and paste it into the xampplite\htdocs folder.

6. Go back into the xampplite folder and click xampp_start. This should start mysql and apache. Leave the window that opens, open. Only use xampp_stop to stop mysql and apache. (Note: When I tried to start mysql and apache I got error messages with apache. In my case I had to add the file “msvcr71.dll” to the xampplite/apache/bin folder.)

7. Open a browser and type localhost into the address bar.

8. You should see the XAMPP welcome screen. Choose your language.

9. You can check the status of the install by clicking on status. Then click security.

10. Setup name and password for mysql and to secure your htdocs folder. This is essential if you are going to connect your system to the internet.

11. Copy the xampplite\phpMyAdmin folder and paste it into the xampplite\htdocs floder.

12. Go to localhost/phpMyAdmin in your browser and log in using the mysql name and password you had set up earlier. If you see a mcrypt error you can ignore it or follow the instructions here to get rid of it. You will have to restart xampp and log back in to see that it has been fixed.

13. Create a database called fonhome in phpMyAdmin.

14. Select the database you created and click import. Select the fonhome.sql file that is in the iPHC2.1 folder and upload it.

15. Locate the connect.php file in your xampplite\htdocs\iPHC2.1 folder and open it using a text editor or html editor. I use PSPad. Change the user name and password to the ones you had set up for mysql earlier and save the file.

16. In your web browser go to localhost/iPHC2.1.

17. If everything went well you should be able to see the interface and utilize its functions. Select admin at the top of the screen and use the form to add a new module. Name and enter the address of your test module and click add. Go to the modules screen and try turning on and off the module you have just added.

18. To get this going on your iPhone you need to find out your IP address. If you don’t have a router with a firewall or anything else in the way like an internal firewall then you should be able to paste this IP into your browser address window and get to the main XAMPP page. In my case I do have a router and have to open up port 80 on it as well as set my computer’s firewall to allow apache and mysql. You will have to search on how to do this for your specific router and firewall setup.

19. If everything works out you should be able to enter your IP address/iPHC2.1 in your iPhone browser (or any other web enabled mobile device) and access your system.

If there are any questions or comments let me know. I’ll add more as I keep testing.

Download iPHC2.1 here.

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

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!