Raspberry Pi, motion, more Python, and stuff

Things have been a little busy for me lately on many fronts.  There are a variety of projects at work which have my attention and this seems to be a time of year when things pick up before we head into the summer months.

I have however been able to work a bit more with my Raspberry Pi lately and the power of the little guy continues to amaze me.  I decided to give motion a try along with, at least for now, one ip camera.  Before I get into motion on the Pi I must say I wonder how this package escaped my radar for as long as it did.  I have over the years written a few programs which detect motion by comparing images and I have looked at the work of others but somehow I missed motion.  The first thing I noticed about motion once it was up and running was the very nice CPU utilization given the capture/comparison loop.

Motion works out of the box and while that should be the norm, the bottom line is that some software which has not yet approached mainstream can take a bit of configuration work before I for one am happy.  What follows are not necessarily cookbook instructions but they are a good overview of what was needed to get up and running.  If there's time, it is my intent that this will be part of a slightly larger project which will include a nice remote viewer.  Currently I am viewing the files remotely as desired but the interface is lacking.  Seems like I could work the UX term in here somehow. :)

On the Pi, getting motion going is not much beyond the sudo apt-get install motion  command.

There is some configuration for your camera(s) but that is minimal.  In my case I had to add the camera to the motion.conf file (in /etc/motion)


and set the target directory

target_dir /tmp/motion/driveway

There are certainly other parameters which may be of immediate interest, such as the number of images to keep when motion is detected, control ports, etc. but I was able to get up and running with a minimalist approach.

Despite the fact that I have a 16GB memory card in my Pi with most of that available, my next task was to move the images to a server on the web both for easier accessibility and backup purposes.  For the time being, I want to move the images and movie files to separate directories on my server so I wrote two simple rsync commands something like these (server and directory names changed for space and privacy):

rsync --remove-source-files -avt /tmp/motion/driveway/*.jpg me@myserver.com:/dir/img/drvw
rsync --remove-source-files -avt /tmp/motion/driveway/*.swf me@myserver.com:/dir/mov/drvw

These command are in a file named move_motion_images.sh which is called by cron (perhaps a little aggressively every five minutes):

*/5 * * * * root /usr/local/bin/move_motion_images.sh

The line above should be entered into a nicely named file which should be created in /etc/cron.d

I mention Python in the title of the post because I used Python and Bottle to create a very simple REST server for the UI I am planning.  I also wanted to mention PyDev.  Although I have in the past, I can't say I currently use Eclipse on a daily basis.  For the most part I use NetBeans but when it comes to Python, I think the Eclipse/PyDev combination is the better of the two.

It was fast and fun to get this little project up and functional...now I just need to make time to finish the UI.  Even if you don't (yet) have a Pi, if you have a USB or ip camera, motion is worth a look.

Until next time...

Post a Comment

Popular posts from this blog

ClassCastException: JAXB

JDeveloper installation on Mac OS X Mountain Lion

Android and JavaFX