It all started with a snow problem.
I wanted to check remotely how much snow had fallen on my home in the mountains (I live in the French Alps), specially whether the snow removal machine had cleared the way.
So I started to tinker with the camera module of the Raspberry Pi (a low cost, Linux based, single board computer).
I quickly landed on Motion , a software package which provides real time camera feed into any web browser. So with running Motion on a Raspberry PI, I can remotely look at my garden from my smartphone (the feed is a few fps, with a one or two seconds delay, but good enough for that purpose).
Motion also provides some interesting additional features:
- motion detection (yes, there is logic in the name) with picture and video creation, and alarm generations.
- timelapse: taking pictures at regular intervals, and assembling them into a video clip.
Motion is very customizable and you will find plenty of tutorials on the Internet. In this short article, I will focus on what I built around it to make it more user-friendly:
- manage multiple cameras
- provide a central GUI (graphical user interface)
- integrate with Monit, health check of Linux systems
- integrate with Pushover , for real time notifications
- integrate with Blynk, for status monitoring
- integrate with a very lightweight photo gallery to record/view detection pictures
The entire software is available on GitHub (python and bash). I typically use a small Raspberry PI Zero as a camera node
The GUI was developed in Python using remi and is accessible from any web browser. There can be one or several camera nodes but only one runs the GUI.
The GUI allows to select one of the configured camera node, and read or set some key configuration parameters for that camera:
- (Detection) Threshold. This is the number of pixels which need to change, from one frame to the next, for Motion to detect a “movement”. Think about it as the detection sensitivity. Setting it to zero or to a very high number will, in fact, disable movement detection. Detection generates notifications and emails which may be overwhelming if you are not interested in the surveillance of the system. Also bear in mind that detection is based on pixels changes, so , unlike others solutions such as PIR (Passive Infrared Sensors), it can be configured to be very sensitive but is also subject to changes in lightning conditions.
- Timelapse interval. If set to 60 (for example), the system will take a picture every 60 seconds, and, at the end of the day or the end of the hour, it will automatically generate a video clip from the captured pictures. The effect is a kind of time contraction.
- Snapshot interval. Same as timelapse but the individual pictures will be available, in case you want to process them on your end.
If motion detection is configured and a motion detected, you will get a notification on your smartphone, as well as a email with a picture of the detection attached.
The URLs included in the smartphone notification are clickable, and point to a picture and a short video recorded at the time of the detection event. By looking at those you can see what happened.
Both the picture and the video are stored in a web server running on the camera node. They are available thru a simple photo gallery application.
This web server can be made available from outside your home network using standard NAT (network address translation) configuration.
A menu on the GUI gives access to:
- stream: this is a real time stream of the camera in your web browser.
- gallery: the pictures of detection events, stored in the camera web server.
- admin: the Motion admin console (typically not needed).
- monit. the status of the camera node (cpu, file system, network, key process, etc. ..).
The camera(s) status are also pushed on a regular basis (eg every 30mn) to your smartphone. Just to get reassured.
Finally, the GUI allows also to stop, reboot a camera node, and view/change passwords.
Holistic management of password was a key function I wanted to develop. It turned out to be not that easy. Each of the component ( Motion, the GUI, monit and the photo gallery) has a separate password. And each password is stored in a specific configuration file.
Now it is time for serious RPC (Remote Procedure Calls) and automatic edition of text files (sed and regex are my friends). This was the most painful part of the project, (or the most interesting, depending on how you view the world).
The system is now relatively well packaged (all key parameters are in json files) and can be duplicated easily.
As I keep offering it to my family and friends, some are interested in the surveillance feature, some in the garden monitoring, some just want to get rid of me …
But I will have no rest until my two daughters tell me, yes Dad, we want one of your camera.