WARNING! THIS POST FULL OF GEEK SPEAK!

I write on all sorts of subjects, and though I do try to stay in the realm of real estate, as you can see by my last post, I write about other things as well. Last time I wrote about divorce law. Not that it had anything to do with real estate, but one of my marketing efforts landed me some new friends that worked in this field, and I became interested… so I wrote about it.

schedule_20161016-152500My family has a property in a remote area, and for many years we have struggled with internet access. I remember the days of 9600-14400 baud dialup modems, and then we managed to get satellite service, a dramatic improvement but still…

Things started to turn around about 5-6 years ago when the local telephone company offered DSL. We were the very first DSL installation in the area, and we were REALLY happy to have 3 meg down and 400k up. Well, mostly. It was pretty unreliable. It was down for weeks at a time, or so unreliable nothing would work. It was barely possible to watch netflix.

Later, they did upgrade to 5 mb down, but it was still very unreliable, despite much effort by their tech folks to make it better. Portions of the phone line run through a lake, and we are at the far, far end of DSL capability. So it wasn”t great, but better than anything else we had tried.

A few years ago I saw that an area development company was pulling fiber optic cable down the highway, about a quarter mile away. “Wow, it would be so nice to have fiber optic service to our place…” I thought.

After a couple years of schmoozing, we finally inked an agreement a few months ago, and now we have (gasp!) gigabit fiber to our place. Well, the fiber is gigabit, we pay for a much smaller service, because now it is a leased line, and if you ever priced one, well, they are expensive. The nice part is that the bandwidth is not shared, it is ALL yours, with a leased line. Oh, and you have to additionally pay a service provider to give you internet service.

When we got everything working last month, I was eager to add an HD webcam to the mix. My other cameras were installed more than 8 years ago, and they are still working! These were the old Trendnet TV-IP100 cameras with a CMOS sensor. You can check out the web page at http://www.patrickharvey.net/regis

These cameras, the old Trendnet ones, can be configured to upload an image every X seconds, and they will dutifully upload it via ftp to a server of your choice; they also can be configured to upload only a certain number of images, and then roll over to the next image. They create PIC001.jpg, PIC002.jpg, etc. to whatever number you set, then roll over.

After implementing these cameras, I wanted to see a time lapse – so my friend Matt wrote a little animator script that steps through the images from oldest to newest, and shows a little movie. Unlike many webcam web pages that periodically create a time lapse for you, this creates onscreen-shot-2016-10-17-at-3-12-21-pme with the very latest images. The Trendnet cameras are configured to store I think 60 images, or about 5 hours of animation. If you want a copy of the Trendnet animator, let me know, but the Foscam one is more what you want. The directory structure from the Trendnet cameras looks like this:

The Foscam web cams can also be configured to upload images, but they don”t roll over or limit the number of uploaded images or anything like that, and the names don”t repeat, the image name is a timestamp. So it takes a little unix prowess to get a time lapse to work and behave well.

First, you configure the camera to upload an image from time to time. Mine are set for once every 5 minutes. The files are uploaded into a directory, and end up looking like the second directory image here.

r\nscreen-shot-2016-10-17-at-3-10-17-pmNow, that isn”t the most exciting thing, but you get the idea. These are the files we need to deal with. With the first set, the file names follow a set of repeating rules, so it is pretty easy to write a script to display each one in sequence. With the second set, it is slightly more interesting.

First, we need to limit the number of uploaded files. I wrote a shell script that scans the directory and deletes anything older than a day. So it keeps 24 hours worth of files, and it is run by cron every hour. I also have the cameras set by schedule to not upload anything between about 7PM and 6AM since it is dark. The script to delete older files is very simple:

 find . -iname ”*.jpg” -mtime +0 -exec rm {} \\;

You will want to replace the “.” with your fully qualified directory name since it will be run from cron. You can also control the age of files you want to delete with the argument after mtime.  Your crontab entry will be something like 0 * * * * script.sh, which would run your script on the hour each hour.

The next thing we want to do, is to stash the latest uploaded file into a specific filename. Most webcam services like this – it isn”t needed if you aren”t going to submit your camera to a webcam service, but it is easy to do, and again, I let cron run it every hour so the oldest photo is an hour old. The script for this one is a little more complex, note the direction of the quotes.

cp `ls -t -1 ./S*.jpg | sed ”1q”` new.jpg

So this says, first do an ”ls” command looking for files that start with S and end with .jpg (the Foscams upload a file like Schedule_xxxxxxx-xxxxxx.jpg so I use the S, so the script doesn”t match ”new.jpg” since it has no ”S” in it); The ls command sorts them by time and on a one per line basis. This is piped into sed which is told to return only the 1st line and exit. This (ls piped into sed) is within back quotes which tells the shell to execute the command inside the quotes and insert the output into the command line before doing anything else. The rest is just a copy command. So essentially this line gets the latest image uploaded by the camera and copies it into ”new.jpg”. If you have cron run this periodically, new.jpg will always have a most recent webcam picture in it.

nAgain, since cron is running this script you will want to fully qualify the directory/file names.

The other thing that I do with cron is to run another script, just like this one, just after noon every day and stash the latest file into a ”daily” directory so that I can do a monthly or longer term time lapse of the same image at the same time each day to see how it changes over the year. I just set that up, so I only have a couple days worth of data.

If you want to see the nice daily HD animation from the Foscam, click this image:

schedule_20161016-152500

Following is a copy of the animator source, if you want to try it. It is in zip format. It was a bit long and esoteric to insert into the post.

images-php

Enjoy animating your Foscams!

–PLH