|
|
|
@ -7,13 +7,16 @@
|
|
|
|
|
#include <ESP8266HTTPClient.h>
|
|
|
|
|
|
|
|
|
|
#include <WiFiClient.h> // WiFiClient
|
|
|
|
|
#include <WiFiManager.h> // WiFiManager from bib manager
|
|
|
|
|
|
|
|
|
|
// Project includes
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "config_user.h"
|
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_WIFIMANAGER
|
|
|
|
|
#include <WiFiManager.h> // WiFiManager from bib manager
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//*************************************************************************//
|
|
|
|
|
// check if some settings are correct
|
|
|
|
|
|
|
|
|
@ -38,7 +41,9 @@ uint32_t wifi_check_interval_counter = 0;
|
|
|
|
|
|
|
|
|
|
const String wifiName = "oko-weather-" + DEVICE_NAME;
|
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_WIFIMANAGER
|
|
|
|
|
WiFiManager wifiManager;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
uint8_t fsm_state = FSM_STATE_1;
|
|
|
|
|
|
|
|
|
@ -258,11 +263,24 @@ void wifiConnectionCheck()
|
|
|
|
|
|
|
|
|
|
debug("no wifi connection, try to reconnect " + String(wifi_reconnect_cnt));
|
|
|
|
|
|
|
|
|
|
WiFi.disconnect();
|
|
|
|
|
WiFi.mode(WIFI_OFF);
|
|
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
|
|
|
|
|
|
#ifdef WEBUPDATER_FEATURE
|
|
|
|
|
setWifiReconnectCnt(wifi_reconnect_cnt);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
wifiConnect();
|
|
|
|
|
if (wifi_reconnect_cnt >= 5)
|
|
|
|
|
{
|
|
|
|
|
debug("\nReboot");
|
|
|
|
|
ESP.restart();
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
wifiConnect();
|
|
|
|
|
|
|
|
|
|
//initWifiBasedSW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -273,6 +291,8 @@ void wifiConnect()
|
|
|
|
|
|
|
|
|
|
// Establish WiFi connection if not already applied
|
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_WIFIMANAGER
|
|
|
|
|
|
|
|
|
|
wifiManager.setMinimumSignalQuality(WIFI_MINIMUM_SIGNAL_QUALITY);
|
|
|
|
|
// the time in seconds to wait for the known wifi connection
|
|
|
|
|
wifiManager.setConnectTimeout(WIFI_AUTOCONNECT_TIMEOUT_S);
|
|
|
|
@ -296,6 +316,19 @@ void wifiConnect()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else // DISABLE_WIFIMANAGER
|
|
|
|
|
|
|
|
|
|
WiFi.begin(WIFI_SSID, WIFI_PASSWD);
|
|
|
|
|
|
|
|
|
|
debug("Connecting to WLAN");
|
|
|
|
|
|
|
|
|
|
while (WiFi.status() != WL_CONNECTED)
|
|
|
|
|
{
|
|
|
|
|
delay(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // DISABLE_WIFIMANAGER
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//*************************************************************************//
|
|
|
|
@ -309,7 +342,7 @@ void criticalBatCheck()
|
|
|
|
|
debug("Bat Voltage: " + String(volt) + " V");
|
|
|
|
|
debug("Low battery, going into deep sleep.");
|
|
|
|
|
// Casting to an unsigned int, so it fits into the integer range
|
|
|
|
|
ESP.deepSleep(1U * EMERGENCY_SLEEP_S * 1000000); // battery low, shutting down
|
|
|
|
|
ESP.deepSleep(1U * EMERGENCY_SLEEP_S * 1000000u); // battery low, shutting down
|
|
|
|
|
delay(100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|