Other Projects

Automatic Security Camera

8 5649
Post Last Edited by jkw at 2014-10-8 10:08

Hey guys,
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:

  1. 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...
Copy the Code
(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.

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
- LLama

- 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).
Loosk nice! Good luck!

Edited by egmail at Wed Nov 26, 2014 09:02

I purchased bananapi
I have 2 escam qd320 ip cameras.
I have 500gb sata drive bananapi does not recognise
I would like bananapi to record in loop to hdd the image from 2 ip cameras. Can you prepare img for a small amount of money or write a step by step toutorial?

Your llama and email notifications are a great idea do save disk space.

I've set up a similar system using motion on the Pi. However I'm using a custom bash script for IP detection : if the scripts doesn't detects our smartphone IPs on the network, detection is started. It stops when our IPs are detected.

I only have the simpler script at hand, it could manage one IP and one camera. But I've an improved version for multiple IPs and cameras. Ask me if you're interested (it's in a old Pi backup)
  1. #!/bin/bash

  2. # IP address of your phone
  3. MYIP=""

  4. #ip address of your motion server
  5. MOTIONIP=""

  6. # Results of ping of phone ip
  7. PROXIMITY="$(ping $MYIP -c 1)"

  8. # If the phone was not found, start detection on all cameras, else stop detection
  9. # on all cameras
  10. if [ "$?" -eq 0 ]; then
  11.         echo ip detected Dissarming detection

  12. # Change the ip address to match your motion server
  13.         wget -q --delete-after http://$MOTIONIP:8080/0/detection/pause 2>&1 >/dev/null
  14. else
  15.         echo ip not detected Arming detection
  16. # Change the ip address to match your motion server

  17.         wget -q --delete-after http://$MOTIONIP:8080/0/detection/start 2>&1 >/dev/null
  18. fi
Copy the Code
You could execute it each minute with cron or add a loop+sleep for continuous detection

Could you please post some pictures ?

Hi all together,
I´m a beginner and I´m interested in this project. Is there any code available?????????? (I hope so!!!)

I would like to give an approach using my solution www.jubito.org.
http://jubitoblog.blogspot.gr/20 ... sing-ip-camera.html

Edited by sk1312 at Jan 09, 2017 04:27

Good day!
A short time ago i build little survilliance system on BPro. I have two webcam to control presence in my flat.
I used motion. BPro have enough power to control bouth webcam in realtime with 5-10 fps. I write two scripts and starts it by cron. First starts motion when i go to work, second shut it down, when i come home. Every day cron starts and stops motion, exept weekend. Very simple. First, i like to starts motion by IR remote, but it`s to complecated. Whell. I have USB 8GB drive, motion put everything on it, if some motion has been captured. Then, every hour, cron send all data from USB stick to my cloud. Motion have option to perform some action when motion is detected. you can write script to send you mail, or trigger an alarm. That`s it. Sorry for my english.

Oh, about phone activated system...There is a package, bluetoothproximity. It`s bluetooth triggered mechanism. If some special bluetooth device is in range, maybe your mobile phone, this soft can kill motion. But when you are go away, motion will starts...That is an idia, nothing more.

I really appreciate your work to do this project. I payforessay to know the updates on many apps and softwares. I have gotten many technological information here.

You have to log in before you can reply Login | Sign Up

Points Rules