Pages: [1]   Go Down
Author Topic: Best approach for uni project: Web based Climate and Lighting Control  (Read 391 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good day,

i have the above project and need advice if it can be completed using arduino as webserver?
trying to keep simple as possible, so do i need to display webpage on an SD card or can i use normally?
currently i have a Mega, Ethernet shield and have done some examples with IP & mac address which is new to me (like everything else  smiley-eek-blue).
i have added a picture if the HTML in my browser, which will basically need to look similar on web server page, if its a good way to go.

following are criteria for the 10 rooms with 1 x light and 1 x air-conditioner.

1. The air conditioner of every labs needs to be controlled using the existing IR control signals, not with remote.<i already have recorded the IR signals using IR dump>
2. Every lab’s temperature and lighting condition should be displayed changeable and displayed on a single web page.
3. All the air conditioners and lighting on and off times should be programmable.
4. All air conditioners and lights should be able to switch off with a single button.
5. The system should be able to read the status of an occupancy/motion sensor in each lab.
  -If no occupancy was detected in a “predetermined time” hour the lighting and air conditioning should be switched off for that specific room.
  -This predetermined time should be variable. <e.g to enter "30" for countdown timer and switch off at 0 >
  -If occupancy is detected the light and air conditioning should be switched on again.

please help..


* Project page.jpg (246.34 KB, 828x899 - viewed 44 times.)
Logged

0
Offline Offline
Tesla Member
***
Karma: 118
Posts: 8962
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

a tutorial that might be of interest.

http://startingelectronics.com/tutorials/arduino/ethernet-shield-web-server-tutorial/
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

thank you Zoomkat,

i completed up to Part 6: Reading a Switch.
after struggling long now again i need help to display the temperature on on the webserver when reading on arduino using 18B20 Temerature Sensor (Arduino Compatible) (SKU: DFR0024) code with hashes ################.

How do i display temperature back onto the web page? added a picture of my result indicating "temperature" instead of the actual temp value i want to display?

PS i the following to get the temp: GetSwitchState1(client);// i added this line************************

Code:

/*--------------------------------------------------------------
  Program:      eth_websrv_switch

  Description:  Arduino web server shows the state of a switch
                on a web page. Does not use the SD card.
 
  Hardware:     Arduino Uno and official Arduino Ethernet
                shield. Should work with other Arduinos and
                compatible Ethernet shields.
               
  Software:     Developed using Arduino 1.0.3 software
                Should be compatible with Arduino 1.0 +
 
  References:   - WebServer example by David A. Mellis and
                  modified by Tom Igoe
                - Ethernet library documentation:
                  http://arduino.cc/en/Reference/Ethernet

  Date:         12 January 2013
 
  Author:       W.A. Smith, http://startingelectronics.com
--------------------------------------------------------------*/
        #include <OneWire.h>  //##############################
       
#include <SPI.h>
#include <Ethernet.h>

        int DS18S20_Pin = 21; //DS18S20 Signal pin on digital 2 //##############################
        //Temperature chip i/o//##############################
        OneWire ds(DS18S20_Pin);  // on digital pin 21//##############################

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(169, 254, 126, 222); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

void setup()
{
    Ethernet.begin(mac, ip);    // initialize Ethernet device
    server.begin();             // start to listen for clients
    pinMode(3, INPUT);  // input pin for switch
            Serial.begin(9600);//##############################
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connnection: close");
                    client.println();
                    // send web page
                    client.println("<!DOCTYPE html>");
                    client.println("<html>");
                    client.println("<head>");
                    client.println("<title>Arduino Read Switch State</title>");
                    client.println("<meta http-equiv=\"refresh\" content=\"1\">");
                    client.println("</head>");
                    client.println("<body>");
                    client.println("<h1>Switch</h1>");
                    client.println("<p>State of switch is:</p>");
                    GetSwitchState(client);
                    GetSwitchState1(client);// i added this line************************
                    client.println("</body>");
                    client.println("</html>");
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                }
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)

      float temperature = getTemp();//##############################
      Serial.println(temperature);//##############################
      delay(100); //just here to slow down the output so it is easier to read//##############################
   

}

