Step 1: Components
The components I used (in no particular order) are:
- Mini ITX computer running Ubuntu Server 11.10 (Any low-power computer with serial and audio ports will work -- the processing power requirements are very very low. In fact, it SHOULD be entirely possible to run the entire setup off of a router with OpenWRT installed -- I just happened to have a spare system kicking around
- Eken M001 Android Tablet (This is my control panel. If you want a tablet to use as ANYTHING other than a dedicated control panel, Don't Get This Model! The touchscreen and battery life are horrible, it's slower than molasses, and it runs a hacked version of Android 1.6 with most of the phone code still intact.)
-X10 Firecracker Module (This is what lets the computer talk to all the widgets you have spread around your house. X10 modules are extremely cheap on Ebay, and are the least-invasive home automation technology I could find -- important for those of us who rent.)
-X10 Mini Transciever Module (Converts the RF signals from the Firecracker module to something usable)
-X10 Lamp Module ( Lamp modules have built in dimmers, so you can set your lamp to whatever brightness you desire -- however, they only work for lamps with incandescent bulbs. If your lamps use something else, like florescent or halogen bulbs, use appliance modules instead)
-X10 Appliance Module (Appliance modules are for devices like coffee pots that are strictly on or off).
-Home Stereo System (Any stereo system with aux inputs will work)
Step 2: Setting Up the Server
Once you have Ubuntu set up, you'll need to install a few extra libraries on it so that the system has everything it needs to run. Libraries are programmer-speak for "I've written this once, and it was really complicated to do the first time, so I don't want to have to re-write it every time I want to do something similar". This is good for other people, as well -- many programmers release their libraries for free, which means that other programmers can concentrate on getting their programs to do what they want, rather than spending a lot of time writing libraries for network communications or displaying things on a screen.
In order to install libraries on a computer running Ubuntu, you need to use something called a package manager. A package manager is a special type of program that looks on the internet for a package, downloads it, installs it, and manages updates. The default package manager for Ubuntu is called apt, and is used by typing "sudo apt-get install packagename".
Note: My setup has the webserver component and the control server running on two separate machines. If you are running everything on one machine, just install all the packages on the same box -- it shouldn't make a difference.
The packages we will need to install are:
On the control server:
- bottlerocket (a program to let you talk to the firecracker module easily)
- mpd (Music Player Daemon -- a program that sits in the background and plays music back)
- python-mpd -- A library for Python that lets you run commands on MPD easily
- python-twisted -- a library for Python network communications
- python-pysqlite2 -- a library to enable Python to talk to sqlite databases
- sqlite3 -- a very, VERY simple file-based database
- screen -- A program that lets you run programs in the background, and makes sure they won't close when you disconnect from the server.
On the web server, we'll be using another package manager called CPAN, in addition to apt. CPAN is used specifically for libraries for the Perl programming language, and is ran by typing "sudo cpan packagename".
- libapache2-mod-perl2 -- This package lets the Apache web server run programs written in Perl.
- IO::Socket::SSL -- Secure Socket Layer, a secure network communication library
- CGI -- A library for letting Perl programs understand the information Apache sends to them
- XML::RSS::Parser::Lite -- This lets your programs understand XML documents, such as RSS news feeds
- LWP::Simple -- This library is used to retrieve things over the internet (also used in the News portion of the control panel).
Step 3: Configure the Control Server
edit the following lines:
listenport is the port you want the server to listen on for incoming connections
server_key is the location of the key you generated
server_crt is the location of the self-signed certificate you generated.
Most of this file should work as-is, although you will need to change the line that reads "serial='/dev/ttyS0'" to point to the actual serial port you have connected the Firecracker module to. If you only have one serial port, the default should work fine, although if you are using a usb-to-serial adapter cable, the port will be /dev/ttyUSB0.
Once you have the control server configured, to run it just type "screen python server.py" at the command prompt.
Step 4: Configuring the X10 Modules
- Firecracker serial port interface module -- this is a RF transmitter that connects to your computer
- Mini Transceiver module -- This module is an appliance module that converts the RF signal from the Firecracker into commands sent out over your houses wiring. It will always be device 1 on whatever house code you select
- Lamp Module -- This type of module uses a built in dimmer switch to set the brightness of an incandescent lamp connected to it. DON'T USE IT WITH ANY OTHER KIND OF LAMP -- you could end up frying the module, the lamp, or both.
-Appliance module -- This module is for appliances that only need to be turned off and on, or for non-incandescent lamps.
X10 modules all have an address, to allow you to control a specific device. the address consists of a house code and a device number. You can have up to 16 devices on a single house code, and up to 16 house codes. To set the house code and device number, just stick a dime in the dial on the front of each module, and rotate it to the right setting. It's worth noting, however, that you will need an additional transceiver for each house code, as the transceiver will only talk to modules that it shares a house code with.
Connecting devices to your X10 module is dead simple -- plug the module into the wall, and plug the device into the bottom of it. The modules that I have only work for ungrounded devices (two prong plugs instead of three prong) -- I'm not sure if they are all this way, or just the ones that I have.
Step 5: Configuring the Web App
Do NOT, under any circumstances, set up port forwarding so that you can access the web app from the internet -- it has no security or authentication of any kind, and if someone (for example) turned your coffee pot on while you were on vacation for a week, or started blasting your stereo at three in the morning, you likely wouldn't be very happen about it. You have been warned!
You will need to make sure you have mod_perl enabled on your web server installation. You can find more information on how to do this at http://perl.apache.org/docs/2.0/user/index.html.
Once mod_perl is enabled, copy the attached files to your document root directory -- on Ubuntu, this is /var/www/. You will need to make sure that index.cgi is executable, by running "chmod 755 index.cgi"
Very little configuration is needed here -- simply change the $serverport variable (currently pintsize.local:8635) to point to the server and port the control center is listening on. If you are running everything on the same machine, you can set the server name to localhost. If you wish to change the RSS feed the news tab pulls from, change the $xml variable in the listRSS function to point at your preferred feed. You should now be able to connect to your web app with a browser, and see it in all it's empty glory (you'll need to actually ADD things to it using the config screen before it's very useful).
Step 6: Set Up a Control Panel
Step 7: Other Ideas
- Add scripts/scheduling -- eventually I'd like to be able to set up (for example) a script to make sure I've turned all my lights off after I leave for work, or a script to start a pot of coffee when I'm on my way home; however, I ran out of time.