From 7df23d4e3e85c6ee8fe814e8d48321a8198e5262 Mon Sep 17 00:00:00 2001 From: Camilo Duque Date: Sat, 15 Aug 2026 14:26:44 -0500 Subject: [PATCH] [FIX] ESP32 Ethernet: make NetworkAdvancedSetup work, and skip WiFiManager when Ethernet is up (#2351) Static IP over Ethernet on ESP32 was unusable, and a fresh board with a working Ethernet link still brought up the WiFi radio. setup_ethernet_esp32() did not compile with NetworkAdvancedSetup defined: it declared ip_adress/gateway_adress/subnet_adress/dns_adress but then called fromString() on ip/gateway/subnet/Dns, which are declared nowhere. The WiFi path a few hundred lines above does the same thing correctly, so this looks like an incomplete copy of it. Once that compiles, the static IP was still ignored. ETH.config() was called before ETH.begin(), but NetworkInterface::config() returns false immediately while _esp_netif is NULL, and the netif is only created inside begin(). The call was a silent no-op and the board kept asking for DHCP. Swapping the order is safe: the client branch of config() stops the running DHCP client itself and sets the static-IP status bit. The return value is now checked and logged instead of being discarded. Separately, the "no config in flash" branch of setup() called setupWiFiManager() guarded only by !failSafeMode, while the "config loaded" branch a few lines above correctly also checks !ethConnected. So a factory-fresh board with Ethernet already up would still start the WiFi manager. Beyond being unnecessary, it powers up the 2.4GHz radio and competes with BLE on gateways that run both. Verified on an Olimex ESP32-POE-ISO: the board now takes its static address immediately with no DHCP wait, does not fall back to the WiFi manager, and reaches the broker. Formatting checked with clang-format against .clang-format. --- main/main.cpp | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index e997dae..c649710 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1451,9 +1451,13 @@ void setup() { checkSerial(); # endif - THEENGS_LOG_NOTICE(F("No config in flash, launching wifi manager" CR)); - // In failSafeMode we don't want to setup wifi manager as it has already been done before - if (!failSafeMode) setupWiFiManager(); + // In failSafeMode we don't want to setup wifi manager as it has already been done before, + // and with Ethernet already connected we don't need it at all: bringing up the WiFi radio + // would only add 2.4GHz contention with BLE. + if (!failSafeMode && !ethConnected) { + THEENGS_LOG_NOTICE(F("No config in flash, launching wifi manager" CR)); + setupWiFiManager(); + } } #endif @@ -2447,18 +2451,23 @@ void setup_ethernet_esp32() { bool ethBeginSuccess = false; WiFi.onEvent(WiFiEvent); # ifdef NetworkAdvancedSetup - IPAddress ip_adress; - IPAddress gateway_adress; - IPAddress subnet_adress; - IPAddress dns_adress; - ip.fromString(NET_IP); - gateway.fromString(NET_GW); - subnet.fromString(NET_MASK); - Dns.fromString(NET_DNS); - THEENGS_LOG_TRACE(F("Adv eth cfg" CR)); - ETH.config(ip, gateway, subnet, Dns); + // ETH.config() has to be called after ETH.begin(): the underlying netif is + // created by begin(), before that the call returns false and is a no-op. ethBeginSuccess = ETH.begin(); + if (ethBeginSuccess) { + IPAddress ip_adress; + IPAddress gateway_adress; + IPAddress subnet_adress; + IPAddress dns_adress; + ip_adress.fromString(NET_IP); + gateway_adress.fromString(NET_GW); + subnet_adress.fromString(NET_MASK); + dns_adress.fromString(NET_DNS); + if (!ETH.config(ip_adress, gateway_adress, subnet_adress, dns_adress)) { + THEENGS_LOG_ERROR(F("Adv eth cfg failed" CR)); + } + } # else THEENGS_LOG_NOTICE(F("Spl eth cfg" CR)); ethBeginSuccess = ETH.begin();