void GetSwitchState1(EthernetClient cl)// i added this to return to the "web page" ************************
{           cl.println("<p>temperature</p>");
    }


void GetSwitchState(EthernetClient cl)
{
    if (digitalRead(3)) {
        cl.println("<p>ON</p>");
    }
    else {
        cl.println("<p>OFF</p>");
    }
}

float getTemp(){//##############################
  //returns the temperature from one DS18S20 in DEG Celsius
 
  byte data[12];//##############################
  byte addr[8];//##############################
 
  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();//##############################
      return -1000;//##############################
  }
 
  if ( OneWire::crc8( addr, 7) != addr[7]) {//##############################
      Serial.println("CRC is not valid!");//##############################
      return -1000;//##############################
  }
 
  if ( addr[0] != 0x10 && addr[0] != 0x28) {//##############################
      Serial.print("Device is not recognized");//##############################
      return -1000;//##############################
  }
 
  ds.reset();//##############################
  ds.select(addr);//##############################
  ds.write(0x44,1); // start conversion, with parasite power on at the end//##############################
 
  byte present = ds.reset();//##############################
  ds.select(addr);    //##############################
  ds.write(0xBE); // Read Scratchpad//##############################
 
   
  for (int i = 0; i < 9; i++) { // we need 9 bytes//##############################
    data[i] = ds.read();//##############################
  }
   
  ds.reset_search();//##############################
   
  byte MSB = data[1];//##############################
  byte LSB = data[0];//##############################
 
  float tempRead = ((MSB << 8) | LSB); //using two's compliment//##############################
  float TemperatureSum = tempRead / 16;//##############################
   
  return TemperatureSum;//##############################
   
}


* proj 20140123.jpg (37.28 KB, 332x426 - viewed 15 times.)
Logged

0
Offline Offline
Tesla Member
***
Karma: 118
Posts: 8962
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A simple way to get the arduino analog pin values into a fame in a web page.

Code:
// zoomkat's meta refresh data frame test page 5/25/13
// use http://192.168.1.102:84 in your brouser for main page
// http://192.168.1.102:84/data static data page
// http://192.168.1.102:84/datastart meta refresh data page
// for use with W5100 based ethernet shields
// set the refresh rate to 0 for fastest update
// use STOP for single data updates

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

const int analogInPin0 = A0;
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogInPin4 = A4;
const int analogInPin5 = A5;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
unsigned long int x=0; //set refresh counter to 0
String readString;

//////////////////////

void setup(){
  Serial.begin(9600);
    // disable SD SPI if memory card in the uSD slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();
  Serial.println("meta refresh data frame test 5/25/13"); // so I can keep track of what is loaded
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         if (readString.length() < 100) {
          readString += c;
         }
        //check if HTTP request has ended
        if (c == '\n') {

          //check get atring received
          Serial.println(readString);

          //output HTML data header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          //generate data page
          if(readString.indexOf("data") >0) {  //checks for "data" page
            x=x+1; //page upload counter
            client.print("<HTML><HEAD>");
            //meta-refresh page every 1 seconds if "datastart" page
            if(readString.indexOf("datastart") >0) client.print("<meta http-equiv='refresh' content='1'>");
            //meta-refresh 0 for fast data
            if(readString.indexOf("datafast") >0) client.print("<meta http-equiv='refresh' content='0'>");
            client.print("<title>Zoomkat's meta-refresh test</title></head><BODY><br>");
            client.print("page refresh number: ");
            client.print(x); //current refresh count
            client.print("<br><br>");
           
              //output the value of each analog input pin
            client.print("analog input0 is: ");
            client.print(analogRead(analogInPin0));
           
            client.print("<br>analog input1 is: ");
            client.print(analogRead(analogInPin1));
                       
            client.print("<br>analog input2 is: ");
            client.print(analogRead(analogInPin2));
           
            client.print("<br>analog input3 is: ");
            client.print(analogRead(analogInPin3));
                                   
            client.print("<br>analog input4 is: ");
            client.print(analogRead(analogInPin4));
           
            client.print("<br>analog input5 is: ");
            client.print(analogRead(analogInPin5));
            client.println("<br></BODY></HTML>");
           }
          //generate main page with iframe
          else
          {
            client.print("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>");
            client.print("Zoomkat's Arduino frame meta refresh test 5/25/13");
            client.print("<BR><BR>Arduino analog input data frame:<BR>");
            client.print("&nbsp;&nbsp;<a href='http://192.168.1.102:84/datastart' target='DataBox' title=''yy''>META-REFRESH</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://192.168.1.102:84/data' target='DataBox' title=''xx''>SINGLE-STOP</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://192.168.1.102:84/datafast' target='DataBox' title=''zz''>FAST-DATA</a><BR>");
            client.print("<iframe src='http://192.168.1.102:84/data' width='350' height='250' name='DataBox'>");
            client.print("</iframe><BR></HTML>");
          }
          delay(1);
          //stopping client
          client.stop();
          //clearing string for next read
          readString="";
        }
      }
    }
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

