Embedded Linux and Home Automation
I love home automation (HA). Ask me a question about it and you will be lucky to leave without hearing one of my lectures on the subject. So when Phil Hughes asked me to write an article on embedded Linux from an HA perspective, I jumped at the chance. There was just one catch: I had a week to write the article. I've been working on HA for 20 years. My background in computers is varied, both hardware and software, but for the last 13 years I have concentrated on networking.
My vision of HA relies on distributed processing, a realm where embedded computing is a must. The Linux OS has a great advantage here not just because it's free (as in beer) but because of its wealth of tools, the vast knowledge base of the Linux community and its light step on system resources. (Ever see NT run on a 386SX?) I'm not saying that Linux will be embedded in every processor board I use; there are cases where a small controller chip won't need an OS like Linux. But when the device needs to do complicated tasks on something less than PC hardware (i.e., no disks, no video, no keyboard), embedded Linux is a great solution.
A large HA project will most likely include a least one central server that handles the database aspect and program interface (i.e., web access to HA controls and information). The user interface can be anything from commands typed in via direct telnet access to a simple-to-understand GUI (yes, the clients could be Windows users). The project would also include a firewall/NAT router for Internet access, intelligent router/switches, intelligent appliance nodes, appliance/terminal servers (which hook up to non-intelligent or legacy devices) and wireless hand-held devices (PDAs with 802.11 or Bluetooth). Many CPU MIPS will be needed to handle HA needs of the future. You may be asking yourself: Is this guy nuts? Why do we need all this power if all we're going to do is turn lights on and off? You want me to put a PC in every room at every outlet? Well you haven't seen my vision of HA then. Turning lights on and off is a drop in the bucket! And as far as having a PC at every outlet, well it's not too far from the truth. It may not be a PC, but it may be as powerful. It also has to do with lower initial costs, expandability and redundancy.
While researching embedded Linux for use in HA, I discovered the usual suspects for hardware choices: SIMM computers, single-board computers, VME boards, PC104 boards and small form-factor PCs. One of the things I've noticed is that the costs tend to be much higher than the average desktop PC. Since my current projects are from a hobbiest' point of view, I've noticed that we often use salvaged or inexpensive PCs. If you've ever tried to run more than two PCs at once, you'll notice three things right away: the noise, the added heat and the increase in your electric bill. This is why it's best to use embedded systems in HA.
It all started when a friend of mine gave me an X10 Active Home kit. I didn't have any computers with Windows on them (I've been using UNIX since '85). All I had was Linux (maybe version 0.96) running on a 386SX/16MHz. BSD wasn't available yet because of the legal problems with AT&T and some of the code. So I jumped on the Internet and searched for software to drive the CM11A included with the X10 kit. CM11A is the X10 attempt at two-way communication: an interface with a small amount of built-in intelligence which needs to be connected to a PC. A few hours later, the CM11A was up and running controlling things automatically from cron. I then started to collect other pieces of software used to control other devices (not just X10).
Jumping forward a few years, I'd purchased a new motherboard for my main server and quickly discovered that I had run out of serial ports and ISA slots. (It came with PCI slots and all I had was ISA boards.) This showed me the value of distributed systems. My home automation software was now divided between two systems. My new 133MHz system with 64MB of RAM was running X, Netscape, and compiler and development software, while my 386SX was handling all the I/O to serially attached devices and performing print serving. With only 8MB of RAM, the old system was a bit weak in the user interface department but had plenty of power for handling my I/O needs. Distributed computing, it's a good thing.
Around this time, Circuit Cellar magazine (run by Steve Ciarcia) had a promotion for the HCS II. The promotion consisted of various boards for digital and analog I/O. It had a serial interface so it could be programmed and monitored. It was meant to basically stand alone though it could be told to issue various commands from the serial port and a program on the PC. One of the things that attracted me to the HCS II was that over the years Circuit Cellar had documented just about every step of the development in the magazine. This was pretty close to open-source philosophy, and it gave me ideas for a Linux interface. I also discovered that to get my vision of the perfect HA system off the ground I would need help. But I didn't know how to get that help.
Fast forward to the present. I now have a cable modem with a Netgear router acting as the firewall/NAT gateway. I originally had these services through the development server but now my wife wishes to access the Internet. Since I do development work on my server I decided to move the Internet access to a dedicated box. I used the Netgear RT311 because it was inexpensive and easy to use. (Note to the Netgear people: publish the hardware specs and we could load embedded Linux to perform additional router functionality.) Eventually I will replace this box with an embedded processor card. It'll be a diskless workstation with RAM, two Ethernet interfaces, an embedded Linux kernel (2.4 or better, via BOOTP) a few base utilities, ssh access and IP filters (the ``packet mangler ''). Just a small box, no fans, no disks. Just an extremely powerful setup with extremely flexible software.
My current system consists of two X10 CM11As (a spare for development), an Oregon Scientific WM918 weather station, a Dallas one-wire network, a Marrick LynX10, a Creative Control Concepts HCS II, an ADI Ocelot, a bunch of Dallas TINI boards and a serial IR device. I currently have all of this connected to an 8-port Digiboard serial communication board. I access the Internet via a cable modem and a Netgear RT311 router. My central server, a 350MHz ADM K6-3D running services for Appletalk, Samba and TCP/IP, is my home's HTTP server for local information (a notebook of sorts).
I also have various X10-controlled outlets and lamps. The HCS II controls X10, digital I/O and analog I/O, but it can do a lot more. The Ocelot interfaces to IR and X10, but it also can do more. In addition, I have a collection of PCs, routers, terminal servers, various I/O boards and prototype controller boards I've built. Before anyone gets the idea that I am rich, please understand that most of my equipment is second-hand and was received in exchange for computer services. Lastly, I have collected software, about 10 years worth, off the Internet. Everything from parallel-port projects for current X10 software, to serial-port networks to control other devices (all usable by Linux of course). This is well and good but none of it really fits well into a single project.
So with that in mind I started the Linux Home Automation (LHA) project, the basic premise being that if we put together a system from the ground up, we can build a single coherent system from many incoherent systems. For now we are using readily available products from the HA industry, but I envision adding additional projects using embedded Linux. Unfortunately, I managed to get sick at the start of the project in March. But as you are reading this, the LHA project will have restarted, 80 members strong.
Again fast forward this time into the future (and by my count, not far off). You and your wife are sitting in front of your entertainment system, an HDTV, with theater-quality surround sound. Your remote control looks like a PDA, a touch tablet like something out of Star Trek. You decide your are interested in a romantic movie. You perform a search via your PDA which finds a list of movies. You select one and it begins to play on the TV. You select a preprogrammed romantic lighting level and settle in with you wife. While watching the program the phone rings (note to self: reprogram romantic setting to have Send All Calls (SAC) forward calls to the answering machine), a picture-in-picture box appears on your screen with the caller ID info on it. Oops, it's you mother-in-law. SAC that call and SAC the rest. Now for a little quality time with the wife.
Seems like a fairy tale, doesn't it? Well, not really. The HDTV has an embedded processor connected to it or in it. The video feed is via a 100Mb Ethernet, which delivers an MPEG2 encapsulated program. The embedded processor handles the mixing of picture-in-picture. It also handles the Voice-over-IP (VoIP) and other data streams for control. The PDA has a wireless 802.11 interface and a connection back to the central server. An intelligent router/switch provides Quality of Service (QoS, guaranteed bandwidth). Central servers handle the database aspects of the system. And a firewall router protects the infrastructure access from outside intrusion and keeps everything inside that needs to stay inside.
The handling of the electricity is one of the more interesting aspects. Embedded processing exists at each outlet, at the switch and the circuit breaker panel. This permits control and monitoring of the system, requires less cabling and permits the user to expand and modify the system. (Have you ever wished to add a light switch to control an outlet?) It also avoids the clumsy turning on and off devices that is currently available. Even though the system may decide that lighting is not needed, the user may decide additional lighting is needed. Voice synthesis/recognition will also be available, though there may be times when it is not appropriate.
The nice thing about talking about the future is that nobody can say I'm absolutely wrong (yet). So bear with me as I take reality and twist it a little towards absurdity.
The average US home will have HDTV (the FCC said so). I say we connect the TV not to a cable system directly but to a 100Mb Ethernet. Add embedded Linux and deliver, PIP, Internet movies and IP telephony. But wait, there's more! We've all heard about the Internet 'fridge; lets take that one step further and hook up an LCD to the front of the fridge and a web camera to the inside. With this we can answer the age-old question: ``Does the light really go out when the door closes?''. But wait, it gets better; couch potatoes unite (dyslexics untie). No longer will you have to get out of that chair to search for food in the fridge! With an Ethernet connection to the fridge we can now provide a real-time feed delivered to the PIP. Surf the fridge from the comfort of the living room and never miss a minute of the big game! Your wife will love the fact that every item that gets put in the fridge (and why not the pantry?!) will be automatically scanned. (We're working with the farms for genetic bar code scans.) No longer will she have to trudge to the grocery store, fight for a good parking spot, battle with spoiled-rotten children and their parents, the clueless and lost who occupy every isle, not to mention the cart with the giggling wheels. No more waiting in line behind the same clueless. Now simply let the central server agent figure out what to order and when. Delivery to you door and with a smile!
Okay, I know that sounded pretty silly but it comes from a collection of complaints that my wife and I have about shopping and my work with IP telephony and networks. The first thing you have to understand is that the future home will most likely include networking and TCP/IP will be the de facto standard. (I'll take a guess that IPV6 will be what we're using then.) I envision the network being made up of VLANs (Virtual LANs), intelligent router/switches (the lines are blurring even now) and a server to handle DHCP and BOOTP requests. Various devices around the home will have network connections. (Some may use wireless others the power line; the media is not too important right now.) The entertainment system will probably use several VLANs on the same physical connection. This will permit a certain QoS to be delivered. The video needs to have a guaranteed bandwidth (MPEG2, 20Mb/feed per channel displayed), voice another 128K, caller ID, stock ticker and other data can have whatever is left. TCP/IP, QoS, VLANs, VoIP, MPEG2--a lot of mumbo jumbo. Whatever the standards, they will be in place and tested by the time most homes have HA.
Okay, back to the present. Let's take another look at the router. As I previously mentioned, I purchased a cable router to perform Internet Firewall, IP Masquerading (NAT) and basic routing. I paid $120, which included shipping, and I found this box a breeze to setup, install and monitor. The total time I spent was 15 minutes from grabbing the box to actual Internet connectivity (but remember I do this for a living). It comes out of the box blocking telnet, FTP and HTTP access to your home LAN, and it won't permit Microsoft's TCP/IP encapsulated NETBIOS from traveling onto the Internet. For most users this is perfect. But there are also filters available to permit access to ports on the home LAN from the Internet. This box is fine for now, but I miss the extended capabilities that I'm used to seeing in the larger Internet routers that I am used to working with. So eventually the cable router will be replaced by a Linux-based firewall router.
I have available a spare motherboard and two network cards (although they could be a single network card and serial interface or modem or ISDN or etc.). I can drop this into a thin desktop case and I'm one step away from an embedded system. This leaves me with lower electrical power usage (but not low enough in my opinion) and less heat generated, but I still have to deal with the additional noise (just the fan). I also have access to an EPROM burner (amongst other tools). Using the instructions from the Etherboot project I can create a router with no floppy, hard disk, monitor or keyboard. I've discovered that many motherboards expect to have a video board so I'll include that here. The router, using BOOTP, loads the Linux operation system from a central server and runs it in RAM disk (no swap). Everything gets set up and built on the server before hand. All the rules for forwarding, dropping, redirecting and general mangling (IP Filters) is set up on the initial RAM disk (instead of the usual hard disk). This has the benefit that if someone breaks in and alters the software on the router a simple reboot wipes out their changes. Then making the appropriate changes on the server and the repairs are made.
I'm sure a few of you out there are asking; ``Well why didn't you build the router instead of buying the cable router?'' Good question, and my answer is: I haven't quite figured out everything I wanted to using IP Filters yet. With all that power comes a steep learning curve. Well, I guess that's another mailing list to add to my topics to read.
I'm still looking for an SBC or similar small-form-factor board with low enough cost to justify the effort of replacing the PC router. The cost of many dual Ethernet boards is about the cost of a used two-port Ethernet router at the auctions. So I can't justify the expense.
There has been some talk of the Internet refrigerator. Basically everyone thinks that it's an LCD that allows you to look at things on the Internet. I sincerely hope this is not the case. A manufacturer might want to consider providing services such as eliminating the need for you to go to the grocery store. Run low on milk and the 'fridge will order you up some milk. My current concern here is that manufacturers might embed cellular technology and bypass local control of the user information. I would prefer that I dole out the information as I see fit.
If the power problems that occurred in California this last summer and in New Zealand the previous summer continue to occur in other parts of the world, we will need to monitor and control our resources with better management. Embedded systems will provide us with those tools and Linux will be at the forefront of this arena if for no other reason than lower initial development expense and the tremendous collection of available tools. I must also note that some of the industrial giants have taken notice of HA. Cisco, GE, Intel, 3COM and Microsoft have made announcements with HA in mind. Not to mention the industrial giants who have taken notice of Linux. Just imagine what the future may bring!
email: [email protected]