Making a Webcam Server
You want to set up a Raspberry Pi as a webcam server.
Download the motion software. This will allow you to set up a Raspberry Pi with a USB webcam connected to it so you can connect to a web page and view the webcam.
To install the software, enter the following command in a Terminal window:
$ sudo apt-get install motion |
Plug in your USB webcam and type lsusb to see if the webcam is connected:
$ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 3538:0059 Power Quotient International Co., Ltd Bus 001 Device 006: ID eb1a:299f eMPIA Technology, Inc. |
If it isn’t obvious, try disconnecting it, run the command again, and see if one of the entries vanishes from the list. In this case, the final entry in the list is for the webcam.
There are now a few configuration changes that you need to make. First, edit the file /etc/motion/motion.conf using the command:
$ sudo nano /etc/motion/motion.conf |
This is quite a big configuration file. Right near the top of the file, you will find the line daemon off; change this to be daemon on.
The other change is much further down the file. You need to change webcam_localhost = on to webcam_localhost = off.
There is one other file that you need to change. Enter the command:
$ sudo nano /etc/default/motion |
Change start_motion_daemon=no to start_motion_daemon=yes.
To get the web service running, issue the command:
$ sudo service motion start |
You should now be able to open your web browser and view the webcam. To do this, you will need to know the IP address of your Raspberry Pi (Recipe 2.2).
From another computer on the same network, open a browser and go to the URL http://192.168.1.16:8081/. You will need to change the URL to match the IP address of your Raspberry Pi, but you need to keep the :8081 port number on the end of the URL.
If all goes well, you should see something like Figure 4-7.
Discussion
The motion software is actually really powerful; there are many other settings you can tweak to change how your webcam works.
By default, the webcam will be viewable only from within your network. If you want your webcam to be visible to the whole Internet, you need to set up port forwarding on your home hub. This will require you to log in to the admin console for the hub, look for the port forwarding option, and enable it for port 8081 for the IP address of the Raspberry Pi.
You will then be able to view the webcam using the external IP address allocated by your ISP. This is usually shown on the from page of your admin console. But beware: unless you pay your ISP for a static IP address, this IP address is likely to change every time you restart your home hub modem.
See Also
There is thorough documentation on the motion website.
The Raspberry Pi has a plug-in camera module (Figure 1-18). At the time of writing, this is not compatible with motion, but it may be by the time you are reading this.
See also Recipe 3.16 for information on using apt-get.