From 7973fd84f1b50e63cdf3990041f192216822d19a Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Wed, 25 Jun 2025 11:23:13 +0200 Subject: [PATCH] Revert disable OTA & optional Arduino OTA - new compile flag WLED_ENABLE_AOTA - modify WLED_CONNECTED macro - bugfix in Network isConnected() when static IP is set --- wled00/src/dependencies/network/Network.cpp | 8 ++------ wled00/wled.cpp | 22 +++++++++++---------- wled00/wled.h | 15 +++++--------- wled00/wled_server.cpp | 20 +++++++++++++++---- wled00/xml.cpp | 2 +- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/wled00/src/dependencies/network/Network.cpp b/wled00/src/dependencies/network/Network.cpp index d86bf127f..dbc270788 100644 --- a/wled00/src/dependencies/network/Network.cpp +++ b/wled00/src/dependencies/network/Network.cpp @@ -73,17 +73,13 @@ void NetworkClass::localMAC(uint8_t* MAC) bool NetworkClass::isConnected() { -#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET) - return (WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED) || ETH.localIP()[0] != 0; -#else - return (WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED); -#endif + return (WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED) || isEthernet(); } bool NetworkClass::isEthernet() { #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET) - return (ETH.localIP()[0] != 0); + return (ETH.localIP()[0] != 0) && ETH.linkUp(); #endif return false; } diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 63af7c2b8..4f8e79916 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -1,7 +1,10 @@ #define WLED_DEFINE_GLOBAL_VARS //only in one source file, wled.cpp! #include "wled.h" #include "wled_ethernet.h" -#include +#ifdef WLED_ENABLE_AOTA + #define NO_OTA_PORT + #include +#endif #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DISABLE_BROWNOUT_DET) #include "soc/soc.h" @@ -105,8 +108,8 @@ void WLED::loop() if (!realtimeMode || realtimeOverride || (realtimeMode && useMainSegmentOnly)) // block stuff if WARLS/Adalight is enabled { if (apActive) dnsServer.processNextRequest(); - #ifndef WLED_DISABLE_OTA - if (WLED_CONNECTED && aOtaEnabled && !otaLock && correctPIN) ArduinoOTA.handle(); + #ifdef WLED_ENABLE_AOTA + if (Network.isConnected() && aOtaEnabled && !otaLock && correctPIN) ArduinoOTA.handle(); #endif handleNightlight(); yield(); @@ -469,7 +472,7 @@ void WLED::setup() if (mqttClientID[0] == 0) sprintf_P(mqttClientID, PSTR("WLED-%*s"), 6, escapedMac.c_str() + 6); #endif -#ifndef WLED_DISABLE_OTA +#ifdef WLED_ENABLE_AOTA if (aOtaEnabled) { ArduinoOTA.onStart([]() { #ifdef ESP8266 @@ -709,9 +712,8 @@ void WLED::initInterfaces() alexaInit(); #endif -#ifndef WLED_DISABLE_OTA - if (aOtaEnabled) - ArduinoOTA.begin(); +#ifdef WLED_ENABLE_AOTA + if (aOtaEnabled) ArduinoOTA.begin(); #endif // Set up mDNS responder: @@ -782,7 +784,7 @@ void WLED::handleConnection() if (stac != stacO) { stacO = stac; DEBUG_PRINTF_P(PSTR("Connected AP clients: %d\n"), (int)stac); - if (!WLED_CONNECTED && wifiConfigured) { // trying to connect, but not connected + if (!Network.isConnected() && wifiConfigured) { // trying to connect, but not connected if (stac) WiFi.disconnect(); // disable search so that AP can work else @@ -857,7 +859,7 @@ void WLED::handleConnection() } // If status LED pin is allocated for other uses, does nothing -// else blink at 1Hz when WLED_CONNECTED is false (no WiFi, ?? no Ethernet ??) +// else blink at 1Hz when Network.isConnected() is false (no WiFi, ?? no Ethernet ??) // else blink at 2Hz when MQTT is enabled but not connected // else turn the status LED off #if defined(STATUSLED) @@ -871,7 +873,7 @@ void WLED::handleStatusLED() } #endif - if (WLED_CONNECTED) { + if (Network.isConnected()) { c = RGBW32(0,255,0,0); ledStatusType = 2; } else if (WLED_MQTT_CONNECTED) { diff --git a/wled00/wled.h b/wled00/wled.h index 52bb2f936..318bf9890 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -21,6 +21,9 @@ // You are required to disable over-the-air updates: //#define WLED_DISABLE_OTA // saves 14kb +#ifdef WLED_ENABLE_AOTA + #undef WLED_DISABLE_OTA +#endif // You can choose some of these features to disable: //#define WLED_DISABLE_ALEXA // saves 11kb @@ -121,10 +124,6 @@ #endif #include #include -#ifndef WLED_DISABLE_OTA - #define NO_OTA_PORT - #include -#endif #include #include "src/dependencies/time/TimeLib.h" #include "src/dependencies/timezone/Timezone.h" @@ -588,7 +587,7 @@ WLED_GLOBAL bool otaLock _INIT(true); // prevents OTA firmware update WLED_GLOBAL bool otaLock _INIT(false); // prevents OTA firmware updates without password. ALWAYS enable if system exposed to any public networks #endif WLED_GLOBAL bool wifiLock _INIT(false); // prevents access to WiFi settings when OTA lock is enabled -#ifndef WLED_DISABLE_OTA +#ifdef WLED_ENABLE_AOTA WLED_GLOBAL bool aOtaEnabled _INIT(true); // ArduinoOTA allows easy updates directly from the IDE. Careful, it does not auto-disable when OTA lock is on #else WLED_GLOBAL bool aOtaEnabled _INIT(false); // ArduinoOTA allows easy updates directly from the IDE. Careful, it does not auto-disable when OTA lock is on @@ -1024,11 +1023,7 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0); WLED_GLOBAL unsigned loops _INIT(0); #endif -#ifdef ARDUINO_ARCH_ESP32 - #define WLED_CONNECTED (WiFi.status() == WL_CONNECTED || ETH.localIP()[0] != 0) -#else - #define WLED_CONNECTED (WiFi.status() == WL_CONNECTED) -#endif +#define WLED_CONNECTED (Network.isConnected()) #ifndef WLED_AP_SSID_UNIQUE #define WLED_SET_AP_SSID() do { \ diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 4434a2f3e..5fb36e577 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -1,9 +1,11 @@ #include "wled.h" -#ifdef ESP8266 - #include -#else - #include +#ifndef WLED_DISABLE_OTA + #ifdef ESP8266 + #include + #else + #include + #endif #endif #include "html_ui.h" #include "html_settings.h" @@ -387,6 +389,7 @@ void initServer() createEditHandler(correctPIN); static const char _update[] PROGMEM = "/update"; +#ifndef WLED_DISABLE_OTA //init ota page server.on(_update, HTTP_GET, [](AsyncWebServerRequest *request){ if (otaLock) { @@ -446,6 +449,13 @@ void initServer() } } }); +#else + const auto notSupported = [](AsyncWebServerRequest *request){ + serveMessage(request, 501, FPSTR(s_notimplemented), F("This build does not support OTA update."), 254); + }; + server.on(_update, HTTP_GET, notSupported); + server.on(_update, HTTP_POST, notSupported); +#endif #ifdef WLED_ENABLE_DMX server.on(F("/dmxmap"), HTTP_GET, [](AsyncWebServerRequest *request){ @@ -657,6 +667,7 @@ void serveSettings(AsyncWebServerRequest* request, bool post) { case SUBPAGE_DMX : content = PAGE_settings_dmx; len = PAGE_settings_dmx_length; break; #endif case SUBPAGE_UM : content = PAGE_settings_um; len = PAGE_settings_um_length; break; +#ifndef WLED_DISABLE_OTA case SUBPAGE_UPDATE : content = PAGE_update; len = PAGE_update_length; #ifdef ARDUINO_ARCH_ESP32 if (request->hasArg(F("revert")) && inLocalSubnet(request->client()->remoteIP()) && Update.canRollBack()) { @@ -670,6 +681,7 @@ void serveSettings(AsyncWebServerRequest* request, bool post) { } #endif break; +#endif #ifndef WLED_DISABLE_2D case SUBPAGE_2D : content = PAGE_settings_2D; len = PAGE_settings_2D_length; break; #endif diff --git a/wled00/xml.cpp b/wled00/xml.cpp index f821f86fb..934bcc60b 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -596,7 +596,7 @@ void getSettingsJS(byte subPage, Print& settingsScript) snprintf_P(tmp_buf,sizeof(tmp_buf),PSTR("WLED %s (build %d)"),versionString,VERSION); printSetClassElementHTML(settingsScript,PSTR("sip"),0,tmp_buf); settingsScript.printf_P(PSTR("sd=\"%s\";"), serverDescription); - #ifdef WLED_DISABLE_OTA + #ifndef WLED_ENABLE_AOTA //hide settings if not compiled settingsScript.print(F("toggle('aOTA');")); // hide ArduinoOTA checkbox #endif