fix(network): set ethernet hostname before startup

This commit is contained in:
agessaman committed 2026-09-03 20:47:00 -07:00
1 parent 17409e56a0
commit 2c21406380
2 files changed
+4 -20

No files matched your search

+3 -19
View File
@@ -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);
+1 -1
View File
@@ -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