Working with software developers on a daily basis makes me want to code too occasionally. At least in my spare time. Mainly in the winter period. This allows me to experience the challenges they face. Analyse the problem and the edge cases from a different perspective. Find and evaluate alternative solutions. It is great joy when it finally works the way I imagined. I believe this helps me to be more emphatic with the developers during my day job.
Recently I wanted to do an experiment with Raspberry Pi: build a home security system. I wanted it to be always on, but only capture video when something happens and notify me about it. I was thinking of doing it with a motion sensor initially. After I some research it turned out, that I don’t have to buy the motion sensor. It can be accomplished by free software. I had some reservations about detecting motion this way as I thought it might be triggered too frequently or would skip a few events. At the beginning I did not know how much coding will be necessary.
To start the project I ended up buying
- a Raspberry Pi Zero W in a starter kit
- a Raspberry Pi Model B also in a starter kit
- a couple of cameras: Camera Module V2 (5MP), Pi NoIR Camera V2 (8MP), and an 5MP infrared night vision camera
- a bunch of cables (the Pi Zero needs the orange FCC one and the Model B needs the lightgrey FPC one) and camera stands
- power adapters and cases for the Pis (these came with the starter kit)
- a memory card reader
I bought 3 different cameras as I didn’t know what to expect. Which one is going to be the best for my needs. Actually, I still don’t know for sure. The 5MP official camera is producing suprisingly good images, but it is obviously blind in dark. The NoIR camera has the best image quality in daylight out of the three. However it requires a separate infrared light source which I am yet to buy. The night vision camera came with infrared lights I can attach to the camera. These IR lights aren’t that strong, so the distance is limited. The other issue is that they glow slighlty red, which is clearly visible to the naked eye. Finally they heat up and stay quite warm during operation. As you can see neither is perfect, but hey, these are very cheap. I got fairly good image quality for my money with all of them.
My setup is that I use the Pi Model B as the server (as that one has more processing power than the Pi Zero) and the Pi Zero with a camera to operate the camera. It is the Pi Model B which is capturing the video when it detects motion. I found quite a few articles talking about a free software called MotionEyeOS which is capable to do everything what I wanted. I found these how to articles the most helpful in the process:
All I had to do is to assemble everything following the steps to get the camera and the entire ecosystem working together smoothly. I had to install and configure things, but no coding was required at all. It was very easy and fun. Oh, and the motion detection software works like a charm.
Uploading footage to Dropbox automatically
Once everything was installed I experimented with the settings. It took quite some time to find the ones best for my use case. I think the email notifications is very handy. As well as the option to upload the files to Dropbox. The latter enabled me not just to simply store the footage, but to share it with multiple people and watch it remotely without exposing my device on the Internet.
How to avoid running out of space?
There was one issue though. I had to delete every single file manually on Dropbox as the retention setting only applies to videos stored on the device locally. In the first few weeks it did not bother me much, but then I went on holiday and the storage space got used up, so no new videos were uploaded. To solve this issue I first read Dropbox’s documentation. Then I found a web app, called Finesse which can schedule deletion, just like I wanted for $48 a year (apparently it used to be free). Given this is a hobby project I don’t want continuously spending money running it.
Scheduled deletion of old files from Dropbox for free
In the end I decided that I solve this on my own and wrote a small Node.js app DBDelete which I scheduled to run with crontab several times a day. This app deletes recordings in the MotionEye app folder on Dropbox which is older than 24 hours. It is using Dropbox’s own API and it is very easy to setup and change the folder or the number of hours after it deletes files.
No more running out of storage space, no more manual deletion and best of all it is free. Go an get it if you also have a similar issue that this app would solve.
I have to say that I enjoyed this project a lot and I ended up learning some Node.js. Something which I didn’t expect at the start 🙂