#include #include #include //////////////////////////////////////////// #include #define DHTPIN A3     // what pin we're connected the DHT output #define DHTTYPE DHT11   // DHT 11 DHT dht(DHTPIN, DHTTYPE); #include ///////////////////////////////////////////// byte mac[] = {  0xFE, 0xA9, 0xE7, 0xD6, 0xE4, 0x95 }; IPAddress ip(192,168,0,153); EthernetServer server(8081); OneWire ds(2); ///////////////// int pinoentrada; int tensao; int I=0; int soma=0; int media=0; //////////////////// //Set up some variables byte i, ii; //array pointers byte dev[8] [8]; //device array byte devpr; //Number of devices present void setup() { //////////////////////////  pinMode(A1,INPUT); //////////////////////// ////////////////////// dht.begin(); /////////////////    Serial.begin(9600);  Ethernet.begin(mac, ip);  server.begin();  Serial.print("server is at ");  Serial.println(Ethernet.localIP());  //Find all of the Onewire devices connected to pin 9  for (ii = 0; ii < 8; ii++) { //Up to eight devices    if (!ds.search(dev[ii])){ //if no devices found      Serial.println("No more devices found! ");      devpr = ii;      Serial.print("Number of devices found equal ");      Serial.println(devpr);      ds.reset_search();      delay(10);      return;   //       bits //        of //     precision // 0   -   9 // 1   -  10 // 2   -  11 // 3   -  12  // For 9 bit precision      int t_precision = 0;      ds.select(dev[ii]);          ds.write(0x4E);      // write zero into the alarm registers      ds.write(0);      ds.write(0);      // and write t_precision into the configuration register      // to select the precision of the temperature      ds.write(t_precision << 5);      // Write them to the EEPROM      ds.write(0x48);    }  } //////////////////////////////// while (!Serial) {    ; // wait for serial port to connect. Needed for Leonardo only  } //////////////////////////////////////////// } void loop() { EthernetClient client = server.available();    if (client) {    Serial.println("new client");    // an http request ends with a blank line    boolean currentLineIsBlank = true;    while (client.connected()) {      if (client.available()) {        char c = client.read();        Serial.write(c);        // if you've gotten to the end of the line (received a newline        // character) and the line is blank, the http request has ended,        // so you can send a reply        if (c == '\n' && currentLineIsBlank) {                byte present = 0;  byte data [8] [12];// 8  12  int16_t raw [8];//8  float celsius [8] ;//8  //Print out the device serial numbers  for( ii = 0; ii < devpr; ii++) {    Serial.print("ROM =");    for( i = 0; i < 8; i++) {      Serial.write(' ');      Serial.print(dev[ii][i], HEX);    }    Serial.println("");  }  //Let get some data!  for( ii = 0; ii < devpr; ii++) { //Select which device    ds.reset();    ds.select(dev[ii]);    ds.write(0x44, 1); //(bilo je 1 sad je 10) start conversion, with parasite power on at the end    delay(100); // data 750ms is enough, maybe not    present = ds.reset();    ds.select(dev[ii]);    ds.write(0xBE); // Read Scratchpad    for ( i = 0; i < 9; i++) { // we need 9 bytes      data[ii][i] = ds.read();    }  }  //Conversion time...  // Convert the data to actual temperature  // because the result is a 16 bit signed integer, it should  // be stored to an "int16_t" type, which is always 16 bits  // even when compiled on a 32 bit processor.  for( ii = 0; ii < devpr; ii++) {    raw [ii]= (data[ii][1] << 8) | data[ii][0]; // bilo je 0     byte cfg = (data[ii][4] & 0x60);    // at lower res, the low bits are undefined, so let's zero them    if (cfg == 0x00)      raw[ii] = raw[ii] & ~7;  // 9 bit resolution, 93.75 ms    else if (cfg == 0x20) raw[ii] = raw[ii] & ~3; // 10 bit res, 187.5 ms    else if (cfg == 0x40) raw[ii] = raw[ii] & ~1; // 11 bit res, 375 ms    //// default is 12 bit resolution, 750 ms conversion time    celsius [ii] = (float)raw [ii] / 16.0;    Serial.print(" Temperature = ");    Serial.print(celsius [ii]);    Serial.print(" Celsius, ");  }  // listen for incoming clients on the Ethernet  EthernetClient client = server.available();  if (client) {    Serial.println("new client");    // an http request ends with a blank line    boolean currentLineIsBlank = true;    while (client.connected()) {      if (client.available()) {        char c = client.read();        Serial.write(c);        // if you've gotten to the end of the line (received a newline        // character) and the line is blank, the http request has ended,        // so you can send a reply        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"); // the connection will be closed after completion of the response          client.println("Refresh: 5"); // refresh the page automatically every 5 sec          client.println();          client.println("");          client.println("Sensores");          client.println("");          client.println("");          client.println("

");                    client.println("");          client.println("");          client.println("
");          client.print("
Temperatura Entrada:  ");          client.print(celsius [0]);          client.println("°C");          client.print("
Temperatura Saida:   ");          client.print(celsius [1]);          client.println("°C");          client.print("
");          client.println ("
");          client.println("
");          client.println("");          client.println("");          break;        }        if (c == '\n') {          // you're starting a new line          currentLineIsBlank = true;        }        else if (c != '\r') {          // you've gotten a character on the current line          currentLineIsBlank = false;        }      }    }    // give the web browser time to receive the data    delay(100);      } ////////////////////////////////////////////////////////// {         client.println(); // auto reload webpage every 5 second // webpage title // read analog pin 1 for the value of photocell client.print("

Voltagem = "); client.println((analogRead(A1) /4.606 )); client.println("

");    delay (100);    } //////////////////////////////////////////////////////  int h = dht.readHumidity();  int t = dht.readTemperature();    // listen for incoming clients            // send a standard http response header          boolean currentLineIsBlank = true;          if (c == '\n' && currentLineIsBlank) {                                      // add a meta refresh tag, so the browser pulls again every 5 seconds:          {                                                // output the value of temperature and humuidity from DHT          client.println("
");                    client.print("");          client.println("



");          client.println("");          client.println("

");          client.print("Ambiente : ");          client.print(t);          client.print("0");          client.print("C");          client.println("
");          client.print("Umidade : ");          client.print(h);          client.print("%");          client.println("

");          client.println("
");                    delay (100);          }                    }        if (c == '\n') {          // you're starting a new line          currentLineIsBlank = true;        }        else if (c != '\r') {          // you've gotten a character on the current line          currentLineIsBlank = false;        }      }    }  }    // give the web browser time to receive the data        // close the connection:    client.stop();    Serial.println("client disonnected"); delay(100);  } }