Open Source

Play super sleuth/geek with this inexpensive server-room security camera system

Server-room equipment walking off? Don't bother calling Scotland Yard; set up this quick and inexpensive Web cam/Linux server-room monitoring system and solve the case yourself.


I recently got my hands on a Logitech QuickCam Express (approximately $49.99 USD) and knew that I could employ its services in more ways than as just the typical Web cam. My goal was to get the cam working with Linux and to use that combination to create a security cam/security archive with low overhead and low cost. With the help of an open source driver, an open source application, Gqcam, and a handy bash script of my own creation, I got this little security system up and running and keeping an eye on my server room.

I’ll show you how to get the Logitech QuickCam Express working with Linux and then how to make it interact with a simple shell script to archive the images taken by the cam.

What you need and where to get it
First, you need the Web cam itself (it’s even sold at your local Target these days). You also need:
  • ·        One computer running one of the newer distributions of Linux (my setup is handled with Red Hat 7.2).
  • ·        One copy of Gqcam.
  • ·        The QuickCam Express driver files—I'll talk about how these are installed in a moment. For now, just download all the files from the driver site. Put these files into a new directory named /usr/local/quickcam/.
  • ·        This script for manipulating the files created by Gqcam.
  • ·        A little time.

Before you move on to the first step, plug the QuickCam into the USB port on your server. Now you're ready to rock.

First, the driver
First, compile the driver and load it into the kernel. You’ll need to su to root and then mv (move) to the /usr/local/quickcam directory that you created before you downloaded the driver files. Once you’re inside that directory, issue the command make, which will compile the mod_quickcam.o file. You’ll insert that into the kernel with the insmod command.

Before you insmod the mod_quickcam.o file, make sure that the videodev.o module is in the current kernel. To check this, run the command /sbin/lsmod | less and see if you find the videodev module listed. If not, first locate the module with locate videodev.o (on my system, it’s in /lib/modules/2.4.7-10/kernel/drivers/media/video/). After you’ve located the module, issue this command and the correct module will be loaded.

Now, from within the directory where you compiled the QuickCam driver, run this command and the QuickCam driver will officially be loaded into the kernel:
/sbin/insmod mod_quickcam.o

Installing Gqcam
You’re ready to install the front-end application that will allow you to take snapshots with your QuickCam. You’ll need to mv the gqcam g'zipped tarball file (as of this writing, it was gqcam-0.8.tar.gz) into /usr/local/ and run this command, which will unpack the files, creating a new directory (in this case, gqcam-0.8):
tar xvzf gqcam-*

Now you need to move into the newly created directory (in this case, cd gqcam-0.8) and issue the command make. After a few seconds (or minutes, depending on the speed of your machine), you’ll have a new gqcam binary file ready to run.

Glitches
After you install the Gqcam application, you’ll have to deal with one rather strange issue. The Gqcam application expects two files in the /dev directory: bttv and video. That is all fine and good except there’s already a directory in /dev called video. To get around this, run the following commands and Gqcam will run properly:
mv /dev/video /dev/video_BAK
cd /dev
ln -s video0 bttv
ln -s video0 video
chmod 666 bttv
chmod 666 video


Final setup
You're very close. Before you run Gqcam (although it’s certainly ready to run now) as root, create a new directory in /var/www/html/ called webcam. Change the ownership of that directory to a standard user on the system so root doesn’t have to run Gqcam for this system.

The next step is to take the script shown above, name it web_cam, copy it into /usr/bin, and then give it executable permission with the command chmod u+x /usr/bin/web_cam. You’ll also change USER, in the script, to the actual username that will be running the Gqcam application.

This script is going to:
  • ·        Count the number of files in /var/www/html/webcam and add one to that number.
  • ·        Rename the file /var/www/html/webcam/web_cam.jpg, which is automatically created after Gqcam snaps the picture, by adding the totaled number (from the above step) to the end of the filename (before the .jpg extension).
  • ·        Move the new /home/USER/web_cam.jpg file into the /var/www/html/webcam directory (where USER is the actual username).

It's that simple.

Running Gqcam
Now you're ready to fire up Gqcam and start snapping images. From a terminal window, as the user you used in the script file, run the command gqview; the application will start up and you’ll immediately see the view from the camera.

To get the application to start taking snapshots at specified intervals, click the Camera drop-down menu and select Set Timer. From here, select how often you want the image to be snapped (you can choose from 0 seconds to 99 hours) and specify the command web_cam to run after each snapshot is taken.

You also must specify the Image Information. Tell Gqcam to save the image as /home/USER/web_cam.jpg (where USER is the actual username running the application). You can opt to bump up the quality by selecting Optimize and then clicking OK. After you click OK in the Image Information screen, you’ll be back at the Set Timer screen, where you’ll click OK.

At this point, Gqcam is snapping pictures at the interval you selected, dumping those images into the user’s home directory and then running the script from earlier. If you want to make sure the setup is running, open either Konqueror or Gqview, navigate to /var/www/html/webcam/, and see which images are there. If you see something like: web_cam.jpg, web_cam1.jpg, web_cam2.jpg, etc., you know it's working perfectly.

What to do with it?
The main reason I created this was to have an inexpensive and simple means to watch over my server room. What you can do is set this up in your server room, point it to whatever (or wherever) you want to monitor, and fire it up. As the setup does its job, it will keep an archive of images taken throughout the day (or night) that you can scan through to see what kind of activity occurs while you’re gone.

Another great thing you can do with this little setup is to secure shell into the server housing the system, run the gqcam command (so long as it's not already running), and watch what’s going on, remotely and in living/moving color. Remember, of course, that this is going to be a rather slow method of monitoring a location because of streaming video over possibly constrained pipes (and a server that may not be set up for such needs).

Conclusion
This system can be used with any number of other Web cameras (the driver installation will vary depending upon the unit selected), but I felt the Logitech was best suited because of reliability, price, and availability of specific drivers for the Linux OS.

I hope this little setup has inspired you to create your own use for such a system. With the flexibility of the Linux operating system and the low overhead, limit yourself only to the scope of your imagination in what you can do with these tools.

Tell us your uses
Have you come up with an ingenious way to use such tools? Send a note to Jack Wallen, Jr., and you might find your ideas published in TechProGuild.

 

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.

Editor's Picks