The Linux Letter: Embedded Linux

Linux / Open Source
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
Cheap computing power is as close as your nearest office supply store.

 

Call me a geek, but I always get excited when I acquire a new, more powerful server. To me, there's nothing quite as beautiful as a well-engineered piece of hardware, and IBM's xSeries boxes never fail to bring a smile to my face. As much as I have always loved the bigger machines, I have come to realize that for some of my projects, even a minimal desktop computer is an unnecessary waste of physical space and electricity. Thus, I found myself in a quest to find minimalist computing nirvana. What a short trip! I found all that I needed was in the diminutive and hackable embedded hardware disguised as wireless routers available at your neighborhood office supply store.

 

My wireless router of choice (for the home market) is the Linksys/Cisco WRT54GL. The very first thing I usually do when deploying one of these routers is to install an alternative firmware package, such as DD-WRT. I deviate from the factory-supplied firmware because the replacements provide all of the functionality of the original firmware but add enhancements that let me get creative crafting customized firewalls. Running the Linux kernel and using BusyBox (which provides some of the familiar *nix tools) puts me into productive and comfortable territory.

 

During one of my investigative forays, I came across some replacement firmware, called OpenWRT, that opened my eyes to the power of the little boxes. The project Web site says it succinctly: "OpenWrt is described as a Linux distribution for embedded devices." It goes on to say, "Instead of trying to create a single, static firmware, OpenWrt provides a fully writable filesystem with package management. This frees you from the application selection and configuration provided by the vendor and allows you to customize the device through the use of packages to suit any application. For [the] developer, OpenWrt is the framework to build an application without having to build a complete firmware around it; for users this means the ability for full customization, to use the device in ways never envisioned." OpenWRT is actually a fork of the DD-WRT project, decomposing the latter into component parts that can be installed or omitted as required. Thus, the limited RAM inherent in embedded devices can be more efficiently utilized.

What's the Use?

So now you're thinking "OK, Kline, other than as a wireless router, what could you use one of these things for?" If you look at the Table of Hardware, you'll see that there's more to them than meets the eyes. Scrolling down to the entry for the WRT54GL and clicking on the "supported" link will reveal that the box has two serial ports on the board; they're simply not routed to the outside of the case. With some minimal hardware hacking, you can easily add A/D converters to monitor voltages,temperatures or switch contact positions, or you could add a level converter (such as the MAX232 chip) to bring the serial TTL voltages to RS232 levels, enabling you to access serial devices. Although the WRT54GL isn't one, many of the embedded devices sport USB ports, offering even greater possibilities. Not a hardware hacker? No problem. There are still many uses for which you need not even open the box, let alone attack with a soldering iron. I'll discuss a non-trivial example shortly.

Getting Started

Loading OpenWRT onto an embedded system couldn't be easier. A basic firmware image is readily available on the download link at the project Web site. You have a choice of two flavors: whiterussian and kamikaze. (Yes, they are named after mixed drinks.) The whiterussian release is considered stable (but not yet deprecated). The kamikaze release is where development is currently concentrated. For the purposes of discussion, I'll choose the kamikaze release, and clicking on that link brings me to a page listing recent versions, the latest of which (at the time of this writing) is 7.09. (You may want to open another browser window and follow along.) Unless you know of a specific bug regression, you'll want the latest version, so click on 7.09. At this point, you may panic when you see a list of 11 folders! Where do you go from here? With the exception of the "docs" directory, each folder represents a specific embedded system. The one you need to pick can be determined by referring to the "Table of Hardware" page and looking up your specific box. For the WRT54GL, we can see that it is built on the Broadcom 5352 chipset. For Broadcom, we have two choices: brcm-2.4 and brcm47xx-2.6. But we can quickly eliminate the 47xx series, since that is for the 4710 and 4712. We're not done yet. Drilling down further, we see that there are a number of variations on that chipset. It so happens that the WRT54GL is most closely matched by the link for the openwrt-wrt54g-2.4-squashfs.bin, so download it.

I realize that this sounds complicated, and it can be, so if you want to take the express route, simply click on the "Supported" link on the "Table of Hardware" page and you'll find not only the correct file name but also instructions on how to load it. The WRT54GL's supported link has the correct information under "Installation," as does all of the other supported hardware.

 

