check NTP host resolves before updating config
parent
9b43bbcdb3
commit
7f9f6595e9
|
@ -1,4 +1,5 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "time.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
|
@ -103,6 +104,7 @@ bool cUWeatherConfig::setNTPHost(const char* buff)
|
||||||
{
|
{
|
||||||
if (strlen(buff) >= 32) return false;
|
if (strlen(buff) >= 32) return false;
|
||||||
strncpy((char*)_data.ntp_host, buff, 32);
|
strncpy((char*)_data.ntp_host, buff, 32);
|
||||||
|
uweather_time_init(); // restart time
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,11 @@ void handle_config_set(HttpRequest& req, HttpResponse& res)
|
||||||
} else if (strcmp("mdns_hostname", key) == 0) {
|
} else if (strcmp("mdns_hostname", key) == 0) {
|
||||||
result = Config.setMDNSHostname(value);
|
result = Config.setMDNSHostname(value);
|
||||||
} else if (strcmp("ntp_host", key) == 0) {
|
} 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);
|
result = Config.setNTPHost(value);
|
||||||
} else if (strcmp("mqtt_host", key) == 0) {
|
} else if (strcmp("mqtt_host", key) == 0) {
|
||||||
result = Config.setMQTTHost(value);
|
result = Config.setMQTTHost(value);
|
||||||
|
|
Loading…
Reference in New Issue