#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xFA, 0xCA, 0xE5, 0x4C, 0xE7, 0xE6 }; // CHANGE THIS
IPAddress ip(192, 168, 1, 157); // IP address, may need to change depending on network
byte subnet[] = { 255, 255, 255, 0 }; // subnet address, may need to change depending on network
EthernetServer server(80); // Port 80 is HTTP port for POST commands from
Blue Iris.
char new_state[512];
EthernetClient client;
char BIserver[] = "192.168.1.12"; // IP Adres of Blue Iris Server. // CHANGE THIS
char user[]= "admin";
char pass[]= "VeniseLab";
String stringOne = "Camera";
long prevmill = 0;
long interval = 500; //Time between check for checking Digital Inputs
long prevmill2 = 0;
//long interval2 = 10000; //Time to zero triggers from arduino to Blue Iris, this time will be a form of re-trigger time.
long interval2 = 1000; //Time to zero triggers from arduino to Blue Iris, this time will be a form of re-trigger time.
int DI03 =0;
int BlueIrisIN3=0;
int tmp03 =0;
const int buttonPin = 3; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
#define RELAY1 7
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(4, OUTPUT);
digitalWrite(4, HIGH); // disable the SD card by switching pin 4 high
Ethernet.begin(mac, ip, subnet); // initialize Ethernet device
server.begin();
Serial.begin(9600); //Used for debuging
pinMode(3, INPUT);
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
pinMode(8, OUTPUT);
digitalWrite(8, HIGH);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(RELAY1, OUTPUT);
}
void loop()
{
unsigned long curmil = millis();
if (curmil - prevmill > interval) { //Checking everything every xxx milisecond.
prevmill = curmil;
digital_read();
HTTP_write();
}
unsigned long curmil2 = millis();
if (curmil2 - prevmill2 > interval2) { //Checking everything every xxx milisecond.
prevmill2 = curmil2;
tmp03=0;
}
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
int i = 0;
int head = 1;
int body = 0;
while(client.available()) {
char c = client.read();
if (c == '\n') {
if ( i <= 2 ) {
// an http request ends with a blank line
sendPage(client);
if ( head == 1 ) {
body = 1;
head = 0;
}
}
i = -1;
}
if ( body == 1 ) {
new_state
= c;
}
i++;
new_state = '\0';
}
i = 0;
}
writedigital();
}
}
void writedigital(){
if ( strncmp( new_state, "Out07=On", 8) == 0 ) {
digitalWrite(7, HIGH);
}
else if ( strncmp( new_state, "Out07=Off", 9) == 0 ) {
digitalWrite(7,LOW );
}
}
void sendPage(EthernetClient client)
{
client.println("HTTP/1.0 200 OK\Content-Type: text/html\n\n<html>\n<head>");
client.stop();
}
void digital_read() {
int input=0;
input = digitalRead(3);
if (input == LOW) {
DI03 = 0;
}
else {
DI03 = 1;
digitalWrite(ledPin, HIGH);
digitalWrite(RELAY1,HIGH); // Turns ON Relays 1
//delay(100); // Wait 1 seconds
//digitalWrite(RELAY1,LOW); // Turns Relay Off
}
}
void HTTP_write(){
BlueIrisIN3 = DI03;
if (BlueIrisIN3 == 1 && tmp03 == 0) {
// if (BlueIrisIN3 == 1 ) {
stringOne = "Cam3";
Serial.print(BlueIrisIN3)
Serial.print(stringOne)
triggerBI();
tmp03=1;
}
}
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
void triggerBI(){ // sending the trigger to Blue Iris web-server
//EthernetClient client;
EthernetClient client = server.available();
Serial.print("Alive1") ;
if (client.connect(BIserver,80))
{
Serial.print("Alive2 ") ;
client.print( "GET /admin?camera=");
client.print(stringOne);
client.print( "&trigger&user=");
client.print(user);
client.print( "&pw=");
client.print(pass);
client.println( " HTTP/1.1");
client.print( "Host: " );
client.println(BIserver);
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
}
}