X-Git-Url: http://git.home-dn.net/?p=manu%2Farduino-maison.git;a=blobdiff_plain;f=garage%2Fgarage.ino;h=5128f1fdf7899452ce054103e7d2db3a9aa703b4;hp=0c11eaab2ec4aa86bfe5044a775d43f4d6c9fdde;hb=53f952dbf7aaf1800c3632f6916393d94f1ca432;hpb=92461c3a3b98d41c79ae7aa3eeb849f20bead087 diff --git a/garage/garage.ino b/garage/garage.ino index 0c11eaa..5128f1f 100644 --- a/garage/garage.ino +++ b/garage/garage.ino @@ -1,7 +1,9 @@ #include #include #include -#include +#include +#include +#include #include "garage-config.h" @@ -18,8 +20,10 @@ String city = CITY; String location = LOCATION; WiFiUDP Udp; -int pinDHT22 = 13; -SimpleDHT22 dht22(pinDHT22); +// Temp +#define DHTPIN 19 +#define DHTTYPE DHT22 +DHT_Unified dht(DHTPIN, DHTTYPE); TeleInfo teleinfo(&Serial); @@ -32,32 +36,59 @@ 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); + + // Check wifi connexion + if ( WiFi.status() != WL_CONNECTED ) { + int retry = 0; + WiFi.mode(WIFI_STA); + WiFi.begin(WIFI_SSID, WIFI_PASS); + while (retry < 10 || WiFi.status() != WL_CONNECTED) { + retry++; + delay(500); + } } - - teleinfo.process(); - if(teleinfo.available()){ - long I1 = teleinfo.getLongVal("IINST1"); - long I2 = teleinfo.getLongVal("IINST2"); - long I3 = teleinfo.getLongVal("IINST3"); - long PAPP = teleinfo.getLongVal("PAPP"); - long BASE = teleinfo.getLongVal("BASE"); - sendToInfluxDB("teleinfo,city="+city+",phase=1", "IINST", String(I1)); - sendToInfluxDB("teleinfo,city="+city+",phase=2", "IINST", String(I2)); - sendToInfluxDB("teleinfo,city="+city+",phase=3", "IINST", String(I3)); - sendToInfluxDB("teleinfo,city="+city, "PAPP", String(PAPP)); - sendToInfluxDB("teleinfo,city="+city, "BASE", String(BASE)); - teleinfo.resetAvailable(); + + if ( WiFi.status() == WL_CONNECTED ) { + 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)); + } + + teleinfo.process(); + if(teleinfo.available()){ + long I1 = teleinfo.getLongVal("IINST1"); + long I2 = teleinfo.getLongVal("IINST2"); + long I3 = teleinfo.getLongVal("IINST3"); + long PAPP = teleinfo.getLongVal("PAPP"); + long BASE = teleinfo.getLongVal("BASE"); + sendToInfluxDB("teleinfo,city="+city+",phase=1", "IINST", String(I1)); + sendToInfluxDB("teleinfo,city="+city+",phase=2", "IINST", String(I2)); + sendToInfluxDB("teleinfo,city="+city+",phase=3", "IINST", String(I3)); + sendToInfluxDB("teleinfo,city="+city, "PAPP", String(PAPP)); + sendToInfluxDB("teleinfo,city="+city, "BASE", String(BASE)); + teleinfo.resetAvailable(); + } } - delay(POLL_INT); } void sendToInfluxDB(String measure, String key, String value) {