Monday, December 29, 2014

Simple Linux webcam script on Raspbian

Here is how to get a webcam up and running easily on Raspbian...  First of all, install fswebcam, which allows you to take single snapshots from a USB-connected (or other) camera.  (My webcam is USB-connected.)

$ sudo apt-get install fswebcam

Next, download the Dropbox uploader script and set it up to link up to a folder in your Dropbox account.  Then, create a script called snapanddrop.sh somewhere useful. Here's the entire contents (three lines):

#!/bin/sh
fswebcam -r 640x480 --jpeg 85 -D 1 -timestamp test.jpg

./dropbox_uploader.sh upload test.jpg `date +"%Y%m%dT%H%M%S"`.jpg

This script takes a single snapshot, timestamps it, and then uploads it to your Dropbox area.  Incidentally, you can give this Dropbox folder as a link that anyone can use to see its contents.  Don't forget to make snapanddrop.sh executable:

$ chmod +x snapanddrop.sh

If you want a snapshot any given time, just call snapanddrop.sh from the command line.  Finally, I wanted to take a snapshot every ten minutes.  This is easily done by adding an entry to the crontab...  Simply call

$ crontab -e

and then add the line

*/10 * * * * /home/pi/snapanddrop.sh >/dev/null 2>&1

to the end (of course you should change the path to the directory containing snapanddrop.sh).

No comments:

Post a Comment