fix dns name being set to "tasmota"

This commit is contained in:
proddy
2026-04-18 19:42:45 +02:00
parent 86a20fc97a
commit 1d33a26318
2 changed files with 10 additions and 4 deletions

View File

@@ -80,11 +80,11 @@ void NetworkSettingsService::loop() {
case CONNECT_IDLE:
if (ETH.started() && _state.ssid.length() == 0) {
emsesp::EMSESP::logger().info("ETH started");
ETH.setHostname(emsesp::EMSESP::system_.hostname().c_str());
ETH.enableIPv6(true);
if (_state.staticIPConfig) {
ETH.config(_state.localIP, _state.gatewayIP, _state.subnetMask, _state.dnsIP1, _state.dnsIP2);
}
ETH.setHostname(emsesp::EMSESP::system_.hostname().c_str());
connect = CONNECT_WAIT_ETH;
}
if (WiFi.isConnected()) {
@@ -173,11 +173,13 @@ void NetworkSettingsService::manageSTA() {
// Connect or reconnect as required
if ((WiFi.getMode() & WIFI_STA) == 0) {
WiFi.setHostname(_state.hostname.c_str()); // updates shared default_hostname buffer
WiFi.enableSTA(true); // creates the STA netif
WiFi.STA.setHostname(_state.hostname.c_str()); // pushes to esp_netif_set_hostname
WiFi.enableIPv6(true);
if (_state.staticIPConfig) {
WiFi.config(_state.localIP, _state.gatewayIP, _state.subnetMask, _state.dnsIP1, _state.dnsIP2); // configure for static IP
}
WiFi.setHostname(_state.hostname.c_str()); // set hostname
// www.esp32.com/viewtopic.php?t=12055
if (_state.bandwidth20) {
@@ -419,11 +421,11 @@ void NetworkSettingsService::WiFiEvent(arduino_event_id_t event, arduino_event_i
break;
case ARDUINO_EVENT_ETH_START:
// configure for static IP
// apply hostname FIRST so DHCP DISCOVER carries the correct name
ETH.setHostname(emsesp::EMSESP::system_.hostname().c_str());
if (_state.staticIPConfig) {
ETH.config(_state.localIP, _state.gatewayIP, _state.subnetMask, _state.dnsIP1, _state.dnsIP2);
}
ETH.setHostname(emsesp::EMSESP::system_.hostname().c_str());
break;
case ARDUINO_EVENT_ETH_GOT_IP:

View File

@@ -1061,6 +1061,10 @@ void System::network_init() {
digitalWrite(eth_power_, HIGH);
}
eth_present_ = ETH.begin(type, phy_addr, mdc, mdio, power, clock_mode);
if (eth_present_) {
// Push hostname to the ETH netif immediately after it's created
ETH.setHostname(hostname_.c_str());
}
#endif
}