2018-02-26 00:11:31 +00:00
|
|
|
#include <NTPStatus.h>
|
|
|
|
|
2019-09-28 20:29:46 +00:00
|
|
|
NTPStatus::NTPStatus(AsyncWebServer* server, SecurityManager* securityManager) {
|
2019-07-14 21:13:26 +00:00
|
|
|
server->on(NTP_STATUS_SERVICE_PATH, HTTP_GET,
|
2019-09-28 20:29:46 +00:00
|
|
|
securityManager->wrapRequest(std::bind(&NTPStatus::ntpStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)
|
2019-05-31 18:58:33 +00:00
|
|
|
);
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NTPStatus::ntpStatus(AsyncWebServerRequest *request) {
|
2019-04-14 07:52:40 +00:00
|
|
|
AsyncJsonResponse * response = new AsyncJsonResponse(MAX_NTP_STATUS_SIZE);
|
|
|
|
JsonObject root = response->getRoot();
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|