Nicu Hodos 7bb1f231ca
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
extract Dht in separate file and disable it
2022-10-08 16:08:12 +02:00

35 lines
689 B
C++

#if DHT_SENSOR
#include <DHT.h>
#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(JsonDocument& jsonDoc) {
currentTime = millis();
static unsigned long lastReadTime = 0;
if (currentTime > lastReadTime) {
lastReadTime = currentTime + READ_INTERVAL(5);
JsonObject dht11 = jsonDoc.createNestedObject("dht11");
dht11["temperature"] = dht.readTemperature();
dht11["humidity"] = dht.readHumidity();
}
}
}
#else
namespace Dht {
void setup() {
}
void read(JsonDocument& jsonDoc) {
}
}
#endif