forked from rjwats/esp8266-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNTPStatus.cpp
More file actions
30 lines (25 loc) · 1.04 KB
/
Copy pathNTPStatus.cpp
File metadata and controls
30 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <NTPStatus.h>
NTPStatus::NTPStatus(AsyncWebServer *server, SecurityManager* securityManager) : _server(server), _securityManager(securityManager) {
_server->on(NTP_STATUS_SERVICE_PATH, HTTP_GET,
_securityManager->wrapRequest(std::bind(&NTPStatus::ntpStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)
);
}
void NTPStatus::ntpStatus(AsyncWebServerRequest *request) {
AsyncJsonResponse * response = new AsyncJsonResponse(MAX_NTP_STATUS_SIZE);
JsonObject root = response->getRoot();
// request time now first, this can sometimes force a sync
time_t timeNow = now();
timeStatus_t status = timeStatus();
time_t lastSync = NTP.getLastNTPSync();
root["status"] = (int) status;
root["last_sync"] = lastSync;
root["server"] = NTP.getNtpServerName();
root["interval"] = NTP.getInterval();
root["uptime"] = NTP.getUptime();
// only add now to response if we have successfully synced
if (status != timeNotSet){
root["now"] = timeNow;
}
response->setLength();
request->send(response);
}