Post Last Edited by jkw at 2014-10-8 10:08 |
I've started a little project that runs now for a week pretty stable and I'm curious if you have some addition ideas.
The reason for this project was an article about the program motion, that uses the webcam to detect movements in the surrounding and saves pictures.
I thought it would be nice to have a little security cam, watching my apartment as long as I'm not at home.
Upfront: I'm pretty sure that I won't ever need it, there hasn't been a crime going on within the last years, its more to play around with the bpi.
The first problem from my perspective is that Motion will just save a picture on the local disk, so if there is someone in the flat, I won't realize it until I'm back home. Calling the police in time is not possible. And if that persons steals the pi, the evidence is gone.
1. Improvement: Report alerts via mail
To fix this issue I've written a simple python script. The script (once it gets called) will wait up to N (default 5) sec or until M (default 4) pictures have been generated by motion and then attach them to a Mail and send them instantly to my phone.
Of cause I'll get a lot of pictures of myself or my wife as someone comes home - not perfect ;) So I have to switch of the motion detection as soon as anyone of us is at home. Motion has a webinterface where you can pause/resume the detection, so my first idea was simply to create a browser bookmark that will start / resume the detection. The problem is that I'm not really rely on my brain. I'll forget to activate it very often and the woman-acceptance-factor will be very low, so this is not a good solution.
2. Improvement: Increase usability
I'm using an app called LLama for a very long time. It can "do things" based on your mobile-cell based location. I have a bunch of profiles like: "As soon as I've left my home cell (actually it is the area "home" that has multiple mobile-cells) it will
switch of my wlan interface". Or: "As soon as I enter "work" it switches the phone to vibrate" ... etc
My idea was to toggle the state of my security cam, based on my personal location provided by llama: "As soon as I've left home it should call the URL to activate the alert system" and "switch if off once I enter the are home".
This has 2 problems: 1. LLama can open bookmarks, that works. Fine. But that leads to an open browser window showing the motion webinterface every single time I leave/return home. Thaaaaat's ... ugly. Woman-acceptance-factor = 0.1 (of 10)
So I wrote an android app that can just "touch" a web-server. It opens, starts a service in the background and closes. The service will call the url and shutdown once this is done (more later). That's perfect, it take <0.1 sec so its very hard to see at all. W-a-f: 9.9/10
LLama starts my program, that sets motion, aahh ... fine. But wait! As soon as I leave home my wife might be still there. Activating the alert system leads to a lot mail with photos of her, nice but after a few days annoying. Problem Nr. 2!
(Of cause she has the same apps installed (LLama + my "call_url"), but as long as she isn't frequently "entering" our home zone as soon as I leave it LLama won't re-de-active the alert system that I've just activated. So I have to combine our states.)
3. Improvement: Just activate the alert system if everyone has left and stop it as soon as anyone comes home.
I already had a web-server incl. php and mysql running on my bpi, so I've written an php script that gets called with a user name and a location like this:
(of cause I've added addition parameter like a key to ensure just I can update my state but me). The set.php will update my record in the database and check if everyone has left home. If so, it calls the motion interface to activate the detection and of cause the other way around -pausing motion- as well. Copy the Code
- http://mypublicurl/set.php?user=bob&location=home or http://mypublicurl/set.php?user=bob&location=not_home or http://mypublicurl/set.php?user=susan&location=home and so on...
This is the state of the system so far. It might look complicated but once it is installed it runs without any user interaction.
- Motion (and of cause a webcam + pi)
- PHP / mysql / webserver
- Android app "Call_url"
- phython script "send mail with pictures if alert"
- php scripts "pause/resume motion"
- To ensure that everything is working I've written a log.php, showing on a graphical dashboard (still ugly) our movement and the time we've been away = the time the system was active.
- I saw that LLama will to something like this: "07:01:23: bob left home, 07:01:24: bob returned to home, 07:01:25: bob left home" and so on.. to compensate that my program (call_url) will start the service that will WAIT K (default 10) sec
to call the last url generated by LLama. This will reduce the entries in the database.
- I don't want to expose the livestream to the public, but it would be nice if I could see it from the office once motion tells me that something is going on there.
Motion has no encryption on the mjpeg stream so I added a "status.php" that will reload every 3 seconds, grabbing and displaying a picture from the stream.
That status.php can be secured with the key so I can open the stream but no one else
- I had some problems with motion so my set.php will send me a mail if it had no success setting the state of the detection system. In addition I've complied a modified version of motion that will restart motion, once it crashed.
Right now I'm discussing (with myself) if I want a second cam in my garage (I have a second pi with no use, but I would have to buy a second camera ... uff).
The scalability of the system would be very easy, I would just copy the same "send mail with pictures if alert" script to the second pi and the first "super" pi would have to call two URLs once the system should goes "online/offline".
Everything else could stay the same. (If my garage would be far away I could clone the hole pi and create a new area in LLama resuming and pausing only the second pi once I arrive there ... but its not)
So now you read a very long story, what do you think? Where could I improve, because usually things gettin' boring once everything works.
(the good thing: the android app crashes every once in a while, it will set my status but crash after that so there is room for improvements).