X-Git-Url: http://git.home-dn.net/?p=manu%2Farduino-maison.git;a=blobdiff_plain;f=salon%2Fsalon.ino;h=5bcbc3856b1230dd5b00b4f6c0b75c7ac65b50c7;hp=fb7d51f90d3cabe67595a4f31baaa640c74f0ebd;hb=77198d84ebbca4919f19b24d949b7d0c74774ae2;hpb=e0347f1c0aaca5922015857588383e7d73cdb81a diff --git a/salon/salon.ino b/salon/salon.ino index fb7d51f..5bcbc38 100644 --- a/salon/salon.ino +++ b/salon/salon.ino @@ -1,6 +1,8 @@ #include #include -#include +#include +#include +#include #include "salon-config.h" @@ -17,8 +19,10 @@ String city = CITY; String location = LOCATION; WiFiUDP Udp; -int pinDHT22 = 13; -SimpleDHT22 dht22(pinDHT22); +// Temp +#define DHTPIN 13 +#define DHTTYPE DHT22 +DHT_Unified dht(DHTPIN, DHTTYPE); void setup() { @@ -29,18 +33,32 @@ void setup() { while (WiFi.status() != WL_CONNECTED) { delay(500); } + + dht.begin(); + sensor_t sensor; + dht.temperature().getSensor(&sensor); + dht.humidity().getSensor(&sensor); + } void loop() { - float temperature = 0; - float humidity = 0; - int err = SimpleDHTErrSuccess; - if ((err = dht22.read2(&temperature, &humidity, NULL)) == SimpleDHTErrSuccess) { - sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(temperature)); - sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(humidity)); + delay(POLL_INT); + + sensors_event_t event; + + dht.temperature().getEvent(&event); + if (isnan(event.temperature)) { + // Error + } else { + sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature)); + } + dht.humidity().getEvent(&event); + if (isnan(event.relative_humidity)) { + // Error + } else { + sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity)); } - delay(POLL_INT); } void sendToInfluxDB(String measure, String key, String value) {