Thursday, January 26, 2012

The Internet Doorbell Mk I


VR doobell with recursive doodad thingy picture
I like things simple.

That's just how it is.  Things most people have no problem with bother me. 

For example:

I have a house in Second Life that my online friends occasionally visit. I also have a house in real life that my real life friends occasionally visit. It bothers me that I have to treat these two houses separately, that I have to constantly context switch between them. It seems inelegant. Primitive. So I've decided to overlap the two using vinterstitial objects and spacial techniques.

I'm trying to merge my real and virtual lives, become a whole person again.  Is that so wrong?

To accomplish this I am going to start with the front door. The plan is to have my doorbell in VR ring my doorbell in RL and visa versa.

technical architecture diagram
Platform: 

WiFly Xbee module
I needed a relatively inexpensive stand alone solution that combined a programmable controller with wifi wireless capability.  I intend for this platform to eventually include other functionality to support my project so it needed to have decent digital and analog i/o capability.   I was also interested in having battery backup and/or power.   I chose the Arduino Fio and WiFly Xbee module.   The Fio is a great little arduino, it is inexpensive, has a xbee socket on the back already and a built in charger and battery connector, so minimal work is needed to meet my goals. The WiFly Xbee module is an inexpensive drop in wifi replacement for the popular 802.15.4 xBee radios. This means that I can program my Fio wirelessly via the xbee radios, test the code via the serial port, then simply switch in the WiFly module and the fio for standalone wifi. For comparision consider an Uno and wifi sheild ($30 + $90 = $120).  The Fio and WiFly xbee I use costs ($25 + $35 = $60) and has a battery connector, wireless programming and charger circuit.   I have a feeling I'll be using the Fio + wifly xbee quite a lot.

My RL doorbell guts and diagram
Doorbells:

Most doorbells are simple buttons that power a selenoid striker that hits the chime plate(s) when the circuit is closed.  They generally have support for two different chimes so that the front and back doors have different rings.  This is usually accomplished by having two selenoid strikers, one that rebounds from the first chime plate strike and hits the second chime plate, creating the classic doorbell 'ding dong'.  That is also why the dong can be delayed by holding down the doorbell button.  "Ding.........Dong..Ding.Dong...Ding......." The second striker is blocked from strike plate two so it only chimes once "Ding".

Hand Crafted Project Harness



Ringing the Doorbell from the Internet:

The Fio/Wifly connects to my home network automatically on powerup and runs a simple web server listening on the (newly dubbed) standard internet doorbell port of 33301.   My home router forwards any requests from the internet on that port to my home's public ip address to the fio. When the fio gets a http request it rings the doorbell "Ding" and sends a message back to the requestor.  Easy peasy.
Solid state relay
Relay Hardware:

I used a solid state relay kit from sparkfun although any sort of relay with the proper characteristics should work fine.  Basically doorbells are ~15-25V AC, so solid state relays are a really good solution (they generally can't switch DC on/off).  Most solid state relays are also opti-coupled.  This means there is no current path between the 24V AC and your arduino, which is a good thing in case your arch enemy's robot tries to fry it via the doorbell.  I suppose your doorbell is also protected from cyber threats as well.  Doorbells can be dangerous in the wrong hands so be careful.

Planned Improvements:

  • Bi-Directional - ie add a RL doorbell detector circuit and ring my internet doorbell
  • Add a text display to tell me who rang the internet doorbell
  • Add a video camera capture to tell me who rang the RL doorbell
  • Power the circuit off of the doorbell AC.
  • Add mobile device notification.

Do It Yourself:


/**
 * Internet Doorbell Web  Server for Arduino - 
 *   note, this is http over serial since I'm using a FIO and a WiFly module, 
 *   which implements the tcp/ip server in the wifly module 
 *
 *  this code is in the public domain
 */

int inByte = 0;
int doorBell = 2;
int relayPulse = 40;
boolean silent = false;
boolean startLine = true;

char LF = '\n';
char CR = '\r';

void setup()
{
  // start serial port 
  Serial.begin(57600);
  Serial.flush();
  pinMode(doorBell, OUTPUT);
}

void loop()
{
  
  delay(20); // let serial get ready
  
  while(Serial.available())
  {     
        char c = Serial.read();
        
        // if you've gotten to the end of the line (received a newline
        // character) and the previous line is blank, the http request has ended,
        // so you can send a reply
        if (c == LF && startLine) {
           
          // ring doorbell
          if ( ! silent)
          { 
            digitalWrite(doorBell, HIGH);   // sets the doorbell relay pin on
            delay(relayPulse);                  // power the relay
            digitalWrite(doorBell, LOW);    // sets the doorbell rela pin off
          }
           
           // send a standard http response header
           Serial.println("HTTP/1.1 200 OK");
           Serial.println("Content-Type: text/html");
           Serial.println();
    
           Serial.println("<html><body style=\"background:white;color:black;\">")
           Serial.println("<h1>Doorbell Rung</h1><h2>ding dong ding dong</h2></body></html>");
           Serial.println();
           Serial.println();
           
           //startLine = false;
           //flush whatever other detritus the web client has sent us
           Serial.flush();
           delay(10);
           break;
        }
        else if (c == LF) {
          // you're starting a new line
          startLine = true;
        } 
        else if (c == CR) {
          // ignore \r
        }
        else 
        {
          // you've gotten a character on the current line, toggle flag
          startLine = false;
       }
  }
}

// Vinterstitial Doorbell 1.0
//  LSL

// Global Variables

string doorbellUrl = "http://your.doorbell.com:33301";
string baseUrl = "http://vinterstitial.blogspot.com/2012/01/internet-doorbell-mk-i.html";
list params = [];
string request = "GET /";
string body = "REAL doorbell not rung.  :(";
key http_request_id;

// Functions

displayHTML(string url)
{
            llSetPrimMediaParams(2,                  // Side to display the media on.
            [PRIM_MEDIA_AUTO_PLAY,TRUE,      // Show this page immediately
             PRIM_MEDIA_CURRENT_URL,url,    // The url currently showing
             PRIM_MEDIA_HOME_URL,baseUrl,       // The url if they hit 'home'
             PRIM_MEDIA_HEIGHT_PIXELS,512,   // Height/width of media texture will be
             PRIM_MEDIA_WIDTH_PIXELS,512]);  //   rounded up to nearest power of 2. "data:text/html," + 
             
}

// Main

default
{
    state_entry()
    {
        llSay(0, "Internet Doorbell Active!");
        llSetText("", <1.0, 1.0, 1.0>, 1.0);
        displayHTML(baseUrl);
    }

    touch_start(integer total_number)
    {
        http_request_id = llHTTPRequest( doorbellUrl, params, body );
    }
    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == http_request_id)
        {
            llSay(0, body);
            displayHTML( "data:text/html," + body);
            llSetTimerEvent(30);
        }
    }
    timer()
    {
        llSetTimerEvent(0);
        displayHTML(baseUrl);
    }
}

7 comments:

  1. A worthy goal. Are the layouts the same for both your second life house and real world houses? Would that be more elegant?

    ReplyDelete
    Replies
    1. They aren't really, however I think at least the overlapping space, ie the living rooms will have a similar layout.

      Delete
  2. dig your use of the rn-xv and the Fio's. i use the fio in my project as well. www.onyx-ashanti.com i have been using the xbee series ones but recently purchased a few of the rn-xv's and am itching to use them, but i have a slight issue. when i plug them into the fio, the fio power light blinks intermittently. the rn-xv (which i have not configured yet) blinks 3-4 times then it goes green for a sec then both it and the fio start the blink cycle over. would you have any sage wisdom that might be useful? i think i just need to set the power settings in the rn-xv but i dont know because i just got them yesterday.

    keep up the good work. maybe i will visit you on second life and ring the bell (onyx moo)

    onyx

    ReplyDelete
  3. Thanks for sharing such an important post. For getting best Xbee examples to understand XBee tutorial. It's very beneficial for readers.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. Doorbell Camera Reviews

    ReplyDelete