Very Simple Pi Webcam

in #programming8 years ago

view.png

If you already have a website and just want to add a webcam view to it, this is the most straightforward way I can think of.

The advantage, of course, is you don't need to allow visitors into your home network, and you can move the webcam wherever there is wifi or a network port.

There are two pieces, first is capture, second is display:

Capture the Stills

#!/bin/bash

while [ 1 ];
do
        raspistill -o cam.jpg
        scp cam.jpg [email protected]:apache/html/cam
        sleep 5s
done

This uses the Pi built in camera tool to take a still every 5 seconds and copies it up the webserver.

Display the pics

Gist here with example Python code

Set up a simple HTML or Python page on your webserver, but add this little piece of JS:

<script>
window.setInterval(function(){
        var newImage = new Image();
        newImage.src = "cam.jpg?"+new Date().getTime();
        jQuery("#cam").attr("src",newImage.src);

},1000);
</script>

This will repeatedly reload and replace the image with ID of cam :)

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.086
BTC 60398.95
ETH 1628.09
USDT 1.00
SBD 0.41