projects
/
manu
/
arduino-maison.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add "grande chambre" (using esp8266 nodemcu)
[manu/arduino-maison.git]
/
station-meteo
/
station-meteo.ino
diff --git
a/station-meteo/station-meteo.ino
b/station-meteo/station-meteo.ino
index
589c4bb
..
dc4cc21
100644
(file)
--- 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;
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;
// 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);
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) {
// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
+ WiFi.begin(wifi_ssid, wifi_pass);
delay(500);
delay(500);
+ if (WiFi.status() != WL_CONNECTED) {
+ delay(2000);
+ }
}
Serial.println("Connected to wifi");
}
Serial.println("Connected to wifi");
@@
-92,13
+95,12
@@
void loop(void)
{
delay(POLL_INT);
{
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);
WiFi.begin(wifi_ssid, wifi_pass);
- while (retry < 10 || WiFi.status() != WL_CONNECTED) {
- retry++;
- delay(
5
00);
+ delay(500);
+ if (WiFi.status() != WL_CONNECTED) {
+ delay(
20
00);
}
}
}
}
@@
-174,5
+176,8
@@
void printWifiStatus() {
void getRain ()
{
void getRain ()
{
- rainfall_ticks ++ ;
+ if((long)(micros() - last_micros) >= debouncing_time * 1000) {
+ rainfall_ticks ++ ;
+ last_micros = micros();
+ }
}
}