fix(network): set ethernet hostname before startup

This commit is contained in:
agessaman committed 2026-09-03 20:47:00 -07:00
1 parent 0c65fc79db
commit fc528ae640
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);