Hello Zoomkat.

Do you (or anyone else) have examples where LED is controlled with SD Webserver? Or any  SD Webserver examples?

normal Webserver is OK. i am having trouble regarding SD Webserver and controlling LED.

i did a basic page with 2 buttons and put that on the SD.
i did your webserver LED controll (without SD).
i did the starting electronics Arduino SD Card Web Server (this unfortunately only let you open a webpage on SD)

Basic Webpage 2 buttons
Code:
<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
 
Buttons to control PIN 5 (High / LOW)<br>
<input type=submit value=ON style=width:100px;height:45px onClick=location.href='/?on'>
<input type=submit value=OFF style=width:100px;height:45px onClick=location.href='/?off'> <br> <br>

</body>
</html>

Zoomkat webserver example (without SD)
Code:
//zoomkat 3-17-12
//simple button GET server code to control servo and arduino pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//Powering a servo from the arduino usually DOES NOT WORK.
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605

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

#include <Servo.h>
Servo myservo;  // create servo object to control a servo

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 169,254,126, 123 }; // ip in lan
//byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String readString;

//////////////////////

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip);
  server.begin();

  myservo.write(90); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo co
  //enable serial data print
  Serial.begin(9600);
  Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(c);
        }

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
         
          // DIY buttons
          client.println("<a href=\"/?on\"\">ON</a>");
          client.println("<a href=\"/?off\"\">OFF</a><br />");

          // mousedown buttons
          client.println("<br><input type=\"button\" value=\"ON\" onClick=location.href='/?on111'>");
          client.println("<input type=\"button\" value=\"OFF\" onClick=location.href='/?off112'>");       
         
          client.println("<input type=submit value=ON style=width:100px;height:45px onClick=location.href='/?on111'>");
          client.println("<input type=submit value=OFF style=width:100px;height:45px onClick=location.href='/?off112'>");
         
          // mousedown radio buttons
          //client.println("<br><br><input type=\"radio\" value=\"ON\" onmousedown=\"location.href ('/?on');\"\">ON</>");
          // client.println("<input type=\"radio\" value=\"OFF\" onmousedown=\"location.href ('/?off');\"\">OFF</>");       
 
          client.println("</BODY>");
          client.println("</HTML>");
 
          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("111") >0)//checks for on
          {
            myservo.write(40);
            digitalWrite(5, HIGH);    // set pin 5 high
            Serial.println("Led On");
          }
          if(readString.indexOf("112") >0)//checks for off
          {
            myservo.write(140);
            digitalWrite(5, LOW);    // set pin 5 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

Starting Electronics example to open SD webpage
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(169,254,126, 123); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

File webFile;

void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for debugging
   
    // initialize SD card
    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("INDEXH~1.TXT")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    // send web page
                    webFile = SD.open("INDEXH~1.TXT");        // open web page file
                    if (webFile) {
                        while(webFile.available()) {
                            client.write(webFile.read()); // send web page to client
                        }
                        webFile.close();
                    }
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                }
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

thank you.
Logged

Pages: [1]   Go Up
Jump to: