BlueIris IP camera activation

Hey Guys,

I am new to arduino, and brand new to this forum so I am hoping that I am posting in the correct category. We have had some security issues and as a result I installed a couple of IP cameras made by foscam and turned one of my PCs into a camera server with a program called BlueIris. Some of you may be familiar with this but the story goes that for a while now I have been using it's video based motion detection with good results but a massive amount of false alarms. These false alarms are very annoying and I am beginning to not notice them as much (BlueIris sends push alerts to my cell). However BlueIris has support for digital I/O boards, one of which being our favorite uno R3. Unfortunately it will only recognize one uno, and it must be on a com port (IE attached via USB). So here is my end goal:

I bought a batch of Arduino goodies that included an R3 uno, and a Yun. I bought a LAN shield for the Uno and a couple of PIR sensors.

Idea is, I have the Uno attached to my PC via USB, and it also has a PIR sensor on it. I then will place the Yun outside in a custom built box (yet to be designed but not a big deal) with several PIR sensors to watch over our vehicle. The Uno will activate my indoor cameras, and the Yun my outdoor along with all the alarms and push alerts. The Uno must be able to check the Yun for sensor highs and lows. This should be very reliable, and also more efficient as the PC will not have to sit there and crunch numbers on the pixels for the motion detection day and night.

I have been learning the language on my own, and looking at some other guys who did something similar (my situation is much different, though). Right now, I have the Uno with the LAN shield in a situation where it works successfully with the indoor cameras and I can see it on the network. I also have the Yun attached to the network via Wifi, however I cannot get the two to talk to each other.

I started off with the Uno and no LAN shield just to put it into service on the indoor cameras. The following code works perfectly and I have had zero false alarms this week:

//second attempt at making a PIR activate onboard LED as well as BI trigger
//THIS SKETCH IS SUCCESSFUL WITH TRIGGERING INDOOR CAMERA
//USE ARDUINO UNO R3 WITH CHINESE ADJUSTABLE PIR ON COM3 AND SERIAL BIT 2 IN CAMERA OPTIONS

//vars
int calibrationTime = 60;
int ledPin = 9; //led pin number
int pirPin1 = 2;//digital pin connected to primary PIR out

long unsigned int lowIn; //time the sensor outputs a low impulse
long unsigned int pause = 5000;//amount of millis the sensor has to be  low before we assume all motion has stopped

boolean lockLow = true;
boolean takeLowTime;



void setup() {
 Serial.begin(9600);
 pinMode(pirPin1,INPUT);
 pinMode(ledPin,OUTPUT);

 
 //sensor calibration
 for(int i = 0; i<calibrationTime; i++){
   digitalWrite(ledPin,HIGH);
   delay(30);
   digitalWrite(ledPin,LOW);
   delay(970);  //flashes LED until calibration over
}
Serial.print(0);
}

void loop() {
//Primary PIR sensor
   if(digitalRead(pirPin1) == HIGH){
     digitalWrite(ledPin,HIGH); //turn on the LED when motion sensed
     if(lockLow){
     //makes sure we wait for transition to LOW before any further output is made
     lockLow = false;
   }
   takeLowTime = true;
   Serial.print(2); //send ASCii signal to BI to start recording
}
if(digitalRead(pirPin1) == LOW){
digitalWrite(ledPin, LOW);//LED turns off or stays off
if(takeLowTime){
  lowIn = millis(); //save the time of the transtion high->low
  takeLowTime = false;
}
//if the sensor is low for more than the given pause,
//we assumee that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
  //makes sure this block of code  is only executed again
  //after a new motion sequence has been detected
  lockLow = true;
}
Serial.print(0);//triggers off on BI
}

}

I was very happy with this and feeling pretty professional about it too. However, moving on to modifying this code to work on and with the Yun has completely stumped me. Following is my current attempt.

First the code for the Uno:

//second attempt at making a PIR activate onboard LED as well as BI trigger
//THIS SKETCH IS UNSUCCESSFUL WITH TRIGGERING INDOOR CAMERA
//USE ARDUINO UNO R3 WITH CHINESE ADJUSTABLE PIR ON COM3 AND SERIAL BIT 2 IN CAMERA OPTIONS
//5-11-15 added network code

