Pages: [1]   Go Down
Author Topic: My Domotic Home  (Read 3435 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

Been a while since I posted but I thought I would throw this up. I started off last night with Marque's excellent little script to allow for android, then built a little site for iPad access. As I am in a rented house this is all done with modified GPO's and old wireless double plug housings (see pic). Anyhoo, Once I move into my own house and tear the walls out the wiring will be a bit neater, but until then...

I've thrown the site mockup online @ www.reanimate.com.au/domotic/index.html (will need to sexify this with something nice and pretty)

Finally on the scheduling page I need to figure out how to get that working with php, cron and a flatfile, record the time and relay down and then open the url when the time is now. But a lack of php is causing a few headaches.

Code:
/*********************** Marque's Arduino Controller Example ***********************/
/***********************  for questions: marque.l@gmail.com  ***********************/
/*
In the android app settingsscreen you can set up you IP and port.
For this example you need to call prefix 1 "B" and prefix 2 "C".

*/
#include <Ethernet.h>
#include <HTTPClient.h>
#include <SPI.h>

int RecievedString;
int valueB;
int valueC;
String readString = String(20);

int rm2light1 = 4;
int fishlight = 2;
int fishpump = 3;


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server(80);   // port to listen on
EthernetClient client;

char content_main_top[] = "<body bgcolor=black><font color=white><center>";
char S1[] = "Room 2, Light 1 is on " ;
char S2[] = "Room 2, Light 1 is off" ;
char S3[] = "Fish Light is on";
char S4[] = "Fish Light is off";
char S5[] = "Fish Pump is on";
char S6[] = "Fish Pump is off";
char S404[] = "Not Found";

/************************** Setup **********************/
void setup()
{
  Serial.begin(9600);
  Serial.println("Getting IP......");
  Ethernet.begin(mac);
  Serial.print("My IP address: ");
  Ethernet.localIP().printTo(Serial);
  Serial.println();
  Serial.print("Gateway IP address is ");
  Ethernet.gatewayIP().printTo(Serial);
  Serial.println();
  Serial.print("DNS IP address is ");
  Ethernet.dnsServerIP().printTo(Serial);
  Serial.println();
  pinMode(rm2light1, OUTPUT);
  pinMode(fishlight, OUTPUT);
  pinMode(fishpump, OUTPUT);
  Serial.print("Initialising rm2light1 ");
  Serial.print("Initialising fishlight ");
  Serial.print("Initialising fishpump ");
  Serial.println();
  digitalWrite(rm2light1, LOW);
  digitalWrite(fishlight, LOW);
  digitalWrite(fishpump, LOW);
}
void loop()
{

checkclient();
}

void checkclient()
{
  EthernetClient client = server.available();
  if (client)  
  {
    boolean sentHeader = false;
    while (client.connected())
    {
      if (client.available())
      {
        if(!sentHeader){
        client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          sentHeader = true;
        }
         char c = client.read();
         if (readString.length() < 20)
         Serial.print(c);
         {readString.concat(c);}
         if (c == 'H')
         {
           Serial.println();
           int Is = readString.indexOf("/");
           int Iq = readString.indexOf("?");
           int Ib = readString.indexOf("b");
           int Ic = readString.indexOf("c");
           if(readString.indexOf("?") > 1)
           {
             if (Ib == (Iq+1))
             {
               char carray[5];
               readString.toCharArray( carray,5,(Ib+1));
               Serial.println(carray);
                valueB = atof(carray);
               Serial.print("B is now: ");
               Serial.println(valueB);
               client.print (content_main_top);
               client.print("B is now: ");
               client.print(valueB);
             }
            else if (Ic == (Iq+1))
             {
               char carray[5];
               readString.toCharArray( carray,5,(Ic+1));
               Serial.println(carray);
                valueC = atof(carray);
               Serial.print("C is now: ");
               Serial.println(valueC);
               client.print (content_main_top);
               client.print("C is now: ");
               client.print(valueC);
             }
             else
             {
               char carray[2];
               readString.toCharArray( carray,2,(Iq+1));
               RecievedString = atoi(carray);
               switch (RecievedString) {
               case 1: action(1, client);digitalWrite(rm2light1, HIGH);break;
               case 2: action(2, client);digitalWrite(rm2light1, LOW);break;
               case 3: action(3, client);digitalWrite(fishlight, HIGH);break;
               case 4: action(4, client);digitalWrite(fishlight, LOW);break;
               case 5: action(5, client);digitalWrite(fishpump, HIGH);break;
               case 6: action(6, client);digitalWrite(fishpump, LOW);break;
               default: action(404, client);
               }
             }
          delay(1);
             client.stop();
             readString="";
             client.read(); client.read();
           }
         if (Iq < 0)
         {
         action(404, client);
         delay(1);
         client.stop();
         readString="";
         client.read(); client.read();
         }
          delay(1);
         client.stop();
         readString="";
         client.read(); client.read();
       }
     }
   }
 }
}

void action(int x, EthernetClient client)
{  
  if (x == 1)
  {client.print (content_main_top);
   client.println(S1);
   Serial.println(S1);
  }
if (x == 2)
  {client.print (content_main_top);
   client.println(S2);
   Serial.println(S2);
  }
if (x == 3)
  {client.print (content_main_top);
   client.println(S3);
   Serial.println(S3);
  }
if (x == 4)
  {client.print (content_main_top);
   client.println(S4);
   Serial.println(S4);
  }
if (x == 5)
  {client.print (content_main_top);
   client.println(S5);
   Serial.println(S5);
  }
if (x == 6)
  {client.print (content_main_top);
   client.println(S6);
   Serial.println(S6);
  }
if (x == 404)
  {client.print (content_main_top);
   client.println(S404);
   Serial.println(S404);
  }
x=0;
}



* 20121112_175230.jpg (61.09 KB, 490x368 - viewed 141 times.)

* 20121112_175240.jpg (73.18 KB, 490x368 - viewed 113 times.)

* 20121112_175513.jpg (91.3 KB, 490x368 - viewed 127 times.)
« Last Edit: November 12, 2012, 05:55:43 am by SamuelFreeman » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks cool, I tried something like this, used basic html programing, looks like you can do a lot more cooler stuff with php and java. smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Cool piece of work Samuel!

I am a deep green newbie  smiley-mr-green and would like some guidance on the project I am trying to build...just like yours but stopping at controlling relays via an Ethernet attached arduino.  Is there anyway I can ask you some questions on a private mail address?

Thanks for helpin!
Aldo
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure mate, sales@reanimate.com.au
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi samuel tell me is ur this web is accessable from any network means can i control my devices over the world not remaining on the same network as of the arduino system ??
Logged

Pages: [1]   Go Up
Jump to: