check NTP host resolves before updating config

master
Kenneth Barbour 2020-06-18 22:37:40 -04:00
parent 9b43bbcdb3
commit 7f9f6595e9
2 changed files with 7 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include "config.h"
#include "time.h"
#include <Arduino.h>
#include <EEPROM.h>
@ -103,6 +104,7 @@ bool cUWeatherConfig::setNTPHost(const char* buff)
{
if (strlen(buff) >= 32) return false;
strncpy((char*)_data.ntp_host, buff, 32);
uweather_time_init(); // restart time
return true;
}

View File

@ -182,6 +182,11 @@ void handle_config_set(HttpRequest& req, HttpResponse& res)
} else if (strcmp("mdns_hostname", key) == 0) {
result = Config.setMDNSHostname(value);
} else if (strcmp("ntp_host", key) == 0) {
IPAddress ntp_host_addr;
if (value[0] != '\0' && !WiFi.hostByName(value, ntp_host_addr)) {
client_error("Unable to resolve host", res);
return;
}
result = Config.setNTPHost(value);
} else if (strcmp("mqtt_host", key) == 0) {
result = Config.setMQTTHost(value);