#if DHT_SENSOR #include #include #include #define DHT11_PIN 12 #define READ_INTERVAL(c) (c*60*1000UL) // read interval in minutes DHT dht = DHT(DHT11_PIN, DHT11); unsigned long currentTime = 0; namespace Dht { void setup() { dht.begin(); } void read() { currentTime = millis(); static unsigned long lastReadTime = 0; if (currentTime > lastReadTime) { lastReadTime = currentTime + READ_INTERVAL(5); StaticJsonDocument<200> jsonDoc; JsonObject dht11 = jsonDoc.createNestedObject("dht11"); dht11["temperature"] = dht.readTemperature(); dht11["humidity"] = dht.readHumidity(); serializeJson(jsonDoc, Serial); Serial.println(); } } } #else namespace Dht { void setup() { } void read() { } } #endif