automatic_dht11.ino 1.78 KB
Newer Older
B.Nagasuman's avatar
B.Nagasuman committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#include <ESP8266WiFi.h>
#include <dht.h> 
dht DHT;
#define DHT11_PIN D5                                                                                          
const char* ssid = "vivo 1807";
const char* password = "pavansai";
WiFiServer server(80); 
void setup() 
{
  wifi_connect();
  Serial.begin(115200);
  server.begin();
  Serial.println("Web Server Started");
  Serial.print("Connect to the Server:");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println();
  Serial.println();
  }
void loop() {
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
   int STATUS;
  DHT.read11(DHT11_PIN);
  Serial.print(DHT.humidity,1);
  Serial.print("/n");
  Serial.print(DHT.temperature,1);
  delay(1000);
  client.flush();
  client.println("HTTP/1.1 200 OK"); 
  client.println("Content-Type: text/html");
  client.println("");
  client.println("<!DOCTYPE HTML>");
  client.println("<style>");
  client.println("<head>");
  client.println("<meta http-equiv=\"refresh\"content=\"3\"/>");
  client.println("body {background-color: #8baee8;}"); 
  client.println("</style>");
  client.print("<h1><b>&nbsp tempearture and humidity STATUS  </b></h1>");
  client.println("<br><br><br>");
   client.println("<meta http-equiv=\"refresh\"content=\"3\"/>");
   client.println(DHT.temperature);
   client.println(DHT.humidity);
   client.println("</html>");
  delay(3000);
}



void wifi_connect(void)
{
  
  Serial.begin(115200);
  delay(1000);
  
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected");  
}