Motion control with multiple cameras

I got a bit bored of playing with node.js over the weekend, so I dumped some time into my home security system (which is a grandiose title for what’s basically a couple of cameras and some software) and have now got it into a reasonable state, so I thought I’d write a quick post about it.

The idea of having some sort of security system in my house came about recently because I’m starting to spend more and more time away from home with my lovely fiancee so I wanted something to keep an eye on the house whenever I was away.  I did some googling and found this bargain basement IP camera on amazon:

 

 

The price seems to go up and down on a daily basis, and there’s a few variations on the same basic model but I got mine for £33 and it offers wifi, pan and tilt support (it has little motors that you can move the camera orientation with) and motion capture support.  All sounds rather spiffy.  And indeed the camera itself is pretty good.  The fact it actually has infra red illuminators on it means it can see in the dark remarkably well for such a cheap device, and I had hours of fun messing around with the motorised movement.However after a bit of playing with the motion capture I decided it was a rubbish (it can only send still images over ftp or via email, not very useful) so I decided to have a bit of a play with the rather awesome motion.

After some teething issues I discovered you can set these IP cameras up quite easily using a url like ‘http://HOST/videostream.cgi?loginuse=USER&loginpas=PASS and from there it was pretty straightforward to get motion detection configured (although there was some fine tuning needed to the parameters).  I set up motion to save any captured images / videos into a dropbox folder and voila… DIY motion capturing security system with offsite backup.  I’ll be buying another couple of these cameras in the near future and adding them to my setup.

One problem with this setup is motion’s interface.  There’s a basic web server built in, but if you have multiple cameras it launches a new thread for each camera, and you control motion detection for each thread independantly.  So with two cameras you have to go to 2 urls to enable or disable the motion detection.  Fear not though, I’ve written a little python script that prompts for a password, and then enables or disables all your cameras at once if you enter the correct password.  It shouldn’t be taken to be anything like secure (I don’t even have a username / password set on my motion install since it’s only accessible on my internal network) and you can ctrl-c out of the script at any time…… but the long term plan is to setup a raspberry pi with a little lcd screen and a numpad and use that as the controller…. maybe rig it up to play sound files when activating / deactivating the motion detection.  Anyway, here’s what I have so far, enjoy! (also, this is my first attempt at a python script that actually does something useful, so please excuse any stupid errors in here)

#!/usr/bin/python
import getpass
import requests
import os

#we always assume that all cameras have the same status
def get_status():
        response = requests.get(url= host+"/1/detection/status")
        if response.status_code == 200:
                if "PAUSE" in response.text:
                        return 0
                else:
                        return 1
        else:
                return -1

def toggle_status(current_status):
        if current_status == -1:
                return
        if current_status == 0:
                path = "/detection/start"
                out = " started"
        else:
                path = "/detection/pause"
                out = " stopped"
        for x in range(1,camCount+1):
                response = requests.get(url= host+"/"+str(x)+path)
                if response.status_code == 200:
                        print "Camera "+str(x)+out
                else:
                        print "Error with camera "+str(x)



camCount = 2
password = "PASSWORD"
host = "http://HOST:PORT"

while True:
        os.system('cls' if os.name=='nt' else 'clear')
        status = get_status()
        if status == 0:
                print "Motion detection disabled"
        else:
                if status == 1:
                        print "Motion detection enabled"
                else:
                        print "Error determining status"
        input = getpass.getpass("Enter the passcode: ")
        if input == password:
                toggle_status(status)



No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *