Fish on, Fish off

by Erik Lotspeich

As technology advances and electronic devices proliferate, it is easy to envision a Jetsons-like future with esoteric and complex electronics, appliances and devices automating our homes and offices. Such a future gives reason to stop and wonder how much automation is possible today and at what price. Are a second mortgage on our home and hours of programming required?

Using a desktop system as a prototype, this article serves to demonstrate the feasibility of setting up a WAP/WML-based home-automation system on a conventional desktop Linux box running as the staging machine. Next month, we will then use this prototype to finalize the project onto an embedded device.

Background

With the flexibility of Linux and the low-cost automation hardware available today, advanced home automation can be accomplished with minimal financial and time investments. I first became interested in home automation when I discovered X10's FireCracker Kit (see Resources) and downloaded BottleRocket (see Resources). I was amazed at the ease at which lighting devices and appliances could be turned on, off and dimmed using simple Linux commands and cron. My primary desire was an automated way to toggle the lighting in my home aquarium to provide consistent lighting duration for its inhabitants. Fire Cracker, an X10 appliance module, cron and BottleRocket filled this need nicely. When I acquired a wireless phone with a micro-browser, I wondered if I could integrate the two technologies.

At elc technologies (see Resources), I played a significant role in the development of Sparkler, our newly-released open-source (GPL) project (see Resources). Sparkler allows a user with a working version of BottleRocket to control X10 devices with a WAP/WML-enabled device such as a wireless phone or PDA with Internet connectivity. Sparkler works by running as a CGI script installed on a home machine with Fire Cracker and Internet connectivity. The wireless phone runs the CGI through its micro-browser, and Sparkler will activate BottleRocket to turn X10 devices on or off as requested.

The only drawback of this system is the requirement of an ``always-on'' Internet connection such as that provided by DSL, Cable Modem or a frame-relay connection such as a T1. With the growth of low-cost broadband access in residential areas, more households are gaining such access every day.

Imagine an embedded system contained in a small family-friendly cube that contains an integrated FireCracker module and has two Ethernet ports. One Ethernet port would plug into the DSL or cable modem and the other into the home computer. It would have a simple LCD screen for configuration of IP address and other necessary network settings. It could also serve as a virtually zero-install Masquerading router with home automation capabilities built-in. Security-conscious home users would add both home automation and secure firewalling in a one-step setup.

The usefulness of such an embedded home-automation device is limited only by the imagination. On vacation and wondering if you left the coffee-maker on? Connect with your cellular phone, check the status, and if it's on, turn it off. Home security systems could be monitored by your embedded Linux box and the status could be displayed on your cell phone. Did you remember to close the windows in your apartment before you headed out to that Linux user's group meeting? Check the status on your wireless phone. Even a site administrator out with his or her family could check web server status and restart the server, if necessary, to save a trip to the office. Bored at your fiancée's parents' house? Whip out your wireless phone and show off your home-automation accomplishments. Your spouse-to-be's parents will certainly allow the marriage then!

Implementation

Sparkler was designed from the beginning to be a self-contained efficient C program that could be ported to, or easily compiled for, an embedded system. Sparkler is a work-in-progress--there is much work to be done in the areas of modularization, configurability, and integration with BottleRocket. It currently does not support the new two-way modules from X10 that allow each X10 module to report its status (on/off/dim setting), and it does not currently support dimming. It does, however, provide a powerful springboard for development in the area of home automation and implementation as a part of a more complex system.

Before installing Sparkler, it is necessary to obtain the prerequisites such as the FireCracker Home Automation kit which can be had from X10's web site, currently priced at $49 US. I have seen this kit offered for only $5.95 when X10 is running a special promotion, so shop around. The FireCracker device requires a nine-pin serial port, so if your computer happens to have both a 9- and a 25-pin serial port, figure out whether the 9-pin serial port on your computer is /dev/ttyS0 (COM1 in DOS/Windows), which is /dev/ttyS1 (COM2 in DOS/Windows). The BottleRocket installation gives the option --with-x10port to specify which Linux device to use by default--it is wise to take advantage of this feature.

Another requirement is a working web server. Most Linux distributions will install Apache by default, and this article will refer to Apache configuration directives. In preparation for installing Sparkler, add the following directive to your httpd.conf file, which can usually be found in /etc/httpd/conf on many Linux distributions:

ScriptAlias /sparkler /home/httpd/cgi-bin/sparkler.cgi

You may have to modify this location if your Apache installation runs CGIs from a different directory. Sparkler likes to be run as /sparkler currently, but this behavior will be made configurable in a future version.

After you have verified that your web server and BottleRocket are functional, you are now ready to install and configure Sparkler. The installation instructions are included with the package (obtainable from http://www.elctech.com/sparkler), but basically consist of breaking open the tar.gz archive and running (as root) make and make install. The command make install will install Sparkler in the /home/httpd/cgi-bin directory by default, so you may have to modify the Makefile if your cgi-bin directory is located somewhere else.

The installation of Sparkler will create a file called sparkler.cfg that should be located in the same directory as the Sparkler CGI. The format of the file is simple--up to eight lines of text at ten characters each (additional characters will be ignored to fit into the constrained screen formats of many wireless devices). Each line of text corresponds to a symbolic name for each light ID number on the X10 system. For example, you may have your room light on ``1'' and your fish tank light on ``2''. In this case, line one of the configuration file could be ``Room'', and line two could be ``Fish''.

Testing

You are now ready to test your installation. If your ISP has provided you with a host name for your Internet connection, you may use it. Otherwise, you may have to use the IP address associated with your connection. What you will type into your WAP-enabled device should resemble the following:

http://1.2.3.4/sparkler

Note that ``1.2.3.4'' should be replaced with the host name or IP address of your test computer. If all went well, you should see a screen on your wireless device identifying the host name of your machine and allowing you to select X10 ID light numbers to toggle on and off.

For testing purposes, you may find it useful to use a WAP phone emulator. I found the Java-based YoSpace SmartPhone Emulator useful (it is used in these screen shots). The YoSpace emulator is available for free trial (see Resources). You may scroll down to view all of the possible lighting choices. Select ``on'' or ``off'' to turn the selected light on or off.

Conclusion

Low-cost automation products are readily available in today's market. Linux allows these products to be integrated and made more powerful with the addition of freely available software. Not only should you be excited about home-automation possibilities yet to come, but you can experiment with the low-cost and easy-to-implement possibilities available now. With Linux, embedded hardware and vision, the possibilities are endless whether home automation is your career specialty or an after-work hobby. Look for next month's column that will integrate Sparkler into a real-live embedded system that can be used to create a variety of flexible home automation-schemes.

Load Disqus comments