Detecting if someone is in a room in your house and sending you an email.

Posted by mbcrump on Geeks with Blogs See other posts from Geeks with Blogs or by mbcrump
Published on Fri, 09 Apr 2010 16:08:53 GMT Indexed on 2010/04/09 23:23 UTC
Read the original article Hit count: 473

Filed under:

Let me setup this scenario:

  1. You are selling your house.
  2. You have small children. (Possibly 2 rug rats or more)
  3. The real estate company calls and says they have a showing for your house between the hours of 3pm-6pm.
  4. You have to keep the children occupied.
  5. You realize this is the 5th time you have shown your house this week.

What is a programmer to do?……Setup a webcam, find a motion detection software that has support to launch a program and of course, Visual Studio 2010.

First, comes the tools

  1. Some sort of webcam, I chose the WinBook because a friend of mine loaned it to me. It is a basic USB2.0 camera that supports 640x480 without software.  image
  2. Next up was find webcam software that supports launching a program. WebcamXP support this.
  3. VS 2010 Console Application.
  4. A cell phone that you can check your email.

You may be asking, why write code to send the email when a lot of commercial software motion detection packages include that as base functionality. Well, first it cost money and second I don’t want the picture of the person as that probably invades privacy and as a future buyer, I don’t want someone recording me in their house. Now onto the show...

First, the code part. We are going to create a VS2010 or whatever version you have installed and use the following code snippet.

Code Snippet
  1. using System;
  2. using System.Net.Mail;
  3. using System.Net;
  4.  
  5.  
  6. namespace MotionDetectionEmailer
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             try
  13.             {
  14.                 MailMessage m = new MailMessage
  15.                    ("[email protected]",
  16.                     "[email protected]",
  17.                     "Motion Detected at " + DateTime.Now,
  18.                     "Someone is in the downstairs basement.");
  19.                 SmtpClient client = new SmtpClient("smtp.charter.net");
  20.                 client.Credentials = new NetworkCredential("mbcrump", "NOTTELLINGYOU");
  21.                 client.Send(m);
  22.             }
  23.  
  24.             catch (SmtpException ex)
  25.             {
  26.                 Console.WriteLine("Who cares?? " + ex.ToString());
  27.             }
  28.         }
  29.  
  30.     }
  31. }

Second, Download and install wecamxp and select the option to launch an external program and you are finished.

Now, when you are at MCDonalds and can check your email on your phone, you will see when they entered the house and you can go back home without waiting the full 3 hours. --- NICE!

image

© Geeks with Blogs or respective owner