Lego Laptop

Posted: March 2nd, 2010 | Author: Rob Lynch | Filed under: Computers, Tech, What I'm Doing | Tags: , , , , , , | No Comments »

Lego Digital Picture Frame

The guts of an old laptop
Ubuntu 9.10 Karmic Koala (linux distro)
Screenlets (widget software)
A handful of cron jobs
Motion (motion detection software)
a USB Webcam
and a bucket of Legos makes a…

Lego Internet Thingy!

It displays the time, local weather, news, twitter and latest emails via Screenlets.

The Motion software uses the webcam to look for movement or changes in lighting allowing the screen to shut off when not home or asleep.

A daily alarm is scheduled via crontab which shuffles through my iTunes library music to wake me up in the morning. If Motion detects movement the music stops.


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: , , , , , , , , , , | 2 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.