mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2025-12-13 02:09:58 +01:00
NetworkSettings: Optimize setHostname function
Also replace all print and println by printf
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user