BSS – Brainfusion Surveillance System

BSS app iconLast weekend I sat down and built a surveillance system, including an iPhone webapp, for my apartment using my old iBook, an external iSight, the Webcam Software EvoCam and a set of scripts in AppleScript, PHP and some shell scripts.

The whole thing is pretty custom made but I’ll document it here anyway and with a basic understanding of the technology it should be fairly easy to reproduce with whatever hardware you have available. At the end of the post you’ll find a ZIP file with all the scripts I used in the setup.

The set up

  • The iBook has the iSight connected and pointed at the entrance door.
  • iBook is using MAMP to serve PHP scripts and produces some audible confirmation messages.
  • The iPhone webapp shows if the system is armed or not, can start or stop EvoCam, lists all the available surveillance videos and offers a link to the live video stream.
BSS CTRL center

BSS CTRL center

Read on for the whole article with a detailed explanation of all components.

The course of action

In addition to the control center there are also two separate webapps for starting and stopping BSS. This allows me to have the three related icons positioned in the bottom left corner of my iPhone home screen. Now whenever I leave the apartment I just need to turn BSS on, with a touch of my finger.

BSS home screen icons

BSS home screen icons

The iBook then launches EvoCam and announces “BSS armed” through Apple’s built in text to speech engine, so I can hear if everything started up properly. Whenever EvoCam detects motion on the entrance door it will record a video (including a 2 second buffer before the motion event occured and 10 seconds afterwards) and save it to a webaccessible folder.

At this point I still haven’t decided on the best form of notification I will send out. Right now there’s a little AppleScript, triggered by EvoCam, that uses Mail.app to send me a predefined Email with the subject “Intruder Alert!”. But this method is a bit of a performance hog, so I’ve considered a number of alternatives. One easy possibility would be to send out an alert via Twitter, but there are also ideas like starting a FaceTime call, having a Push enabled iPhone app that receives the notification or hacking together some kind of way to alarm me via SMS (short message service).

When I get a notification I can choose to see the live stream or the archived video from my iPhone right where I am. The videos are compressed in a format that is playable on iOS and stream nicely over 3G.

When I come home I take out the iPhone again and push the stop button. The system will then announce “BSS disarmed” as soon as EvoCam has quit and I can open the door without triggering an alarm.

Possible additions

There are a number of improvements I can think of that will be incorporated once I have the time to do them.

  • Using a cookie to save the list of videos, each time the control center is opened. That way I can append a little “new” badge on each video link that wasn’t there the last time I started the webapp.
  • Re-programm the webapp to use only AJAX (probably using jQuery), so I don’t fall out of webapp context, whenever an outside link (video, live stream…) is opened.

EvoCam configuration

  • On the “Recording” tab set the Destination path to the folder you want your movies in (/Users/ibook/Sites/bss/ in my case). Then choose “Advanced” and set the filename to “YYYY-MM-DD-HH-MM-SS.mov”
  • Select a suitable amount of frames to be prepended to the beginning of the video under “Use Standby Recording”
  • Leave “Use Schedule for Recording” unchecked
  • Go to the “Items” tab and add a sensor that covers the part of the image you want to monitor for motion.
  • Under “Settings” for that sensor ensure that the sensor is always active and check “Perform actions selected in the “Refresh” tab”
  • Configure how long the video should continue recording after the sensor triggered.
  • Leave all other boxes unchecked.
  • On the “Refresh” tab choose “When motion is detected” and select the actions you want to take place.
  • If you want to run an AppleScript on an event, choose “Options” from the main menue and select “AppleScript Settings”.
  • If you want live video, be sure to turn on EvoCam’s internal webserver on port 8080.

Of course there are a lot more settings and tweaks in EvoCam, so once the system is running, come back here and click through everything that’s available.

The scripts

The main hub is the index.php file in the BSS root folder. It renders out the HTML for the webapp and ties together all the other components. Download the ZIP file at the end of the post and have a look through all the files, it should be pretty self-explanatory and I’ve added a few comments but you do have to adjust all the respective paths and your security token (more on that below) to fit your setup.

The start_evocam.sh and stop_evocam.sh scripts are called via their respective web frontend (PHP scripts in subfolders). They launch and quit evocam and announce the status via text-to-speech. status.sh uses an AppleScript oneliner to report 0 if EvoCam is stopped or 1 if EvoCam is running. It also has an accompanying PHP caller script in the status subdirectory. If you’re confused by the weird folder set up, let me explain. Every script lives in it’s own subdirectory, so via HTTP I can call all the functions just by appending the name to the base URL. If I need status information I call http://myhome.com/bss/status. The same applies to the start & stop commands.

