#include #include #include "DHT.h" // Uncomment one of the lines below for whatever DHT sensor type you're using! //#define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT21 // DHT 21 (AM2301) #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 /*Put your SSID & Password*/ const char* ssid = "xxxxxxxxxxxxxxxxxxxx"; // Enter SSID here const char* password = "xxxxxxxxxxxxxxxxxxxx"; //Enter Password here WebServer server(80); // DHT Sensor uint8_t DHTPinRack = 4; uint8_t DHTPinOutside = 2; // Initialize DHT sensor. DHT dht_rack(DHTPinRack, DHTTYPE); DHT dht_outside(DHTPinOutside, DHTTYPE); float temp_rack, temp_outside; float hum_rack, hum_outside; void setup() { Serial.begin(115200); delay(100); pinMode(DHTPinRack, INPUT); pinMode(DHTPinOutside, INPUT); dht_rack.begin(); dht_outside.begin(); Serial.println("Connecting to "); Serial.println(ssid); //connect to your local wi-fi network WiFi.begin(ssid, password); //check wi-fi is connected to wi-fi network while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); server.on("/", handle_OnConnect); server.onNotFound(handle_NotFound); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); } void handle_OnConnect() { temp_rack = dht_rack.readTemperature(); // Gets the values of the temperature hum_rack = dht_rack.readHumidity(); // Gets the values of the humidity temp_outside = dht_outside.readTemperature(); // Gets the values of the temperature hum_outside = dht_outside.readHumidity(); // Gets the values of the humidity server.send(200, "text/html", SendHTML(temp_rack,hum_rack,temp_outside,hum_outside)); } void handle_NotFound(){ server.send(404, "text/plain", "Not found"); } String SendHTML(float temp_rack, float hum_rack, float temp_outside, float hum_outside){ String ptr = " \n"; ptr +="\n"; ptr +="ESP32 Gartenhaus\n"; ptr +="\n"; ptr +="\n"; ptr +="\n"; ptr +="
\n"; ptr +="

Outside

\n"; ptr +="

Temperature: "; ptr +=String(temp_outside,1); ptr +="C

"; ptr +="

Humidity: "; ptr +=String(hum_outside,1); ptr +="%

"; ptr +="

Rack

\n"; ptr +="

Temperature: "; ptr +=String(temp_rack,1); ptr +="C

"; ptr +="

Humidity: "; ptr +=String(hum_rack,2); ptr +="%

"; ptr +="
\n"; ptr +="\n"; ptr +="\n"; return ptr; }