X-Git-Url: http://git.home-dn.net/?p=manu%2Farduino-maison.git;a=blobdiff_plain;f=cave%2Fcave.ino;h=996154e534f778c6f8db273a5af2a5a7a26c8c38;hp=24d9d46cb7f02b51504fb311ec110426b03a4f4c;hb=53f952dbf7aaf1800c3632f6916393d94f1ca432;hpb=cf209e608c5a2e6d2662db6861e1ba5cecb11e4d diff --git a/cave/cave.ino b/cave/cave.ino index 24d9d46..996154e 100644 --- a/cave/cave.ino +++ b/cave/cave.ino @@ -62,34 +62,47 @@ void setup() { void loop() { delay(POLL_INT); - sensors_event_t event; - - dht.temperature().getEvent(&event); - if (isnan(event.temperature)) { - #if defined(DEBUG) - Serial.println("DHT 22 temperature error"); - #endif - } else { - #if defined(DEBUG) - Serial.println("Temperature: "+String(event.temperature)); - #endif - sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature)); - double water_dist = distanceSensor.measureDistanceCm(event.temperature); - #if defined(DEBUG) - Serial.println("Distance: "+String(water_dist)); - #endif - sendToInfluxDB("water_well,city="+city+",location="+location, "distance", String(water_dist)); + // 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)) { - #if defined(DEBUG) - Serial.println("DHT 22 humidity error"); - #endif - } else { - #if defined(DEBUG) - Serial.println("Humidity: "+String(event.relative_humidity)); - #endif - 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)) { + #if defined(DEBUG) + Serial.println("DHT 22 temperature error"); + #endif + } else { + #if defined(DEBUG) + Serial.println("Temperature: "+String(event.temperature)); + #endif + sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature)); + double water_dist = distanceSensor.measureDistanceCm(event.temperature); + #if defined(DEBUG) + Serial.println("Distance: "+String(water_dist)); + #endif + sendToInfluxDB("water_well,city="+city+",location="+location, "distance", String(water_dist)); + } + dht.humidity().getEvent(&event); + if (isnan(event.relative_humidity)) { + #if defined(DEBUG) + Serial.println("DHT 22 humidity error"); + #endif + } else { + #if defined(DEBUG) + Serial.println("Humidity: "+String(event.relative_humidity)); + #endif + sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity)); + } } }