#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 // Replace with your network credentials const char* ssid = "TR-2"; const char* password = "1234"; WiFiServer server(80); // DHT Sensor const int DHTPin = 16; // Initialize DHT sensor. DHT dht(DHTPin, DHTTYPE); // Temporary variables static char celsiusTemp[7]; static char fahrenheitTemp[7]; static char humidityTemp[7]; // Client variables char linebuf[80]; int charcount=0; void setup() { // initialize the DHT sensor dht.begin(); //Initialize serial and wait for port to open: Serial.begin(115200); while(!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // We start by connecting to a WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); // attempt to connect to Wifi network: while(WiFi.status() != WL_CONNECTED) { // Connect to WPA/WPA2 network. Change this line if using open or WEP network: delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin(); } void loop() { // listen for incoming clients WiFiClient client = server.available(); if (client) { Serial.println("New client"); memset(linebuf,0,sizeof(linebuf)); charcount=0; // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); //read char by char HTTP request linebuf[charcount]=c; if (charcount"); client.println(""); client.println("

ESP32 - DHT web server

"); if(atoi(celsiusTemp)>=25){ client.println("

"); } else if(atoi(celsiusTemp)<25 && atoi(celsiusTemp)>=5){ client.println("
"); } else if(atoi(celsiusTemp)<5){ client.println("
"); } client.println(celsiusTemp); client.println("*C

"); client.println(fahrenheitTemp); client.println("*F

"); client.println(humidityTemp); client.println("%

"); client.println(""); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; memset(linebuf,0,sizeof(linebuf)); charcount=0; } 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(1); // close the connection: client.stop(); Serial.println("client disconnected"); } }