Nicu Hodos 89da9a80e8 re-organize:
- move code for all devices in dedicated folder
- move code for gateway in the root folder
2025-09-20 10:00:42 +02:00

39 lines
755 B
C++

#if DHT_SENSOR
#include <Adafruit_Sensor.h>
#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() {
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