From 2c21406380c76400a3867d3b79dd8c9265c66e4f Mon Sep 17 00:00:00 2001 From: agessaman Date: Thu, 3 Sep 2026 18:36:43 -0700 Subject: [PATCH] fix(network): set ethernet hostname before startup --- src/helpers/ethernet/ch390/CH390Config.h | 22 +++------------------- variants/thinknode_m7/platformio.ini | 2 +- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/helpers/ethernet/ch390/CH390Config.h b/src/helpers/ethernet/ch390/CH390Config.h index 30f110bf..656603ba 100644 --- a/src/helpers/ethernet/ch390/CH390Config.h +++ b/src/helpers/ethernet/ch390/CH390Config.h @@ -14,29 +14,13 @@ static inline bool beginConfiguredCH390(const char* hostname = nullptr) { config.spi_sck_gpio = ETH_SCLK_PIN; config.spi_cs_gpio = ETH_CS_PIN; config.int_gpio = ETH_INT_PIN; - if (!CH390.begin(config)) return false; - if (hostname && hostname[0] != '\0') { -#if !(defined(ETHERNET_STATIC_IP) && defined(ETHERNET_STATIC_GATEWAY) && defined(ETHERNET_STATIC_SUBNET)) - // ESP32-CH390 creates and starts its esp_netif inside begin(), so its - // setHostname() cannot be called earlier. Stop the just-created DHCP - // client, apply the name to that exact Ethernet netif, then start a fresh - // DHCP transaction. This prevents a fast wired link from retaining the - // ESP-IDF default hostname for its initial lease. - const bool dhcp_stopped = CH390.disableDHCP(); - const bool hostname_set = CH390.setHostname(hostname); - const bool dhcp_started = CH390.enableDHCP(); - if (!dhcp_stopped || !hostname_set || !dhcp_started) { - Serial.printf("Network: could not fully apply Ethernet hostname %s\n", - hostname); - } -#else if (!CH390.setHostname(hostname)) { - Serial.printf("Network: could not apply Ethernet hostname %s\n", - hostname); + Serial.printf("Network: invalid Ethernet hostname %s\n", hostname); + return false; } -#endif } + if (!CH390.begin(config)) return false; #if defined(ETHERNET_STATIC_IP) && defined(ETHERNET_STATIC_GATEWAY) && defined(ETHERNET_STATIC_SUBNET) IPAddress ip(ETHERNET_STATIC_IP); diff --git a/variants/thinknode_m7/platformio.ini b/variants/thinknode_m7/platformio.ini index 890faee2..fa9a0140 100644 --- a/variants/thinknode_m7/platformio.ini +++ b/variants/thinknode_m7/platformio.ini @@ -47,7 +47,7 @@ build_flags = -D ETH_INT_PIN=45 -D ETHERNET_DEBUG_LOGGING=1 lib_deps = - https://github.com/liamcottle/ESP32-CH390.git#47b401f1de546118b03c18b5689dedec45871f2d + https://github.com/agessaman/ESP32-CH390.git#55c425705d9b21df11f95782ae6408707b2a91a9 ; Existing companion/CLI transport overlay. MQTT Ethernet observers consume the ; CH390 fragment above without ETHERNET_ENABLED, whose meaning in the simple