From 7f9f6595e9e01bae9059115b8b121c4e7df9a317 Mon Sep 17 00:00:00 2001 From: Kenneth Barbour Date: Thu, 18 Jun 2020 22:37:40 -0400 Subject: [PATCH] check NTP host resolves before updating config --- src/config.cpp | 2 ++ src/web.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/config.cpp b/src/config.cpp index bab4da5..382adc3 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1,4 +1,5 @@ #include "config.h" +#include "time.h" #include #include @@ -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; } diff --git a/src/web.cpp b/src/web.cpp index 59ff0ed..e4aca1c 100644 --- a/src/web.cpp +++ b/src/web.cpp @@ -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);