This commit is contained in:
iranl
2024-08-21 13:40:10 +02:00
committed by GitHub
parent 618591e65e
commit 22348d71a3
18 changed files with 1459 additions and 1421 deletions

View File

@@ -52,8 +52,6 @@ EthernetDevice::EthernetDevice(const String &hostname,
void EthernetDevice::init()
{
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect);
#ifndef NUKI_HUB_UPDATER
size_t caLength = _preferences->getString(preference_mqtt_ca, _ca, TLS_CA_MAX_SIZE);
size_t crtLength = _preferences->getString(preference_mqtt_crt, _cert, TLS_CERT_MAX_SIZE);
@@ -253,7 +251,7 @@ ReconnectStatus EthernetDevice::reconnect(bool force)
void EthernetDevice::onDisconnected()
{
if(_restartOnDisconnect && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
reconnect();
}

View File

@@ -67,7 +67,6 @@ private:
void onNetworkEvent(arduino_event_id_t event, arduino_event_info_t info);
bool _connected = false;
bool _restartOnDisconnect = false;
char* _path;
bool _hardwareInitialized = false;

View File

@@ -18,8 +18,6 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const I
_startAp = strcmp(WiFiDevice_reconfdetect, "reconfigure_wifi") == 0;
#ifndef NUKI_HUB_UPDATER
_restartOnDisconnect = preferences->getBool(preference_restart_on_disconnect, false);
size_t caLength = preferences->getString(preference_mqtt_ca, _ca, TLS_CA_MAX_SIZE);
size_t crtLength = preferences->getString(preference_mqtt_crt, _cert, TLS_CERT_MAX_SIZE);
size_t keyLength = preferences->getString(preference_mqtt_key, _key, TLS_KEY_MAX_SIZE);
@@ -49,11 +47,11 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const I
if(preferences->getBool(preference_mqtt_log_enabled, false) || preferences->getBool(preference_webserial_enabled, false))
{
MqttLoggerMode mode;
if(preferences->getBool(preference_mqtt_log_enabled, false) && preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::MqttAndSerialAndWeb;
else if (preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::SerialAndWeb;
else mode = MqttLoggerMode::MqttAndSerial;
_path = new char[200];
memset(_path, 0, sizeof(_path));
@@ -72,15 +70,14 @@ const String WifiDevice::deviceName() const
void WifiDevice::initialize()
{
_wifiFallbackDisabled = _preferences->getBool(preference_network_wifi_fallback_disabled, false);
std::vector<const char *> wm_menu;
wm_menu.push_back("wifi");
wm_menu.push_back("exit");
_wm.setEnableConfigPortal(_startAp || !_wifiFallbackDisabled);
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled, false));
// reduced timeout if ESP is set to restart on disconnect
_wm.setFindBestRSSI(_preferences->getBool(preference_find_best_rssi));
_wm.setConnectTimeout(20);
_wm.setConfigPortalTimeout(_restartOnDisconnect ? 60 * 3 : 60 * 30);
_wm.setConfigPortalTimeout(_preferences->getBool(preference_restart_on_disconnect, false) ? 60 * 3 : 60 * 30);
_wm.setShowInfoUpdate(false);
_wm.setMenu(wm_menu);
_wm.setHostname(_hostname);
@@ -94,7 +91,7 @@ void WifiDevice::initialize()
bool res = false;
bool connectedFromPortal = false;
if(_startAp)
{
Log->println(F("Opening Wi-Fi configuration portal."));
@@ -119,7 +116,7 @@ void WifiDevice::initialize()
else {
Log->print(F("Wi-Fi connected: "));
Log->println(WiFi.localIP().toString());
if(connectedFromPortal)
{
Log->println(F("Connected using WifiManager portal. Wait for ESP restart."));
@@ -160,37 +157,39 @@ bool WifiDevice::isConnected()
ReconnectStatus WifiDevice::reconnect(bool force)
{
_wm.setFindBestRSSI(_preferences->getBool(preference_find_best_rssi));
if((!isConnected() || force) && !_isReconnecting)
{
_isReconnecting = true;
WiFi.disconnect();
int loop = 0;
while(isConnected() && loop <20)
{
delay(100);
loop++;
}
_wm.resetScan();
_wm.autoConnect();
_isReconnecting = false;
}
if(!isConnected() && _disconnectTs > (esp_timer_get_time() / 1000) - 120000) _wm.setEnableConfigPortal(_startAp || !_wifiFallbackDisabled);
if(!isConnected() && _disconnectTs > (esp_timer_get_time() / 1000) - 120000) _wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled, false));
return isConnected() ? ReconnectStatus::Success : ReconnectStatus::Failure;
}
void WifiDevice::onConnected()
{
_isReconnecting = false;
_wm.setEnableConfigPortal(_startAp || !_wifiFallbackDisabled);
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled, false));
}
void WifiDevice::onDisconnected()
{
_disconnectTs = (esp_timer_get_time() / 1000);
if(_restartOnDisconnect && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
_wm.setEnableConfigPortal(false);
reconnect();
}

View File

@@ -38,10 +38,8 @@ private:
WiFiManager _wm;
Preferences* _preferences = nullptr;
bool _restartOnDisconnect = false;
bool _startAp = false;
bool _isReconnecting = false;
bool _wifiFallbackDisabled = false;
char* _path;
int64_t _disconnectTs = 0;