// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address on serial monitor
Serial.print("Use this URL to connect: ");
Serial.print("http://"); //URL IP to be typed in mobile/desktop browser
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('r');
Serial.println(request);
client.flush();
float h =0.0; //Humidity level
float t =0.0; //Temperature in celcius
float f =0.0; //Temperature in fahrenheit
// Match the request
int value = LOW;
if (request.indexOf("/Up=ON") != -1) {
h = dht.readHumidity(); //Read humidity level
t = dht.readTemperature(); //Read temperature in celcius
f = (h * 1.8) + 32; //Temperature converted to Fahrenheit
value = HIGH;
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("");
client.println("");
client.println("