Fun afternoon camsite project using Debian

Taking a break from the money stuff, I though it would be fun to set up a webcam project to serve my webcam over the interwebs. Since I already have Apache serving my proper web pages, and was a bit picky about virtual domains, I decided to use completely different server software and port for the project.

I’m using Debian, although you could use some other Linux distro like Ubuntu. OSX or a BSD will also work. Windows users will bigger challenges ahead of them. You’ll need to install packages streamer and chicken-bin (the Chicken scheme compiler). You will also need to open port 8081 on your modem and forward it to your Linux box.

First, I created some directories to house my site:

mkdir -p camsite/htdocs

In the camsite/htdocs directory, I created a dirt simple index.html page:

<html>
<head> 
<META HTTP-EQUIV="REFRESH" CONTENT="60">
<title>Regret later</title>
</head>

<body>

Latest image<p><img src="outfile.jpeg" />

<p>Regenerated every minute, probably.

</body></html>

You see that it refers to an image “outfile.jpeg” – which is the picture from my webcam. The meta tag I have included means that that the user’s browser will refresh automatically every 60 seconds. They will therefore see regenerated pictures. In the camsite directory, I created an executable script called snap:

#!/usr/bin/env bash
while [ true ] ;
do     
    streamer -c /dev/video0 -b 16 -o htdocs/outfile.jpeg
    sleep 1m
done

As you can see, it’s very very simple. Start the script by typing

snap &

which will run it in the background. It repeats an infinite loop, using the streamer command to take a picture from my webcam (dev/video0) and save it as the outfile.jpeg file. It then goes to sleep for a minute, before the loop resumes. I was trying to figure out a way of putting a timestamp onto the picture, but gave up. I know imagemagick could do it, but I have never used that program before.

Onto the webserver. Your favourite scripting language is no doubt capable of serving web pages. I’ve got a bee in my bonnet about Scheme at the moment, so I decided to give that a whirl. Here’s the script, which I call server.scm:

(use spiffy)

(access-log "access.log")

(parameterize ((server-port 8081)   
   (root-path "/home/mcarter/camsite/htdocs"))
(start-server))

How simple is that? It needs the “spiffy” “egg” to run, which you can install as root by typing

chicken-install spiffy

I’m not aware of any other dependency requirement. Activate the server by typing

csi server.scm

You’re now rocking and rolling.Check that it’s working by pointing your browser to localhost:8081. You should see everything up and running. If that is working, then you want to ensure that WAN can access it. To check, Google for “web proxy”, and choose a proxy site from the results. I you have a domain name, then enter an appropriate value; e.g. http://www.example.com:8081 . Note that some web proxies only attempt to connect to port 80, so you may have to try a couple of proxies to ensure it is working OK.

Half the fun is knowing if anyone is watching, of course, and you can guage that by looking at the access log. In a separate terminal, in the camsite directory, type

tail -f access.log

This will give you a rolling update of the contents of the access log.

I guess the next fun thing to do would be to set up a talk daemon so that people could talk to you if they wanted.

Enjoy!

Advertisements

About mcturra2000

Computer programmer living in Scotland.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s