As you might guess from past blog posts, I was trying (several) Microsoft Live Vision USB webcams, with the aim of using them via the RPi and a long ethernet cable to monitor my bird nesting box cameras. My plan (outlined back on this post) is to use power-over-ethernet (POE) to supply 5V to the Raspberry Pi, which will be down the garden within USB range of the birdbox or birdboxes. But first, to get this working indoors - which meant initially a long wait before my RPi was delivered.
Meanwhile, other people were also experimenting with using the RPi as an IP-webcam, like Jeremy who tried both ffserver on his RPi and then later switched to using Motion on a battery powered RPi webcam with wifi and more. Nice blog!
Motion under Raspbian
I decided to try the recently released Raspbian-based SD card image, specifically the 2012-07-15-wheezy-raspbian.zip release. During the first boot I used the menu to expand the file system to take the whole SD card, enabled SSH access, and set my keyboard and locale, and opted not to boot to the graphical desktop. I then ran an update, and installed Motion, the Apache webserver, Emacs, etc.
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install motion
$ sudo apt-get install apache2
$ sudo apt-get install emacs
Initial experiments with an un-powered and a powered USB hub were not fruitful - the second webcam wouldn't register - in fact in some configurations even low power devices like my mouse or keyboard wouldn't work. So rather than trying this with a USB keyboard and mouse, I switched to SSH access and used the only two USB ports for two webcams - which worked.
$ ls /dev/vid*
I've already been running motion for a while now on an old laptop, so the configuration wasn't too hard - I knew that on my laptop getting several USB cameras running at once meant sticking with the default low resolution of 320x240 pixels. I went with two camera configuration files as ~/webcam/cam1.conf which is just:
And likewise for the second camera, configuration file ~/webcam/cam2.conf is just:
These are very short because everything else is in /etc/motion/motion.conf, the main configuration file, most of which remains with the default values. The main change is two thread settings pointing at the above per-camera settings:
The only other configuration change so far is for making this act like an IP-webcam was to change the default (secure) setting restricting this to the same machine (local host). Note you must also ensure the two camera streams are on different ports (I went for the motion default of 8081, and 8082 for the second camera).
I then setup a minimal webpage by creating the file /var/www/webcam.html showing the two images side by side (which would be served by Apache). Initially I've just hard coded the RPi's hostname to access the two webcams, but I think a little Apache magic is a better solution considering my IP address is allocated by DHCP and will change, but this works for now.
Update: As requested in the comments, here's the simple HTML for the page I access as http://raspberrypi/webcam.html from within my home network (this should be edited if you change the default hostname of raspberrypi):
$ more /var/www/webcam.html
<title>Raspberry Pi Webcameras</title>
<h1>Raspberry Pi Webcameras</h1>
<img src="http://raspberrypi:8081/" alt="Camera 1" ></a>
<img src="http://raspberrypi:8082/" alt="Camera 2" ></a>
Update: If you want motion to auto-start when the computer is rebooted, you need to edit the file /etc/default/motion to say start_motion_daemon=yes and this will happen automatically via the /etc/init.d/motion startup script. I'm using this now that I have installed a Raspberry Pi in my garden. Note I added $all to the Required-Start list to hopefully ensure that the USB system, ethernet, and date-time (via the network) are live before starting Motion.
It would be nice if DropBox could run on the Raspberry Pi - but right now it doesn't. You can go here to vote for DropBox to support Linux on the ARM processor. That rules out one way to automatically collect movement triggered images from the RPi - but there are several other options here, perhaps rsync to a separate image server?
Update - More USB devices?
As I noted in the introduction, I could only get two USB webcams to work when directly connected - and thus had to log into the RPi by SSH to control it. Even trying two cameras and a keyboard via a powered or unpowered hub proved problematic.
Using a powered hub is the recommended solution, so perhaps my hub just wasn't up to the job? However, I've been reading about an alternative hack to bypass the RPi's F1 and F2 polyfuses as described on The IO Blog, Himesh's blog, and elsewhere including this forum thread USB Port Current Boost. You would of course still need to use a sufficiently strong power supply.