Wifi check moved info separate function.

This commit is contained in:
Kai Lauterbach 2022-07-27 10:29:01 +02:00
parent 930bde2619
commit 66440f572e
2 changed files with 34 additions and 24 deletions

View file

@ -10,7 +10,7 @@
#define DELAY_LOOP_MS 50
#define POWERSAVING_SLEEP_S 600
#define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover
#define RESET_ESP_TIME_INTERVAL_MS (60*60*6*1000) // (60*60*6*1000) // reset every 6 hours
#define RESET_ESP_TIME_INTERVAL_MS (60*60*3*1000) // (60*60*6*1000) // reset every 3 hours
#define WIND_SENSOR_MEAS_TIME_S 15
#define INITIAL_WEBSERVER_TIME 20

View file

@ -71,29 +71,7 @@ void setup()
criticalBatCheck();
#endif
// Establish WiFi connection
String wifiName = "oko-weather-" + DEVICE_NAME;
wifiManager.setMinimumSignalQuality(WIFI_MINIMUM_SIGNAL_QUALITY);
// the time in seconds to wait for the known wifi connection
wifiManager.setConnectTimeout(WIFI_AUTOCONNECT_TIMEOUT_S);
// the time in seconds to wait for the user to configure the device
wifiManager.setTimeout(WIFI_CONFIG_PORTAL_TIMEOUT_S);
while (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF"))
{
debug("WiFi connection failed, try again in 5 seconds...");
// If autoconnect to WLAN failed and no client connected, go to deep sleep
#ifdef SLEEP_IF_NO_WLAN_CONNECTION
ESP.deepSleep(POWERSAVING_SLEEP_S * 1000000, WAKE_RF_DEFAULT);
delay(100);
#endif
#ifndef SLEEP_IF_NO_WLAN_CONNECTION
// sleep a few seconds and go on trying to connect
delay(5000);
#endif
}
wifiConnectionCheck();
debug("Connected!");
#ifdef INFLUXDB_FEATURE
@ -168,6 +146,35 @@ void setup()
//*************************************************************************//
void wifiConnectionCheck()
{
// Establish WiFi connection
String wifiName = "oko-weather-" + DEVICE_NAME;
wifiManager.setMinimumSignalQuality(WIFI_MINIMUM_SIGNAL_QUALITY);
// the time in seconds to wait for the known wifi connection
wifiManager.setConnectTimeout(WIFI_AUTOCONNECT_TIMEOUT_S);
// the time in seconds to wait for the user to configure the device
wifiManager.setTimeout(WIFI_CONFIG_PORTAL_TIMEOUT_S);
while (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF"))
{
debug("WiFi connection failed, try again in 5 seconds...");
// If autoconnect to WLAN failed and no client connected, go to deep sleep
#ifdef SLEEP_IF_NO_WLAN_CONNECTION
ESP.deepSleep(POWERSAVING_SLEEP_S * 1000000, WAKE_RF_DEFAULT);
delay(100);
#endif
#ifndef SLEEP_IF_NO_WLAN_CONNECTION
// sleep a few seconds and go on trying to connect
delay(5000);
#endif
}
}
//*************************************************************************//
#ifdef BATTERY_POWERED
void criticalBatCheck()
{
@ -189,6 +196,8 @@ void loop()
ESP.wdtFeed();
#endif
wifiConnectionCheck();
#ifdef BATTERY_POWERED
delay(50);
return;
@ -209,6 +218,7 @@ void loop()
#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED
update_windspeed_exceed_cnt++;
#endif
}
void _loop()