fix(network): set ethernet hostname before startup
This commit is contained in:
1 parent
0c65fc79db
commit
fc528ae640
2 files changed
+4
-20
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user