From ad51870d2cf8b57f209aef9304f134f4713b195f Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Tue, 24 Oct 2023 21:54:57 +0200 Subject: [PATCH] no wifi disconnect until reboot on ssid cleared --- lib/PButton/PButon.cpp | 3 ++- lib/framework/HttpEndpoint.h | 3 +-- lib/framework/NetworkSettingsService.cpp | 8 +++++++- lib/framework/NetworkSettingsService.h | 3 ++- platformio.ini | 1 + src/devices/boiler.cpp | 4 ++++ src/system.cpp | 21 +++++++++++---------- src/web/WebStatusService.cpp | 13 +++++++++++-- 8 files changed, 39 insertions(+), 17 deletions(-) diff --git a/lib/PButton/PButon.cpp b/lib/PButton/PButon.cpp index 28eb41f0f..dfbf4f898 100644 --- a/lib/PButton/PButon.cpp +++ b/lib/PButton/PButon.cpp @@ -46,6 +46,7 @@ PButton::PButton() { longPressHappened_ = false; // whether or not the hold event happened already vLongPressHappened_ = false; // whether or not the long hold event happened already buttonBusy_ = false; // idle + pin_ = 255; // undefined } bool PButton::init(uint8_t pin, bool pullMode) { @@ -83,7 +84,7 @@ void PButton::onVLongPress(uint16_t t, buttonEventHandler handler) { } bool PButton::check(void) { - if (!enabled_) { + if (!enabled_ || pin_ == 255) { return false; } diff --git a/lib/framework/HttpEndpoint.h b/lib/framework/HttpEndpoint.h index 448d36b46..926a6f772 100644 --- a/lib/framework/HttpEndpoint.h +++ b/lib/framework/HttpEndpoint.h @@ -112,11 +112,10 @@ class HttpPostEndpoint { AsyncJsonResponse * response = new AsyncJsonResponse(false, _bufferSize); jsonObject = response->getRoot().to(); _statefulService->read(jsonObject, _stateReader); - response->setLength(); - if (outcome == StateUpdateResult::CHANGED_RESTART) { response->setCode(205); // reboot required } + response->setLength(); request->send(response); } }; diff --git a/lib/framework/NetworkSettingsService.cpp b/lib/framework/NetworkSettingsService.cpp index b5795648b..0cf7d6d55 100644 --- a/lib/framework/NetworkSettingsService.cpp +++ b/lib/framework/NetworkSettingsService.cpp @@ -28,10 +28,16 @@ void NetworkSettingsService::begin() { WiFi.onEvent(std::bind(&NetworkSettingsService::WiFiEvent, this, _1)); _fsPersistence.readFromFS(); - reconfigureWiFiConnection(); + // reconfigureWiFiConnection(); + _lastConnectionAttempt = 0; + _stopping = false; } void NetworkSettingsService::reconfigureWiFiConnection() { + // do not disconnect for switching to eth, restart is needed + if (WiFi.isConnected() && _state.ssid.length() == 0) { + return; + } // disconnect and de-configure wifi if (WiFi.disconnect(true)) { _stopping = true; diff --git a/lib/framework/NetworkSettingsService.h b/lib/framework/NetworkSettingsService.h index 12c2ef745..901345ea9 100644 --- a/lib/framework/NetworkSettingsService.h +++ b/lib/framework/NetworkSettingsService.h @@ -76,6 +76,7 @@ class NetworkSettings { static StateUpdateResult update(JsonObject & root, NetworkSettings & settings) { auto enableCORS = settings.enableCORS; auto CORSOrigin = settings.CORSOrigin; + auto ssid = settings.ssid; settings.ssid = root["ssid"] | FACTORY_WIFI_SSID; settings.bssid = root["bssid"] | ""; settings.password = root["password"] | FACTORY_WIFI_PASSWORD; @@ -108,7 +109,7 @@ class NetworkSettings { if (settings.staticIPConfig && (IPUtils::isNotSet(settings.localIP) || IPUtils::isNotSet(settings.gatewayIP) || IPUtils::isNotSet(settings.subnetMask))) { settings.staticIPConfig = false; } - if (enableCORS != settings.enableCORS || CORSOrigin != settings.CORSOrigin) { + if (enableCORS != settings.enableCORS || CORSOrigin != settings.CORSOrigin || (ssid != settings.ssid && settings.ssid == "")) { return StateUpdateResult::CHANGED_RESTART; // tell WebUI that a restart is needed } diff --git a/platformio.ini b/platformio.ini index 42913051b..088b2ef48 100644 --- a/platformio.ini +++ b/platformio.ini @@ -111,6 +111,7 @@ build_flags = ${common.build_flags} [env:esp32_16M] extends = espressi32_base_tasmota board = esp32dev +board_build.extra_flags = -DBOARD_HAS_PSRAM board_upload.flash_size = 16MB board_build.partitions = esp32_partition_16M.csv build_flags = ${common.build_flags} diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index 4495228b8..307efcb62 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -1100,6 +1100,10 @@ void Boiler::process_UBAMonitorFast(std::shared_ptr telegram) { */ void Boiler::process_UBATotalUptime(std::shared_ptr telegram) { has_update(telegram, UBAuptime_, 0, 3); // force to 3 bytes + // if broadcasted there is no need to fetch + if (telegram->dest == 0) { + toggle_fetch(0x14, false); + } } /* diff --git a/src/system.cpp b/src/system.cpp index 4746ac810..dda114816 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -385,7 +385,7 @@ void System::wifi_tweak() { } // check for valid ESP32 pins. This is very dependent on which ESP32 board is being used. -// Typically you can't use 1, 6-11, 12, 14, 15, 20, 24, 28-31 and 40+ +// Typically you can't use 1, 6-11, 20, 24, 28-31 and 40+ // we allow 0 as it has a special function on the NodeMCU apparently // See https://diyprojects.io/esp32-how-to-use-gpio-digital-io-arduino-code/#.YFpVEq9KhjG // and https://nodemcu.readthedocs.io/en/dev-esp32/modules/gpio/ @@ -475,15 +475,16 @@ void System::button_init(bool refresh) { reload_settings(); } - if (is_valid_gpio(pbutton_gpio_)) { - if (!myPButton_.init(pbutton_gpio_, HIGH)) { - LOG_DEBUG("Multi-functional button not detected"); - } else { - LOG_DEBUG("Multi-functional button enabled"); - } - } else { + if (!is_valid_gpio(pbutton_gpio_)) { LOG_WARNING("Invalid button GPIO. Check config."); + myPButton_.init(255, HIGH); // disable + return; } + if (!myPButton_.init(pbutton_gpio_, HIGH)) { + LOG_WARNING("Multi-functional button not detected"); + return; + } + LOG_DEBUG("Multi-functional button enabled"); myPButton_.onClick(BUTTON_Debounce, button_OnClick); myPButton_.onDblClick(BUTTON_DblClickDelay, button_OnDblClick); @@ -1064,7 +1065,7 @@ bool System::check_upgrade(bool factory_settings) { // see if we're missing a version, will be < 3.5.0b13 from Dec 23 2022 missing_version = (settingsVersion.empty() || (settingsVersion.length() < 5)); if (missing_version) { - LOG_DEBUG("No version information found (%s)", settingsVersion.c_str()); + LOG_WARNING("No version information found (%s)", settingsVersion.c_str()); settingsVersion = "3.6.2"; // this was the last stable version } } @@ -1441,7 +1442,7 @@ bool System::load_board_profile(std::vector & data, const std::string & } else if (board_profile == "E32") { data = {2, 4, 5, 17, 33, PHY_type::PHY_TYPE_LAN8720, 16, 1, 0}; // BBQKees Gateway E32 } else if (board_profile == "E32V2") { - data = {2, 14, 4, 5, 0, PHY_type::PHY_TYPE_LAN8720, 15, 0, 1}; // BBQKees Gateway E32 V2 + data = {2, 14, 4, 5, 12, PHY_type::PHY_TYPE_LAN8720, 15, 0, 1}; // BBQKees Gateway E32 V2 } else if (board_profile == "MH-ET") { data = {2, 18, 23, 5, 0, PHY_type::PHY_TYPE_NONE, 0, 0, 0}; // MH-ET Live D1 Mini } else if (board_profile == "NODEMCU") { diff --git a/src/web/WebStatusService.cpp b/src/web/WebStatusService.cpp index f27c0c3d7..06714343b 100644 --- a/src/web/WebStatusService.cpp +++ b/src/web/WebStatusService.cpp @@ -36,8 +36,7 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) { switch (event) { case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: - EMSESP::logger().warning("WiFi disconnected. Reason code=%s", disconnectReason(info.wifi_sta_disconnected.reason)); // IDF 4.0 - // WiFi.disconnect(true); // this is done in NetworkSettingsService + EMSESP::logger().warning("WiFi disconnected. Reason: %s (%d)", disconnectReason(info.wifi_sta_disconnected.reason), info.wifi_sta_disconnected.reason); // IDF 4.0 EMSESP::system_.has_ipv6(false); break; @@ -282,6 +281,16 @@ const char * WebStatusService::disconnectReason(uint8_t code) { return "assoc fail"; case WIFI_REASON_HANDSHAKE_TIMEOUT: // = 204, return "handshake timeout"; + case WIFI_REASON_CONNECTION_FAIL: // 205, + return "connection fail"; + case WIFI_REASON_AP_TSF_RESET: // 206, + return "AP tsf reset"; + case WIFI_REASON_ROAMING: // 207, + return "roaming"; + case WIFI_REASON_ASSOC_COMEBACK_TIME_TOO_LONG: // 208, + return "assoc comeback time too long"; + case WIFI_REASON_SA_QUERY_TIMEOUT: // 209, + return "sa query timeout"; default: return "unknown"; }