The bss folder needs to be copied to a webaccessible directory – in my case that is my MAMP web root (in my case: “Sites” in my user folder).

Security

(kind of!)
Every PHP file’s first line consists of a check for a token, that is sent via the HTTP call. So to start the system you’d have the URL http://myhome.com/bss/start?t=MYSECURITYTOKEN or the server will give you HTTP Status code 403 (forbidden). Of course this is all sent in clear text and could be easily sniffed, so be sure to implement whatever better security system you need for you environment. But since the URLs only need to be entered once and are then concealed from the screen by iPhone’s webapp fullscreen capability, I thought that should be enough for the moment.

Network

To have access to the security system it is necessary to map port 80 (the main webserver) and port 8080 (EvoCam’s internal webserver for the live stream) via NAT to the internal IP adress of the Mac running the security system. Otherwise you won’t be able to access the system from the outside.

BSS CTRL center startup

BSS CTRL center startup

iPhone installation

Once all the scripts pathnames and tokens are edited accordingly, you just have to open http://myhome.com/bss?t=MYSECURITYTOKEN in Safari on your iPhone and add it to the home screen by tapping the little plus symbol on the bottom toolbar. Now the BSS control center lives as an icon on your iPhone and will start up in fullscreen with a pretty startup image. For the start and stop buttons you have to open http://myhome.com/bss/start?t=MYSECURITYTOKEN and http://myhome.com/bss/stop?t=MYSECURITYTOKEN and add them to the home screen as well. Each webapp comes with it’s own descriptive icon and title.

Now your surveillance system should be set up and ready to go.

Improvements

I have a custom website.html file with a black background and no borders that is not included in the download. This file is used by EvoCam to display the live stream on my iPhone.

The AppleScript to send Email is also omitted from the download, as this is easy to figure out and I’m still not sure this will be the final way of delivering alert notifications.

If you have any ideas for additions or improvements  I’d be happy to hear them!

Download

Here is the first (and probably last) public release Version of BSS the Brainfusion Surveillance System:

BSS version 1.0

BSS version 1.0

9 comments

  1. Very cool.

    Some suggestions:

    Your video folder should be mirrored with a service like dropbox in case someone steals the computer that contains the videos.

    For a better notification system, check out Amazon’s SNS: http://aws.amazon.com/sns/ which lets you create a topic and subscribe any combination of email addresses to that topic. They’ve mentioned that direct SMS support is coming, but right now you can just subscribe your iphone’s SMS email address to it. Pushing messages to this service is super simple and very reliable.

    Amazon’s SNS is free for the first 100,000 notifications a month, so it should be cheap enough 🙂

    For the security of the token, you should install an SSL cert (~$35 / year), only access the service over https:// and move the token to a cookie to make it unsniffable.


  2. Scott:

    Your video folder should be mirrored with a service like dropbox in case someone steals the computer that contains the videos.

    My video actually gets uploaded to a dedicated server in a datacenter in germany. So it should be pretty save. Eventually I’ll load the videos in the control center webapp from the server because it has a 100MBit/s connection compared to my very thin upload at home. I just didn’t include those bits in the article, because I can’t expect everyone to have that setup available.


    Jeremy Sanchez:

    You could install Boxcar on your iPhone and then use their Push Notification API to send alerts.

    Ah! Why didn’t I think of Growl as a notification system?
    I already have Notifo and Prowl installed on my iPhone, so sending out push messages via the Growl framework on the iBook should be pretty easy. Thanks for the tip with Boxcar that led me to that idea!

  3. I use the iPhone app iCam for this.

    iCam allows me to view video and hear audio from up to four computers from my iPhone or from a web client.

    It supports push notification for motion events, and the motion detection can be turned on and off from the app. The only thing it doesn’t do is record full video and audio when something is moving; only still images that are captured and archived.

    I recently ran across a success story in the news, where someone was broken into while on vacation hundreds of miles away. iCam notified him and he was able to call police while the intruders were still in the house.

  4. For notification, you could try the $3 app Prowl. It supports a number of options to send push notifications to your iPhone, including the ability to react and open a URL on the iPhone side of things.

  5. I already had Prowl on my iPhone, but after Jeremy Sanchez’ comment I tried out Boxcar and I must say I like it a bit more. So I’m going to try and hack something together with the Boxcar API whenever I find the time.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.