How to make an Ubuntu Webcam
Ok – so it’s a bank holiday and I thought – why not build myself a webcam which would automatically publish up to my website… Here’s the method’s and gotcha’s:
1) Install fswebcam and get it running (man fswebcam) -
my working command line was: fswebcam -q -r 640×480 –no-banner test.jpg
2) Work out how to FTP onto your website – and put the both into a bash script:
#!/bin/bash
# script to capture from webcam and copy up to the web
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin
fswebcam -q -r 640×480 –no-banner test.jpg
ftp -inv mywebsite<<ENDFTP
user myftpuser myftpassword
bin
put test.jpg
bye
ENDFTP
Don’t forget to make the bash script executable: chmod a x filename…
Run it and check that it works… (FTP onto your site and have a look)..
So now onto the Html / Javascript:
Put this in the head:
<script language=”JavaScript” type=”text/javascript”>
function Clock()
{
var now = new Date();
this.document.getElementById(“testimg”).src=”test.jpg?” + now.getTime();
}
</script>
Use this for the onload of the body:
<body onload=”setInterval(‘Clock()’,60000)”>
and here’s the target IMG:
<img src=”test.jpg” alt=”test image” id=”testimg”/>
Ok – so finally (and probably the worst bit) – lets set up a chrontab job to automate the client side:
In a konsole window type:
export EDITOR=”kate – or your favourite editor”
chrontab -e
Now point your job at your script file:
PATH=/usr/sbin:/usr/bin:/sbin:/bin
*/1 * * * * /home/paul/Documents/capandftp.sh >> /home/paul/Documents/cron.log 2>&1
****Don’t forget to put 4 carriage returns in otherwise it seems to just not work****
Note the chron job is logging to cron.log!!!
Hey and that’s it – if you need more help getting this working, feel free to msg me…
- No Comments »
- Posted in Linux, Webcam
