Its been a while since I looked at the RaspberryPi camera. I had intended to turn it into a door bell that emailed me a still of whoever had just rung the door bell – or maybe even a mobile phone app that could display a live stream in near real time… and… I was also going to try using it to take time lapse video but… I just didn’t get round to it.
However, I had a pressing need to resurrect the Pi and its camera recently when our Springer pup damaged her cruciate ligament and had, what in hindsight was, pretty major surgery. I wanted to be able to keep an eye on her remotely and also so my wife could check on her from work.
So with the raspistill command, the screen command and the Apache web server all running on the Pi, I had a quick and dirty web cam.
First off I blew away the old OS on the 16GB SD card and reinstalled Raspbian.
apt-get update; apt-get upgrade
Enabled the camera with:
Installed the apache webserver with:
apt-get install apache2
Installed screen with:
apt-get install screen
Started screen with:
Note: screen allows you to run multiple ssh sessions from a single ‘ssh terminal’, detach from the ‘ssh terminal’ (i.e. disconnect) while all the commands continue to run. You can then reconnect to the screen session at any time. Probably overkill for this, but was handy for testing…
Then in the screen session run:
raspistill -t 0 -vf -hf -tl 10000 -w 800 -h 600 -o /var/www/immi.jpg &
Which does the following:
raspistill is the command to take a still picture with the raspberry pi camera.
-t 0 means don’t wait to take a picture. If I set this to 5 (which I think is the default if you don’t use the -t switch) then the software will wait 5 seconds before taking a picture. Note: the -tl switch (we’ll get to that shortly) doesn’t work if you ommit the -t switch.
-vf means vertical flip – so flip the image vertically. For some reason the images from my Pi cam are back to front so I have to use the -vf command.
-hf means horitonal flip – flip the image horizontally. As the camera is upside down at the top of the cage, this switch flips the image the right way up.
-tl 10000 means operate in time lapse mode and take a picture every n milliseconds. In my case I don’t need rapid updates so I’m taking a picture every 10 seconds (or 10,000 milliseconds). Note: As mentioned above, the -tl switch is ignored if the -t 0 switch is omitted.
-w 800 means set the width of the picture to 800 pixels wide.
-h 600 means set the height of the picture to 600 pixels wide.
-o /var/www/immi.jpg means write the output file to the /var/www directory and call it immi.jpg (Immi is the dogs name).
The ‘&’ allows the command to run in the background. If the ssh session that ran the command exits, then the command also exits, hence the use of the screen command.
Finally I added a really really basic web page into /var/www to load the image and refresh it every 10 seconds.
<head><meta http-equiv="refresh" content="10"; URL=http://immycam.sub-design.co.uk"></head>
<body><p>Immi cam. Poorly Immi :(</p>
The ‘meta http-equiv=”refresh” content=”10″; URL=http://immycam.sub-design.co.uk”> line does the job of reloading the page every 10 seconds.
It isn’t pretty, but it does the job and only took an hour to setup.
And now I know how to do time lapse with the Pi cam, I don’t have an excuse for doing that next!