Once your new firmware image is loaded, you'll probably want to do the initial configuration by unplugging the box from your network and connecting a PC directly to one of the LAN ports. Upon reboot, the box will be configured for the 192.168.1.0/24 network, with its IP address set to 192.168.1.1 and the dhcp server turned on. You wouldn't want this to cause problems on your production network. At this point, you can follow the documentation that is common to all OpenWRT installations and start hacking!

 

Once you have configured the box for your network and have provided it Internet access, log into the system and issue the command "ipkg update" and then "ipkg list" to see the complete list of software available from the official repositories. The list is quite impressive.

A Concrete Example

I hate to sound like some slick infomercial salesman, but if I could offer you a telephone system for your home with features that rival the PBX at your office, how much would you be willing to pay? What if I told you that it had full IVR and voicemail features and could screen calls to keep those pesky ex-es or late-night solicitations out? Now how much would you pay? In June 2006, I wrote an article describing Asterisk, an open-source PBX that has those features and so many more. My original home version of Asterisk was built using a Dell desktop system that I bought during one of their "give-it-away" sales. That system has served me well, but there are three major downsides to it: 1) the system generates a good deal of heat, thus raising my cooling costs in the summer; 2) the system uses about 150 watts of power, so every 10 hours I'm using 1.5 kWh of electricity, at a cost of roughly 10 cents per kWh. Figuring 720 hours in a month, it's costing me around $7.20 to keep that box running ($86.40/year), in addition to whatever it's costing to cool it.; and 3) the thing isn't exactly silent. I get to listen to the fan whenever the house is quiet and I'm in my home office.

 

Here's where OpenWRT came to the rescue. I purchased an Asus WL-500G Premium wireless router for use as my Asterisk box. This is a more powerful box than the WRT54GL (twice as much NVRAM and RAM and a slightly faster processor), and it has two USB ports. Providing storage for the Asterisk software and my voicemail was as easy as plugging a 2G USB memory stick into the back of the box and then configuring it to be mounted into the file system.

 

To connect to the PSTN, I purchased a Linksys SPA3102 VOIP adapter, which has three ports: one that plugs into the PSTN, one into which I plug my analog phone, and a network port. The SPA3102 presents the phone line to Asterisk as an outgoing trunk and the analog phone as an extension.

 

What makes this system more useful to me than a simple answering machine is the access I now have. When a call comes into my home business numbers, three phones ring simultaneously: my analog phone at my home office, a SIP phone I have at my main office, and my cell phone. If I pick up any of these phones, the call will be connected to me. If I don't answer any of them, the call goes to the Asterisk voicemail system, which emails the message to me as an attachment. I now have as much or as little availability as I desire.

 

How much did this all cost? I bought the Asus for around $70. The SPA3102 cost me $85. I "charged up" my Teliax account with $10 (that's 500 minutes). So the total, not including my Polycom SIP phone, is $165. (The Polycom cost me about the same amount). I could just have easily used a softphone running on a PC to save the cost of the Polycom, but I really like those phones, so the cost was worth it to me.

The Savings

Moving to Asterisk saved me quite a bit of money. I used to have three phone lines coming into my home office, with five different numbers. I have reduced that to one physical line and one distinctive ring number, opting instead to take advantage of Teliax, a VOIP provider. I have a pay-as-you-go plan with them, so I don't have the monthly fees I used to have for the other two lines. Changing to VOIP has saved me around $80 per month.

 

Migrating my Asterisk installation from the Dell desktop machine to the embedded system has resulted in additional savings. I calculate that the combined power consumption of the Asus and the SPA3102 is an order of magnitude less than that of the Dell, thus I'm spending roughly $9 annually to run both pieces. My air conditioner is happy that it is no longer competing with the phone system (saving money there), and since the embedded systems have no fans, quiet now reigns supreme at night (saving my sanity).

 

As I look at the little Asus, I marvel at what power can be had for such a minimal cost. I can't argue that you can purchase monitors and other such devices off-the-shelf and ready-to-roll. But I can do the same thing for less than half the cost with just a little elbow grease, thanks to Linux. And I'll have a lot more fun doing it.

BLOG COMMENTS POWERED BY DISQUS