update ntp lib to moment

This commit is contained in:
proddy
2021-02-01 11:30:12 +01:00
parent 04e15a7337
commit 258ed874ec
7 changed files with 112 additions and 106 deletions

View File

@@ -52,10 +52,9 @@ void NTPSettingsService::configureNTP() {
void NTPSettingsService::configureTime(AsyncWebServerRequest * request, JsonVariant & json) {
if (!sntp_enabled() && json.is<JsonObject>()) {
String timeUtc = json["time_utc"];
struct tm tm = {0};
char * s = strptime(timeUtc.c_str(), "%Y-%m-%dT%H:%M:%SZ", &tm);
struct tm tm = {0};
String timeLocal = json["local_time"];
char * s = strptime(timeLocal.c_str(), "%Y-%m-%dT%H:%M:%S", &tm);
if (s != nullptr) {
time_t time = mktime(&tm);
struct timeval now = {.tv_sec = time};
@@ -65,7 +64,6 @@ void NTPSettingsService::configureTime(AsyncWebServerRequest * request, JsonVari
return;
}
}
AsyncWebServerResponse * response = request->beginResponse(400);
request->send(response);
}

View File

@@ -36,14 +36,14 @@ void NTPStatus::ntpStatus(AsyncWebServerRequest * request) {
// the current time in UTC
root["utc_time"] = toUTCTimeString(gmtime(&now));
// local time as ISO String with TZ
// local time with offset
root["local_time"] = toLocalTimeString(localtime(&now));
// the sntp server name
root["server"] = sntp_getservername(0);
// device uptime in seconds
root["uptime"] = uuid::get_uptime() / 1000;
root["uptime"] = millis() / 1000;
response->setLength();
request->send(response);