#include <WiFi.h>
#include <DHTesp.h>
char ssid[]="Wokwi-GUEST";
char pass[]="";
WiFiClient client;
DHTesp dhtsensor;
TempAndHumidity data;
const int DHT_PIN=27;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
WiFi.mode(WIFI_STA);
dhtsensor.setup(DHT_PIN,DHTesp::DHT22);
}
void loop() {
if(WiFi.status()!=WL_CONNECTED)
{
Serial.print("Attempting to connect");
while(WiFi.status()!=WL_CONNECTED)
{
WiFi.begin(ssid,pass);
Serial.print(".");
delay(3000);
}
Serial.println("\n connected");
}
delay(1000);
{
data=dhtsensor.getTempAndHumidity();
Serial.println("Hum:"+String(data.humidity,1));
Serial.println("Temp:"+String(data.temperature));
Serial.println("-------");
delay(1000);
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
}