This post is the second post in a series of posts about making a webcam server using a inexpensive wireless router, some open source software, and a cheap webcam. Read the first post for a little more background.
Why a Webcam
I wanted to be able to watch my 2-year-old's room to see if she was sleeping or not without risking waking her up by entering the room. I had a wireless camera a bought for ~$99 about a year ago and it's crap. It interferes with my WiFi. My WiFi interferes with it. It's not very good quality. And it can only be viewed in one place: the TV the wireless reciever is attached to.
So, my goals are:
- Cheap: Under $100 for a complete camera setup, including means of transmitting to my iPhone or computer. If I add multiple cameras, then the per camera cost should either get cheaper or stay the same.
- Compatible: I want to be able to view this on my iPhone or MacBook Pro. I want my wife to be able to do the same, ideally at the same time in another part of the house (or world.)
- Expandability: I would like to be able to add cameras to the system, and easily switch between them.
- Unobtrusive: I don't want a bulky setup hanging out in the corner of my daughter's bedroom. I'd like something that I can hide most of in a drawer and just have a tiny camera hanging out above a window sill or in the corner. The less messy cords and power plugs the better. It's also important that it be safe for a curious 2-year-old to be around, so the positioning and security of the power plugs and other cords must be carefully considered.
Some of those goals are a bit lofty, I know. Streaming to the iPhone requires H.264 encoding, and that might be a bit much to ask of a 200MHz router, especially if I add multiple cameras to one unit and have multiple people viewing those streams. If that proves to be impossible, I'll try to use my underused G5 as a streaming server, converting a simpler format (MJPEG, most likely, since that's what many webcams send natively) to H.264 with the help of a much more powerful processor.
Buying stuff
Router
As I've mentioned, I'm cheap. I like buying things on sale or sometimes used. So, when I read about the ASUS WL-520GU over on the mightyOhm blog, I immediately started looking for deals. When I bought mine, it was $40 on NewEgg.com. Even when there's no specific coupon or rebate, it's still only $50.
If you decide you would like to use a different router, then a lot of these instructions might still apply so long as you're going to use OpenWRT. You can see if you're device is supported by browsing the Table Of Hardware.
Note: As I write this the OpenWRT team is busy moving and updating the wiki, so that link might go stale. Even the "Supported Devices" link on their home page is broken currently, so you might have to dig some to get to it. In any case, you should search the forums to see if anyone else has asked about the hardware you want to use. Keep in mind that sometimes the manufacturer will change the internals of a device without changing it's name or UPC code, so you have to sometimes buy the device and look at the back and see if it says v1, v2, etc. So far, ASUS seems to fairly clearly state when they make changes, but I can't say how much you can trust that.
Webcam
The web cam isn't as easy of a choice. There are many, many different webcams, with ranging features and quality levels, not to mention prices. Many of them would put us over the $100 mark by themselves. Assuming the router costs about $45, and we'll need a USB hub and USB thumb drive, we've got about $30-$35 dollars to spend on a webcam.
I got lucky and found a Logitech QuickCam Communicate STX at a local Target for $30, and that actually included another (normally less expensive) webcam with it. I haven't found that deal since.
Things you should look for when choosing a web cam:
- Make sure it's compatible with the gspca/V4L2 drives used by OpenWRT. I had a hard time finding a list I could link to, but I did find this one. That's close, but you really want to check the list from your OpenWRT before you build, because there might be some more added. When I get to the installing of OpenWRT part, I'll explain more. Keep in mind that manufacturers change the internals of a product without changing it's name, sometimes making it incompatible with Linux. The only way to know for sure is to plug it into your computer and check the vendor and product IDs. I'm using a Mac, so I open the System Profiler with the device plugged in and grab it there. On Linux you can use lsusb. I don't have a clue about Windows, but I'm sure it's possible. (Feel free to share how in the comments, in case others want to know.)
- You probably want it to be small, for unobtrusive use.
- You might want one with a built-in microphone. The STX I'm using has one, but I still haven't gotten it working. I'll try again later and report.
Other USB Stuff
All that's left is a USB hub and a USB flash drive. You probably already have some of these laying around. Most of them will work, so it's mostly up to price and aesthetics.
For the USB hub, I just use a tiny little mobile USB hub that I had. I have no idea what it cost at the time, but I doubt I paid the $20 it goes for on Amazon.
For a flash drive, I'm actually using a tiny little flash card reader (like this one) and a 1GB microSD card. The router sees it like it's any other flash drive. It doesn't have to be big, unless you plan on keeping recordings around on the drive instead of sending them to another computer or just streaming them into the ether. That old 128MB or 512MB flash drive you hardly use anymore might do the trick quite nicely.
Void your warranty
Warning: What we are about to do to your poor ASUS WL-520GU will void it's warranty. You might also turn it into a bunch of spare parts. Proceed with caution, and use common sense. Please.
Adding a serial port to the router
It's really hard to top the instruction over on the mightyOhm blog. Actually, I wouldn't want to try, since that's where I got my information. (Thanks, Jeff!)
However, since I did a few things differently, I will give a very rough outline here:
- Open your router, voiding your warranty. In order to do this you have to pop off the rubber feet from the bottom of the router and remove the screws hidden underneath. I cut the feet so that I could stick them back on and leave the screws accessible. The top will not pop off. It has a little bit of a latch, so you can leave the screws out and not worry too much about it falling apart when you pick it up.
- Remove the solder from the header that is just below the ASUS logo (when the logo is upright) with a soldering iroon and a solder sucker. This part is not easy, since the "bottom" pin is on a ground plane, and will require a lot of heat. I have a 15W iron, and so I used a BernzOMatic butane-powered mini heat torch to heat the other side at the same time. I have scorched and destroyed several PCBs with this torch, so you have to be careful not to get too hot too fast. Once the solder melts, use the solder sucker to pull the solder out quickly before it cools and solidifies.
- Here's where I varied from the mightyOhm instructions. He said to use a 4-pin straight male header, and I instead used a 4-pin right-angle male header.
Then, instead of soldering up a piece of perfboard and some female headers, I just used the female-to-female jumpers from SparkFun and a strip of straight headers.
Using the schematic provided by mightyOhm, I wired header to the FTDI cable by placing the small strip of straight headers in the FTDI cable and then connecting the cables in this order, from top to bottom as show in the photo above:
I was able to run the wires around the edge of the board and out thru the mounting hole on the back of the router. That way I can close the case and still have access to the serial port on the router.1) 3.3V → (unconnected) 2) RX → Orange 3) TX → Yellow 4) GND → Black
Testing the serial port.
I'm on a Mac, and so my instructions will be slanted that way. Most of this info should transfer to Linux/*BSD quite easily. I'm sure it won't be hard to find information online on how to do this on Windows.
Connect the FTDI cable to your computer's USB port. (You might need to install drivers first.) Then open a terminal emulator and connect to the router. The settings: 115200 baud, 8N1. Over on mightyOhm, Jeff says he likes Zterm for the Mac and Hyperterminal on the PC. I don't know about Hyperterminal, but I've never been much of a fan of Zterm.
Instead, I use screen. It's built into MacOS X, and works like a charm, mostly because you never leave Terminal.app. The only part I don't like is the hand-cramp required to leave the program. To connect (assuming you have only one FTDI cable attached at a time):
$ screen /dev/cu.usbserial-* 115200
That will connect you to your router. You can type in commands to the normal UNIX shell. You may have to hit return at first to bring up the prompt. As an exercise, you can restart your printer while connected to see the startup logging.
When you're ready to disconnect the cable (or just leave screen) type: Ctrl-A, then "k" for kill, then "y" when it's asks "are you sure." Please refer to the mightyOhm post to see what a typical startup of the WL-520GU looks like.
In the next episode...
In the next post, I'll show you how to custom compile an OpenWRT and load in onto your router.
