/* * A Simple Monitoring Sensor */ // Includes for Temperature and Humidity Sensor #include "DHT.h" // Includes for Ethernet #include #include // Definitions for DHT #define DHTPIN 7 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); // Definitions for Ethernet Web Server byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte ip[] = { 0,0,0,0 }; EthernetServer server(80); // Led Pins const int greenLed = 9; const int redLed = 8; //Led handling stuff long waitUntil=0; boolean greenLedState = true; void setup() { //Initialize Ethernet.begin(mac, ip); server.begin(); dht.begin(); // Define led pin modes pinMode(greenLed, OUTPUT); pinMode(redLed, OUTPUT); } void loop() { // Each time through loop(), set green Led to the same value as the state variable digitalWrite(greenLed, greenLedState); // Nothing will change until millis() increments by 1000 if (millis() >= waitUntil) { greenLedState = !(greenLedState); // Toggle the LED's state waitUntil = millis() + 1000; // Make sure we wait for another 1000 milliseconds. } //Process Web requests EthernetClient client = server.available(); if (client) { // an http request ends with a blank line boolean current_line_is_blank = true; while (client.connected()) { if (client.available()) { char c = client.read(); // if we've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so we can send a reply if (c == '\n' && current_line_is_blank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println("
Monitoring");
          client.println();
          
          // output the value of each analog input pin
          client.print("Sabotage: ");
          if (digitalRead(A0) == 1){
            client.println("ok");
          }else{
            client.println("alert");
          }          
          client.print("Battery: ");
          if (digitalRead(A1) == 1){
            client.println("ok");
          }else{
            client.println("alert");
          }             
          client.print("Other: ");
          if (digitalRead(A2) == 1){
            client.println("ok");
          }else{
            client.println("alert");
          }   
          client.print("Burglar: ");
          if (digitalRead(A3) == 1){
            client.println("ok");
          }else{
            client.println("alert");
          }
          client.print("Fire: ");
          if (digitalRead(A4) == 1){
            client.println("ok");
          }else{
            client.println("alert");
          }    
          
            //read and send temperature

            float h = dht.readHumidity();
            float t = dht.readTemperature()-1.9;
            if (isnan(t) || isnan(h)) {
              client.println("Temperature: unknown");
              client.println("Humidity: unknown");
            } else {
              client.print("Temperature: "); 
              client.println(t);
              client.print("Humidity: "); 
              client.println(h);
            }

          // in case of problems turn on red led
          if ( digitalRead(A0) and digitalRead(A1) and digitalRead(A2) and digitalRead(A3) and digitalRead(A4) and t <= 35.0){
            digitalWrite(redLed, LOW); 
          }else{
            digitalWrite(redLed, HIGH); 
          }
          
          client.println("
"); break; } if (c == '\n') { // we're starting a new line current_line_is_blank = true; } else if (c != '\r') { // we've gotten a character on the current line current_line_is_blank = false; } } } // give the web browser time to receive the data delay(1); client.stop(); } }