//libaries
#include <SPI.h>
#include <Ethernet.h>

//vars
//ethernet stuff
byte mac[] = {0x90, 0xA2, 0xDE, 0x0E, 0xC0, 0x0E};
IPAddress server1(192,168,10,204);
IPAddress ip(192,168,10,205);
EthernetClient client;

//onboard PIR sensor stuff
int calibrationTime = 60;
int ledPin = 9; //led pin number for onboard PIR activity
int ledPin2 = 8; //led pin number for server connectivity
int pirPin1 = 2;//digital pin connected to primary PIR out

long unsigned int lowIn; //time the sensor outputs a low impulse
long unsigned int pause = 5000;//amount of millis the sensor has to be  low before we assume all motion has stopped

boolean lockLow = true;
boolean takeLowTime;

void setup() {
 pinMode(pirPin1,INPUT);
 pinMode(ledPin,OUTPUT);
 pinMode(ledPin2,OUTPUT);
 
 //sensor calibration
 for(int i = 0; i<calibrationTime; i++){
   digitalWrite(ledPin,HIGH);
   delay(50);
   digitalWrite(ledPin,LOW);
   delay(950);  //flashes LED until calibration over
}
Ethernet.begin(mac,ip);
Serial.begin(9600);
Serial.print(0);
if (client.connect(server1,8151)){
  Serial.println("connected");
  Serial.print(0);
}
}

void loop() {
//Primary PIR sensor
   if(digitalRead(pirPin1) == HIGH){
     digitalWrite(ledPin,HIGH); //turn on the LED when motion sensed
     if(lockLow){
     //makes sure we wait for transition to LOW before any further output is made
     lockLow = false;
   }
   takeLowTime = true;
   Serial.print(2); //send ASCii signal to BI to start recording
   }
   if(digitalRead(pirPin1) == LOW){
     digitalWrite(ledPin, LOW);//LED turns off or stays off
     if(takeLowTime){
     lowIn = millis(); //save the time of the transtion high->low
     takeLowTime = false;
   }
   //if the sensor is low for more than the given pause,
   //we assumee that no more motion is going to happen
   if(!lockLow && millis() - lowIn > pause){
     //makes sure this block of code  is only executed again
     //after a new motion sequence has been detected
     lockLow = true;
   }
   Serial.print(0);
   }
   if(client.connect(server1, 8151)){
     client.println();
   }
   delay(100);
   if(client.available())
   {
     char c = client.read();
     if(int(c) == 1)
     {
       Serial.print(3);
     }

     delay(100);
     Serial.print(0);
   }
   client.stop();


}

And now the code for the Yun:

//Libraries
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

//vars
YunServer server(8151);
int calibrationTime = 60;
int ledPin = 13; //led pin number
int pirPin1 = 2; //digital pin connected to primary PIR output

long unsigned int lowIn;//time thee sensor outputs a low impulse
long unsigned int pause = 5000;//amonut of millis the sensor has to be low before we assume all motion has stopped

boolean lockLow = true;
boolean takeLowTime;
boolean primarysensor;

void setup() {
Serial.begin(9600);
pinMode(pirPin1, INPUT);
pinMode(ledPin, OUTPUT);

//sensor calibration
for(int i = 0; i<calibrationTime; i++){
  digitalWrite(ledPin, HIGH);
  delay(30);
  digitalWrite(ledPin, LOW);
  delay(970); //flashes LED until calibration over
}
Bridge.begin();
server.listenOnLocalhost();
server.begin();


}

void loop() {
YunClient client = server.accept();//create a named instance of Yunclient to get any clients coming from the server
//primary PIR sensor
if(digitalRead(pirPin1) == HIGH){
  digitalWrite(ledPin,HIGH);//turn on the LED when motion sensed
  if(lockLow){
    //makes sure we wait for transition to LOW before any further output
    lockLow = false;
  }
  takeLowTime = true;
  primarysensor = true;
}
if(digitalRead(pirPin1) == LOW){
  digitalWrite(ledPin,LOW);//LED turns off or stays off
  if(takeLowTime){
    lowIn = millis(); //savve the time of the transition hight->low
    takeLowTime = false;
  }
  //if the sensor is low for more than the given pause,
  //we assume that no more motion is going to happen
  if(!lockLow && millis() - lowIn > pause){
    //makes sure this block of code is only executed again
    //after a new motion sequence has been detected
    lockLow = true;
  }
  primarysensor = false;
}

if (client){
  boolean currentLineIsBlank = true;
  while(client.connected()){
    if(client.available()){
      char c = client.read();
      if(c == '\n' && currentLineIsBlank){
      if(primarysensor){
        client.print(1);
      }
      else{
        client.print(0);
      }
      break;
    }
    if(c == '\n'){
      currentLineIsBlank = false;
    }
  }
}
delay(10);
client.stop();
}
}

The Uno doesn't seem to be connecting to the Yun, much less able to read anything from it. Any detailed help or constructive criticism is highly welcome. FYI I have the correct IP in the code for the Yun and it is statically routed.

IPCamGuy111:
And now the code for the Yun:

Bridge.begin();

server.listenOnLocalhost();
server.begin();

I don't have access to my Yuns or sample code at the moment, but the first thing I notice is this initialization code in setup(). I think you will have to change the listen command to server.[b]no[/b]ListenOnLocalhost();

listenOnLocalHost() waits for connections from the local Linux processor, while noListenOnLocalHost() waits for connections from the network at large (or at least I think that's how it works.)

It looks lime you are trying to establish and close the connection on every loop iteration - this adds a lot of overhead and can make things unreliable. Is there a reason you need to do this? I would think you would want to keep the connection open as long as possible, and only try to initiate/accept a connection when no connection is already active.

Hello ShapeShifter,

Thanks for taking the time to analyze my code and give me your two cents. I looked up the definitions for nolistenonlocalhost vs listenonlocal host and the definitions leave me not understanding. So I will give that a try.

I have played around with putting the connection code on the Uno in setup() as opposed to loop() which is why it shows up twice (I forgot to delete it for a bit there) but as nothing was working I wasn't sure what I was doing wrong. Since I posted this, I added "Serial.write("connected")" in the if(client.connect(server1, 8151)){ loop and it sits there and prints "connected" on the serial monitor, however it does not print a 3 when I wave my hand in front of the sensor on the Yun. So that tells me that the Uno is actually connecting to the Yun, but is not sending the blank line command or the yun is not accepting it and client.printing back to the Uno.

So maybe the key actually is to use nolistenonlocalhost. I will give it a try and get back to you soon. In the mean time, any other suggestions are appreciated.

I'm afraid changing to nolistenonlocalhost did not change anything.

So for the purposes of making the code easier to see and therefore trouble shoot I have deleted everything that doesn't have to do with pulling a value from the Yun and displaying it in the serial monitor. I added a couple lines to the Uno to state in the serial monitor when it is connecting, connected, failed to connect, or disconnected. What happens is that it connects, then nothing happens after that. Just to make sure that the Uno wasn't freezing up, I unplug the Yun and I get "disconnecting..." displayed on the serial monitor. So it seems like I am doing something right, yet something wrong. I pulled some of this code from examples on arduino.cc

Uno:

//vars
//ethernet stuff
byte mac[] = {0x90, 0xA2, 0xDE, 0x0E, 0xC0, 0x0E};
IPAddress server1(192,168,10,204);
IPAddress ip(192,168,10,205);
EthernetClient client;

//onboard PIR sensor stuff

int ledPin = 9; //led pin number for onboard PIR activity

void setup() {

   pinMode(ledPin,OUTPUT);
   digitalWrite(ledPin,LOW);

  Ethernet.begin(mac,ip);
  Serial.begin(9600);
  Serial.println("connecting...");
  if(client.connect(server1, 8151)){
     Serial.print("connected");
     digitalWrite(ledPin,HIGH);
     }
     else{
       Serial.println("connection failed...");
     }
  delay(100);

  }


void loop() {

     if(client.available())
     {
       digitalWrite(ledPin,HIGH);
       char c = client.read();
       Serial.print(c);
     }
     if(!client.connected()){
       Serial.println();
       Serial.println("disconnecting...");
       client.stop();
       for(;;)
       ;
     }


}

Yun:

//Libraries
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

//vars
YunServer server(8151);
int calibrationTime = 60;
int ledPin = 13; //led pin number
int pirPin1 = 2; //digital pin connected to primary PIR output


void setup() {
  Serial.begin(9600);
  pinMode(pirPin1, INPUT);
  pinMode(ledPin, OUTPUT);
  
  digitalWrite(ledPin, LOW);
  Bridge.begin();
  server.noListenOnLocalhost();
  server.begin();
  digitalWrite(ledPin,HIGH);


}

void loop() {

  YunClient client = server.accept();//create a named instance of Yunclient to get any clients coming from the server
  if (client){

    while(client.connected()){
      if(client.available()){
        if(digitalRead(pirPin1) ==HIGH){
        client.print(1);
      }
      else{
        client.print(2);
      }

  delay(10);
  client.stop();
}
}
}
}

Ok, I have something working but it is inefficient. I simplified the files a bit more, then in the Uno's code I started adding serial.println() with characters (seen as commented out in code below) after certain steps in the code. I found that the Uno had no trouble connecting to the Yun. However, at the if(client.accept() part of the loop it broke down. On a whim I started to add more time to the delay that is just before it. As I added more time, it started to work, and the more time I gave it the more reliably it worked. Unfortunately I had to add a whole 5 seconds to each loop to make it reliable. I did activate a camera with it which is great but in a security situation sampling every 5 seconds is just not good enough.

I attempted to move the if(client.connect()) part of the code to the setup part of the file, but nothing worked after I did that. I know that reconnecting after every loop is not such a good idea but I am not sure how to get it to work otherwise.

Uno:

 #include <SPI.h>
 #include <Ethernet.h>
 byte mac[] = { 0x90, 0xA2, 0xDE, 0x0E, 0xC0, 0x0E };
 IPAddress server1(192,168,10,204);
 
int ledPin = 9;

 IPAddress ip(192,168,10,205);
 EthernetClient client;

void setup() {
 pinMode(ledPin, OUTPUT);
 Ethernet.begin(mac, ip);
 Serial.begin(9600); 

 Serial.println(0);
 }

 void loop(){ 
 if(client.connect(server1,5555)){
 client.println();
// Serial.println("ok");
 }
 delay(5000);
 if (client.available()) 
 {
//  Serial.println("yayayayay");
 char c = client.read();
 if(int(c) == 49) 
 {
 Serial.print(2);
 digitalWrite(ledPin, HIGH);
 }
 else{
   Serial.print(0);
   digitalWrite(ledPin,LOW);
 }
 delay(100); 
 }
 client.stop();
//Serial.println("loop");
 }

Yun:

#include <Bridge.h>
#include <SPI.h>
#include <YunServer.h>
#include <YunClient.h>


 YunServer server(5555);

 void setup()
 {
 Bridge.begin();
 server.begin();
 }
 void loop()
 {
 YunClient client = server.accept();

 {
 if(client){
 boolean currentLineIsBlank = true;
 while (client.connected()){
 if(client.available()){
 char c = client.read();

 if(c == '\n' && currentLineIsBlank) {

 if (digitalRead(2) == 0) 
 {client.print(0);}
 else
 {client.print(1);}


 break;
 }
 if (c == '\n'){
 currentLineIsBlank = false;
 }
 }
 }
 delay(10);
 client.stop();
 }
 }



 }

Try this code without the delay. It waits the requested data before doing another request and it connect only when there is no connection. Note that if there is some delay in the communication it is probably due to network services delays.

If you want to make a more real time system you can continuously check the sensor on the Yun and save the alert on a variable/flag. Then, on the Uno, request the value of that variable to check if there is an alert or not. In this way you can sense motion even if the Uno is not updating the value.

Here the modified code for the Uno:

 #include <SPI.h>
 #include <Ethernet.h>
 byte mac[] = { 0x90, 0xA2, 0xDE, 0x0E, 0xC0, 0x0E };
 IPAddress server1(192,168,10,204);
 
int ledPin = 9;
int waitingForData = 0;

 IPAddress ip(192,168,10,205);
 EthernetClient client;

void setup() {
 pinMode(ledPin, OUTPUT);
 Ethernet.begin(mac, ip);
 Serial.begin(9600); 

 Serial.println(0);
 }

 void loop(){ 
 if (!client.connected()) //Reconnect only if you are disconnected
 {
   client.stop();
   if(client.connect(server1,5555)){
   //client.println();
   // Serial.println("ok");
   }
 } else {
   if(!waitingForData) { //if you are waiting for data from yun, don't overload it with another request.
   client.println();
   waitingForData = 1;
  }
 }
 }
 //delay(5000);
 if (client.available()) 
 {
//  Serial.println("yayayayay");
 waitingForData = 0;
 char c = client.read();
 if(int(c) == 49) 
 {
 Serial.print(2);
 digitalWrite(ledPin, HIGH);
 }
 else{
   Serial.print(0);
   digitalWrite(ledPin,LOW);
 }
 delay(100); 
 }
// client.stop();  dont close connection
//Serial.println("loop");
 }

Thanks, I will give this a try after work this evening.

Angelo9999,

This is VERY close. It works pretty good, but sometimes it takes a few seconds to register an activated sensor on the Uno. The faster it is the better. Do you think we can make it any faster? Or could it be the nature of using a wifi connected Yun? Would be troublesome running a LAN cable out there but if it works better...

BTW I really appreciate the help here, you have given me a big leap forward.

Guys,

I still need some help with this. The most recent code for the yun works, but it still disconnects the client after every loop. That is why it is still taking too long (but works). I have tried and tried and tried to understand how to run a server/client relationship without disconnecting them but I just don't understand it and my code keeps failing. There are no examples of code like this that I can find.

Please help me out here, this is the only thing really holding me back from finishing up this project.

Thanks!

This is a simple sketch that starts a server and listens for incoming client connections.

It starts by making an initial server.accept() call in setup(), primarily to get get a valid object to use on later client.connected() calls, I don't expect to actually make a successful connection in setup(). Then, in the loop, it checks to see if there is a client connection.

Inside loop(), if there is a client connection, a clientActive flag is checked to see if this a a new connection: if a new connection, the LED is turned on/ You could do any other new connection processing at this point (this would be a good place to print out a sign-on banner if it were expected to be a user terminal connection.) Then, as long as incoming characters are available on the client, they are echoed to the serial port, and finally a message is sent to the client on the other end. This is where you would put you code to process incoming data.

If there is no client connection inside loop(), the clientActive flag is again checked to see if there used to be a connection the last time through. If so, the client socket is closed by calling client.stop(), and the LED is set low. Here you could add any code you need to handle the client disconnecting. Finally, if there is no active client connection, a server.accept() call is made to try and establish another connection. The results of that won't actually be checked until the top of the loop() function the next time around.

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

#define PORT 255
YunServer server(PORT);
YunClient client;

static boolean clientActive = false;

int clientCount;

void setup()
{
  clientCount = 0;
  
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  // Bridge startup
  Bridge.begin();
  digitalWrite(13, LOW);

  server.noListenOnLocalhost();
  server.begin();
  client = server.accept();
}



void loop()
{
  if (client.connected())
  {
    if (!clientActive)
    {
      clientCount++;
      digitalWrite(13, HIGH);
///      Bridge.put("count", String(clientCount));      
    }
      
    clientActive = true;
    
    // Have a connection. Read and echo any input to the serial port
    while (client.available())
      client.read();
    
    // Send to the client
    client.println("Hello Client!");
  }
  else // No connection, try to accept one.
  {
    if (clientActive)
    {
      client.stop();
      digitalWrite(13, LOW);
    }
      
    clientActive = false;
    
    client = server.accept();
  }
}

I think the important points are to have a flag to track the last known client state so that you can detect new connections being made, and old connections being closed. Detecting new connections isn't necessarily critical, but I think detecting closed connections is: you want to make sure to close() the old client connection, or you will have too many defunct sockets laying around and you won't be able to accept more than 255 connections.

ShapeShifter,

Thanks greatly for the response. I copy/pasted your code into the IDE and it compiles and uploads. My slightly tweaked version of Angelo9999's code on the Uno connects to it and stays connected to it humming away looking for a 49 (which would be a 1 in the Yun code right?), if it finds one it prints a 2 to the serial port on the blueiris PC which would then trip an alarm and start a camera recording. Otherwise is prints a 0 to the serial.

So my understanding of your code is that I need to put my PIR sensor poll where you have the line "client.println("Hello Client!")" in your code? When I do so the reaction on the Uno end is extremely slow. Here is the code I tried to insert into that area:

if (digitalRead(2) == 0)
{client.print(0);}
else
{client.print(1);}

It is pretty simple, and therefore reliable. The PIR has a built in time delay once activated that is adjustable via potentiometer so I don't have to worry about that in code.

Am I trying to insert this code in the wrong area?

My only question is why are you constantly sending the state when it's idle? You are sending a constant stream of redundant data, and that could be slowing down the link. This is a TCP socket, which has guaranteed delivery: every byte sent will be received, and in the correct order. There is a lot of overhead to that.

I would add a flag that tracks the last known state of the sensor, and only sends the 0 or 1 when the state changes. That will reduce a lot of overhead.

Well I have to admit I am very new to programming and I am doing the best I can to figure things out. That means anything outside of a simple loop is hard for me to understand. I certainly have never dealt with TCP/IP connections before. Therefore I have a tough time trying to decipher even the code example you wrote. So I had absolutely no idea it had a high overhead, much less why it is so slow. The way I understand it should work is the Uno constantly checks the state of the Yun, therefore the Yun should only send a byte when requested. And that byte should change dependent on the PIR sensor's output. I will give it some thought throughout the day today while at work and see if I can't figure it out, but I don't have high hopes I will.

