X-Git-Url: http://git.home-dn.net/?p=manu%2Farduino-maison.git;a=blobdiff_plain;f=station-meteo%2Fstation-meteo.ino;h=5a96ba827320f2ca23e922249ab77bd67cb453df;hp=589c4bbfd19726ec3bdd8a107b624f3fb8d600f9;hb=HEAD;hpb=c2263c0c69da7fea06826d04d6061f174c2c89f9 diff --git a/station-meteo/station-meteo.ino b/station-meteo/station-meteo.ino index 589c4bb..dc4cc21 100644 --- a/station-meteo/station-meteo.ino +++ b/station-meteo/station-meteo.ino @@ -29,10 +29,8 @@ String location = LOCATION; int rainfall_sensor_pin = 2; float rain_incr = 0.2794; // this is mm/m2 for each sensor tick int rainfall_ticks = 0; - -// Timing -unsigned long previousMillis= 0; -unsigned long previousMillis2= 0; +long debouncing_time = 30; +volatile unsigned long last_micros; // Initiate udp client WiFiUDP udp; @@ -73,10 +71,15 @@ void setup(void) Serial.println(wifi_ssid); // Connect to WPA/WPA2 network WiFi.begin(wifi_ssid, wifi_pass); + delay(500); // attempt to connect to Wifi network: while (WiFi.status() != WL_CONNECTED) { + WiFi.begin(wifi_ssid, wifi_pass); delay(500); + if (WiFi.status() != WL_CONNECTED) { + delay(2000); + } } Serial.println("Connected to wifi"); @@ -92,13 +95,12 @@ void loop(void) { delay(POLL_INT); - // Check wifi connexion - if ( WiFi.status() != WL_CONNECTED ) { - int retry = 0; + // Reconnect if needed + while (WiFi.status() != WL_CONNECTED) { WiFi.begin(wifi_ssid, wifi_pass); - while (retry < 10 || WiFi.status() != WL_CONNECTED) { - retry++; - delay(500); + delay(500); + if (WiFi.status() != WL_CONNECTED) { + delay(2000); } } @@ -174,5 +176,8 @@ void printWifiStatus() { void getRain () { - rainfall_ticks ++ ; + if((long)(micros() - last_micros) >= debouncing_time * 1000) { + rainfall_ticks ++ ; + last_micros = micros(); + } }