#include <WiFi.h>
#include <DHT.h>
#include <stdlib.h> // For random number generation
// Dummy WiFi credentials (for simulation)
const char* ssid = "wokwi-GUEST";
const char* password = "";
// DHT sensor configuration
#define DHTPIN 4 // Define the GPIO pin to which the DHT22 is connected
#define DHTTYPE DHT22 // Define the sensor type (DHT11 or DHT22)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
// Connect to WiFi (simulated)
Serial.println("Connecting to WiFi (simulated)...");
delay(1000);
Serial.println("Connected (simulated) to WiFi");
// Initialize the DHT sensor
dht.begin();
}
void loop() {
// Read temperature and humidity
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (!isnan(temperature) && !isnan(humidity)) {
// Simulate marginal changes in temperature and humidity
temperature += random(-1, 2); // Change temperature by -1, 0, or 1 degree
humidity += random(-1, 2); // Change humidity by -1, 0, or 1%
Serial.print("Temperature (°C): ");
Serial.println(temperature);
Serial.print("Humidity (%): ");
Serial.println(humidity);
} else {
Serial.println("Failed to read from DHT sensor!");
}
delay(10000); // Delay for 10 seconds before the next reading with marginal changes
}