NetworkSettings: Optimize setHostname function

Also replace all print and println by printf
This commit is contained in:
Thomas Basler
2025-04-12 10:45:01 +02:00
parent 0dcf3c5902
commit 852649fd86

View File

@@ -298,25 +298,26 @@ void NetworkSettingsClass::applyConfig()
void NetworkSettingsClass::setHostname() void NetworkSettingsClass::setHostname()
{ {
MessageOutput.print("Setting Hostname... "); if (_networkMode == network_mode::Undefined) {
return;
}
const String hostname = getHostname();
bool success = false;
MessageOutput.printf("Start setting hostname...\r\n");
if (_networkMode == network_mode::WiFi) { if (_networkMode == network_mode::WiFi) {
if (WiFi.hostname(getHostname())) { success = WiFi.hostname(hostname);
MessageOutput.println("done");
} else {
MessageOutput.println("failed");
}
// Evil bad hack to get the hostname set up correctly // Evil bad hack to get the hostname set up correctly
WiFi.mode(WIFI_MODE_APSTA); WiFi.mode(WIFI_MODE_APSTA);
WiFi.mode(WIFI_MODE_STA); WiFi.mode(WIFI_MODE_STA);
setupMode(); setupMode();
} else if (_networkMode == network_mode::Ethernet) { } else if (_networkMode == network_mode::Ethernet) {
if (ETH.setHostname(getHostname().c_str())) { success = ETH.setHostname(hostname.c_str());
MessageOutput.println("done");
} else {
MessageOutput.println("failed");
}
} }
MessageOutput.printf("Setting hostname %s\r\n", success ? "done" : "failed");
} }
void NetworkSettingsClass::setStaticIp() void NetworkSettingsClass::setStaticIp()