Old Android phone = cheap IP cam

So, I got me a new Samsung phone because my old phone, a HTC Wildfire is rather slow, especially when it comes to websurfing. It also has low crap resolution. I am much happier with the new phone. So, what to do with the old phone? It’s still a small computer with a camera and touchscreen that should be doing something instead of gathering dust in a drawer.

One of the things I thought of was a webcam for my turtle tank. It currently houses two (I think female) red cheeked mud turtles, kinosternon cruentatum. I wanted to observe how often one of turtles gets out of the water to bask and what the general activity in the tank is.

I rooted the phone since I thought it would be handy to have root anyway and installed Cyanogenmod V7, an alternative Android version. This custom ROM does not include the Google Play store to install stuff on Google Play so I had to manually flash it. I am quite unexperienced rooting Android phones and installing custom software but I got it working eventually.

Next I installed IP Webcam, a nice free webcam app. Since it has a webinterface for remote access it is easily accessible with any computer. Being http-based it’s very easy to grab the images over the wireless LAN that the phone is on using a bash script:

#!/bin/sh
wget http://192.168.64.4:8080/shot.jpg
FILEDATE=$(date)
montage -geometry +0+0 -background white -label "$FILEDATE" ~/shot.jpg /var/www/meuk/schildpadcam.jpg
mv ~/shot.jpg /storage/plaatjesenfotoos/schildpadcam_arch/"$(date +%d%m%y%H%M)".jpg

This script uses wget to fetch the most recent video frame (the app is capturing video all the time), uses the imagemagick tool montage to visually timestamp the image and outputs a new picture in a publicly accessible folder on my server. Finally, the most recently downloaded picture is renamed with a timestamp in the filename and moved to a archive directory on the server.

The script is run every minute between 7:00 and 23:59 using the following crontab entry:

*/1 6-23 * * * johan /home/johan/scripts/schildpadcam

This makes sure that most pictures are actually from a lit tank, no need to capture hours of dark frames 🙂

The result is a picture of the inside of the tank that is refreshed every minute:

 To keep the phone running, it is connected to mains with the flimsy USB charger that came with the Samsung.

The archived pictures can be combined into a timelapse, compressing all the pictures of a day into a short movie. I googled around and came up with the following command using the program mencoder:

mencoder -nosound mf:///storage/plaatjesenfotoos/schildpadtime/11082012/*.jpg -mf w=800:h=371:type=jpg:fps=15 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=2160000:mbd=2:keyint=132:v4mv:vqmin=3:lumi_mask=0.07:dark_mask=0.2:mpeg_quant:scplx_mask=0.1:tcplx_mask=0.1:naq -o time_lapse-test.avi

The result is a timelapse that looks like this:

I didn’t get any really interesting pictures as the turtles stayed in the water. But it works as expected, I will continue capturing pictures and hopefully make a more interesting timelapse with some turtles basking on the island.


Comments are closed.