X-Git-Url: http://git.home-dn.net/?p=manu%2Farduino-maison.git;a=blobdiff_plain;f=palier%2Fpalier.ino;h=285673df15c606e2409186eca9e780b2fcdf5cad;hp=7cf3a33789e3dd05309e28a00c1313d33f547588;hb=53f952dbf7aaf1800c3632f6916393d94f1ca432;hpb=cf209e608c5a2e6d2662db6861e1ba5cecb11e4d diff --git a/palier/palier.ino b/palier/palier.ino index 7cf3a33..285673d 100644 --- a/palier/palier.ino +++ b/palier/palier.ino @@ -44,21 +44,33 @@ void setup() { void loop() { 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)); + // 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); + } } - dht.humidity().getEvent(&event); - if (isnan(event.relative_humidity)) { - // Error - } else { - sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity)); + + 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)); + } } - } void sendToInfluxDB(String measure, String key, String value) {