Networking connections can be fast, but when you're sending one character at a time, it can bog down. You send a character, and that gets bundled up into a packet that is sent over the network. Then the computer that receives that packet checks that it arrived properly, and if so it sends a packet ack acknowledging it. If it doesn't come through properly, it sends a message indicating what was last received properly, and the Tun will retransmit the data until it is received properly. (There are more details I'm skipping over, but that's the general idea, I don't want to make it too complicated. ;))

If sending over the serial port, where you don't have all the overhead (and slower speeds) I would do as your doing: since there is no guaranteed delivery, and no retransmission of bad data (unless you write a protocol and do it yourself) I would use the redundancy of sending the same data over and over to help prevent problems with lost data. But I wouldn't do that with the network connection.

What I'm proposing is something similar to the clientActive flag in my sample code. Create a new pirActive flag and initialize it false. Them in the loop() function, check the sensor do something like this (simple pseudo code, not meant to compile):

if (PIR sensor is active)
{
  // sensor is now active, was it active before?
  if (!pirActive)
  {
    // not previously active, it just became active now
    Send the PIR active character over the client connection
  }

  // remember the active state of the sensor. 
  pirActive = true
}
Else
{
  // sensor is not active, was it active before?
  If (pirActive)
  {
    // previously active, it just became inactive now
    Send the PIR inactive character over the client connection
  }

  // remember the active state of the sensor. 
  pirActive = false
}

Feel free to ask any questions on this or the other code, it's a great way to learn, and I'm happy to help.

So this code works. Awesome! Thanks for your help. Now, I was intending on attaching two PIR sensors to the Yun and sending a different bit for each one (where 0 being the common for no active PIRs) and having blueiris perform two different tasks dependent on which PIR is activated. One PIR would have to be handled more importantly than the other. This should be theoretically possible correct? I am not going to tackle this at the moment. I need to put together a box and run power out to it. But the idea is that the camera is at the inward most point of the carport and points out. I am going to put the sensors on the opposite end, one pointing in and one pointing out. The one pointing in will be the "screamer" as I call it. So if someone goes in, our phones/inside alarm scream bloody murder. The one pointing outward triggers blueiris to just record general motion beyond the carport, but no alarm.

Anyways, I am ecstatic with the progress I have made thanks to the help from the forum. Here is the final Yun code:

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

#define PORT 255
YunServer server(PORT);
YunClient client;

static boolean clientActive = false;
static boolean pirActive = false;

int clientCount;

void setup()
{
  clientCount = 0;
  
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  // Bridge startup
  Bridge.begin();
  digitalWrite(13, LOW);

  server.noListenOnLocalhost();
  server.begin();
  client = server.accept();
}



void loop()
{
  if (client.connected())
  {
    if (!clientActive)
    {
      clientCount++;
      digitalWrite(13, HIGH);
///      Bridge.put("count", String(clientCount));      
    }
      
    clientActive = true;
    
    // Have a connection. Read and echo any input to the serial port
    while (client.available())
      client.read();
    
    // Send to the client
    if (digitalRead (2) != 0) {
      if(!pirActive){
        client.print(1);
      }
      pirActive = true;
    }
    else {
      if(pirActive) {
        client.print(0);
      }
      pirActive = false;
    }
  }
  else // No connection, try to accept one.
  {
    if (clientActive)
    {
      client.stop();
      digitalWrite(13, LOW);
    }
      
    clientActive = false;
    
    client = server.accept();
  }
}

I will come back at a later time with the final, polished product and post it as an example. I will probably go over to the IP cam forums and post it there too with a reference to this forum. A lot of other people search for blueiris I/O activation, or arduino activation on google and they get steered towards the IP cam forums (and I just want to be helpful). Thanks to your guys' help, I believe I have the most useful code for the application that has been written thus far.

Yes, it can easily be expanded to a second (or more) PIR sensor inputs. There are a few ways to do it.

The simplest way is to create a new flag variable for the second sensor, and then duplicate your entire if/then/else construct substituting the second input and second flag variable, and sending a different on/off pair of values. In this way, the values sent are completely independent of each other: one sensor sends two values, like 0 and 1; while the second sends two other values, like 2 and 3, or A and B, or whatever.

To do what you want where you send a value of 0, 1, 2, or 3 where each sensor has a bit in the value, it will take a little more work and a slightly different organization. One way to do it is to track each sensor's state, build a combined value with a bit for each sensor, and then look for changes in that value and send it if it's different. This pseudocode example only needs a byte flag to track the last known bit-mapped status value called lastStatus, and doesn't need individual flags for each sensor (they are essentially bits in the status value):

byte status = 0;
// If the first sensor is active, set the first bit in the status value.
if (PIR sensor 1 is active)
  status = status + 1;

// If the second sensor is active, set the second bit in the status value.
if (PIR sensor 2 is active)
  status = status + 2;

// Now, check if the sensor value has changed, if so, send an update.
if (status != lastStatus)
  client.print(status, DEC);

// Finally, remember the last known status for next time.
lastStatus = status;

This will send these status values:
0 - no sensors are active
1 - the first sensor is active, the second is not
2 - the first sensor is not active, the second one is
3 - both sensors are active

In case you expand this into more than two sensors, keep in mind that the value being added into status is the value of the corresponding bit, not the bit position number. So the third sensor would add in a value of 4, and the fourth would be 8. But keep in mind that once you get to a fourth bit, that can't always be represented by a dingle decimal digit, so your protocol will have to get a little more complicated, like adding commas or newlines between updates so you know which set of digits to combine together when reading it on the other end.

Giving a bit of an update. Got delayed by some other stuff. Over the weekend I built my sensor unit complete with drop down brackets for the PIRs (I know, they are out in the open, but this is California, plus I paid like $12 for 10 of them so w/e). I had to run power out there. I didn't want to have to deal with keeping 120 VAC to code so I bought a server power supply from WeirdStuff for $10 and ran 12 vdc out there with 22 gauge shielded two conductor from homedepot and a 10 amp fuse. By the time it got there, of course, it was more like 10 volts. I found a cheap car USB phone charger that happened to be a nice switching power supply with two usb ports on it at 2.1 amps each ($8 at the gas station XD) which then drops the voltage to 5 vdc. This worked absolutely GREAT with only a couple of logic issues to work out in the code. No false alarms for 24 hours, but then my Ethernet shield on the Uno took a dump. Waiting on a replacement. timbo-0012 on ebay is a great seller btw, sending me a new one no questions asked with expedited shipping.

When I get that logic worked out I will post the code.

If you are curious as to why I am doing this well...watch this video please:

That is but one example.

EDIT: sorry my files are too big to attach. Please see direct links below as I am too lazy to resize them: