Slugs have Eyes Too
Slugs have Eyes Too
*** Update following the demise of the SLUT the webcam is no longer running ***
I had an old Logitech Quickcam 4000 lying around so I decided to see if it could be made to work on a Slug (SLUT actually). I used this excellent resource as a starting point. It turns out it is one of the easiest webcams to support, using the Philips pwc driver, If you are not sure which USB webcam you have, try plugging it in and typing
lsusb
This site is a great resource for identifying USB drivers. There are accounts of some unseemly bickering in the Debian ranks about whether or not this driver should be included in the Debian distribution, but thankfully it seems to have been sorted, at least in the ARM version. You can check that the driver is not already loaded with
lsmod
and if not, see if it can be loaded
modprobe pwc
lsmod
I was pleasantly surprised to find that the module was available and loaded fine. To have it load automatically in future on reboot add the following to /etc/modules
# for webcam
pwc
with your favourite editor. After this the video device should become available, and can be identified with this command, mine turned out to be /dev/video0, which is normal:
ls /dev/video*
You can check it is working OK with the simple framegrabber application Streamer:
apt-get install streamer
streamer -c /dev/video0 -b 16 -o webcamfile.jpeg
You will need to copy webcamfile.jpeg to your client to view it, it should be a single frame image from your webcam, so remember to smile ;-)
The next step was to find a proper webcam application. The first I came across was the imaginatively named ‘webcam’. I installed it and after a fair bit of digging in the man files and surfing finally got it to work. Quirkily it uses a config file called /root/.webcamrc . The default supplied is mostly rubbish for our purposes. Also I suggest you supply the full filename when editing it in your fave editor so you don’t end up editing a file in the wrong place which will be ignored. I have copied my file here which should be easy enough to follow along with the man page:
apt-get install webcam
nano /root/.webcamrc
[grab]
device = /dev/video0
text = "NSLU2 webcam %Y-%m-%d %H:%M:%S (BST)"
# infofile =
fg_red = 255
fg_green = 255
fg_blue = 255
width = 640
height = 480
# delay = number of seconds between snapshots
delay = 30
wait = 1
input = usb
norm = webcam
rotate = 0
top = 0
left = 0
bottom = -1
right = -1
quality = 75
trigger = 0
once = 0
# archive =
[ftp]
host = 127.0.0.1
user = root
pass = xxxx
dir = /var/mywebroot/webcam
file = webcam.jpeg
tmp = uploading.jpeg
passive = 1
debug = 0
auto = 0
# local = 1 means just use the local directory specified above, do not use ftp or ssh
local = 1
ssh = 0
You can then start webcam
webcam
and test that it is working by pointing your browser at <your web root>/webcam/webcam.jpeg in the above example. I found it ran well, using negligible resources, and it was easy to knock up some html to pretty it up a bit and auto refresh (hint: if you wish you can check out my webcam page, view source in your browser, and use this as a starting point). If you want it to run automatically you could set up a crontab:
crontab -e
@reboot /usr/bin/webcam
A (much) more sophisticated webcam package which includes motion detection is the equally imaginatively called ‘motion’. This is so complex that it has its own wiki (always a bad sign!) but it wasn’t too hard to get running:
apt-get install motion
and a more conventionally named /etc/motion/motion.conf
# Minimal motion example config file provided by the
# Debian motion package - for basic webcam operation.
#
# You most certainly want to investigate
# /usr/share/doc/motion/examples/motion-dist.conf.gz
# for further configuration options. Also, refer to the
# motion man page and /usr/share/doc/motion/motion_guide.html
# for detailed information on configuration options.
daemon on
quiet on
# You may very well need to change this (check with 'dmesg'
# after plugging in your webcam).
videodevice /dev/video0
# Image size in pixels (valid range is camera dependent).
width 320
height 240
#
framerate 2
quality 85
auto_brightness off
#
# Make automated snapshot every N seconds (default: 0 = disabled)
snapshot_interval 60
#
# General threshold level and noise threshold
# level (for distinguishing between noise and motion).
threshold 4500
noise_level 64
#
# Initial brightness, contrast, hue (NTSC), and saturation.
# 0 = disabled (valid range 0-255).
brightness 0
contrast 0
saturation 0
hue 0
#
# for low-powered cpus
low_cpu 1
#
# Target base directory for pictures and films (you may need
# to change this (or change its permissions) depending on
# which system user runs motion).
target_dir /var/mywwwroot/motion/snapshots
#
# filenames recycle after 1 month
jpeg_filename %d%H%M%S-%q
#
# snapshot_filename %v-%Y%m%d%H%M%S-snapshot
snapshot_filename last-snapshot
#
# Define a port number (e.g. 8000) to enable the mini-http server.
# 0 = disabled.
webcam_port 0
#
# Set to 'off' to allow anybody (not just localhost) to view the
# webcam via the mini-http server (http://hostname:port).
webcam_localhost off
#
webcam_quality 50
webcam_maxrate 1
Start motion from your shell and because of the daemon on setting it will run as a daemon and begin both taking 60 second snapshots (overwriting the same jpeg file in this case), and creating one jpeg per frame while detecting motion. If you like you can stream near-real-time images via its built in web server to a chosen port but be prepared for 97% CPU usage while doing it! In fact performance generally seems to be on the margins for a Slug. I disabled the mini-server, set all the frame rates to their minimum, added the low-cpu statement, and reduced the video size to 320x240. Collectively these took CPU and Memory usage down from both being at about 20% to both being at about 10%, which I guess is just about OK for most users. Beware that by default the motion detection creates zillions of jpeg files, one per frame while something is moving in the webcam’s field of view. I changed it to loop around the day of the month, by changing the filename, which I estimate would create at worst a few gigabytes of data. If you are shorter of space you could loop around say a days or even an hours worth of files, although it could be frustrating to arrive home only to find the only image you had of a burglar was a shot of his arse disappearing thru the window...
*** Update following the demise of the SLUT the webcam is no longer running ***
Saturday, 7 April 2007