Kevin McCallister would’ve got a kick out of this: iPhone X10 Remote Control (How To Part 1)

Posted: January 3rd, 2010 | Author: Rob Lynch | Filed under: Computers, General, Scripts, Tech, Web, What I'm Doing | Tags: , , , , , , , , , , | No Comments »

I recently got my hands on an X10 Firecracker Kit to control my appliances and lighting remotely in conjunction with automating certain daily routines such as turning on an air purifier, air conditioner or a space heater.

Get the Flash Player to see this video.

Below is simplistic approach I took to setting up a basic wireless remote system that is accessible via the net. It’s a result of a few hours work and is fully functional, but is far from complete Anyone looking to do this should have an intermediate understanding of how Windows, Apache, PHP and SQL work. I based the foundation of this system off of a project featured 4 years ago on Hak.5: How to control your lights from an internet enabled cell phone (Episode Video) (Project Wiki). I augmented the project by incorporating a mysql database for keeping track of appliance status and swapped out the undocumented, executable that talked to the firecracker with one that actually explained the syntax. In part two I’ll take on the automation aspect of the project.

What to use:

What to do:

1. Setup and configure the Firecracker as recommended by X10. Hook up the COM port module, install, configure and test with X10 software to confirm everything is working out of the box.

2. Stop the x10 Device Network Service (x10nets) and set the service status to disabled or manual to free up the COM port.

3. Download Adam Brigs’ CMA17 Protocol and attempt to turn on/off devices with it from the command line. The syntax is very simple and allows for multiple devices to react within one call. For example to turn on appliance 1 on channel A using COM 1 you would type: cm17a 1 a1on

4. Install and configure Wamp server adjusting the httpd.conf to your liking to allow access to the server from other IPs. If allowing access via the web as a minimum set up basic authentication with .htaccess.

5. Using phpMyAdmin in Wamp create a database called “x10″ and be sure to create a user with sufficient privileges to read/write or add a password to the root account.

6. Insert a table called appliance_status (download sql table structure and example records)

7. Modify or add records to appliance_status.

Row Definitions:
uid = unique identifier
appliance_id = x10 receiver id number and frequency
status = If device is on of off (bool 0 = off 1 = on)
last updated =  last request sent to server (self updating current timestamp)
appliance_name = friendly appliance name

8. Copy code to x10.php and place in www directory.  Be sure to adjust the first set of variables values as necessary ($cm17a, $comport,$ dbhost,$dbuser,$dbpass).

<html>
<head>
<title>X10 iPhone Remote</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<link rel="apple-touch-icon" href="/iphone.png" />
<link media="only screen and (max-device-width: 480px)" href="/iphone.css" type= "text/css" rel="stylesheet" />

</head>

<body>

<?php
$comport = ‘1′;
$cm17a = ‘c:\wamp\www\cm17a’;

$dbhost=’localhost’;
$dbuser=’root’;
$dbpass=’x10′;
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error Connecting to mysql’);
$dbname = ‘x10′;
mysql_select_db($dbname, $conn);

if(isset($_GET['ChangeStatus'])) {
system($cm17a . ‘ ‘ . $comport . ‘ ‘ . $_GET['App'] . $_GET['ChangeStatus']);

if($_GET['ChangeStatus'] == ‘On’)
{
$UpdateStatus=1;
}else{
$UpdateStatus=0;
}

$updatesql = “update appliance_status set status = ” . $UpdateStatus .” where appliance_id = ‘” . $_GET['App'] . “‘”;
mysql_query($updatesql);
}
?>

<p align=”center”>
<table>

<?php

$get_apps = mysql_query(“SELECT * FROM appliance_status”);
while($row = mysql_fetch_array($get_apps))
{
$aID = $row['appliance_id'];
$aName = $row['appliance_name'];

if ($row['status'] == ‘0′)
{
$aStatus=’Off’;
$aChange=’On’;
}else{
$aStatus=’On’;
$aChange=’Off’;
}

$aDate = $row['last_updated'];
echo ‘<tr><td><font size=”10px” face=”geneva, arial, san serif”>’ . $aName . ‘</font></td><td><a href=”?ChangeStatus=’ . $aChange . ‘&App=’ . $aID . ‘” ><img src = “/’ . $aChange . ‘.jpg” width =”75″ border = “0″ </a></td></tr>’;

}

mysql_close($conn);
?>

</table>
</p>
</body>

9. Add on and off jpegs to www directory (download buttons.zip)
10. If all is well you should be able to navigate to the x10.php and turn on and off your appliances till the cows come home. Enjoy.


Take off your glasses. Oh… wait, wait. Let down your hair. No: glasses on, hair back up. Let’s just get that hair right back up.

Posted: December 29th, 2009 | Author: Rob Lynch | Filed under: Guilty Pleasures, TV | Tags: , , | No Comments »


Jordan vs Bird

Posted: December 28th, 2009 | Author: Rob Lynch | Filed under: General | No Comments »

Basketball just ain’t what it used to be.

Video games are a different story: http://www.retronintendogames.com/j/jordbird/


My Death can beat up your Death

Posted: December 27th, 2009 | Author: Rob Lynch | Filed under: Music | Tags: , , , , | No Comments »

Text Message Dramatization:

C: I found this reissued album from a band named Death. I’m really digging it. You should check it out.
Me: Death? I used to listen to them when I was in high school! What album did they re-release?
C: “For the Whole World to See”
Me: (After googling the album) My Death can beat up your Death.


The Lego iPhone Dock

Posted: November 30th, 2009 | Author: Rob Lynch | Filed under: General, What I'm Doing | Tags: , , | No Comments »

While home for Thanksgiving my mom dug out ton of Legos from under the eves for me. I took a container of them back to Boston in hopes of putting them to good use.

My first of hopefully many Lego doodads: The iPhone Dock

Lego iPhone Dock

Lego iPhone Dock