Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1010 B

  1. #include <NTPStatus.h>
  2. NTPStatus::NTPStatus(AsyncWebServer* server, SecurityManager* securityManager) {
  3. server->on(NTP_STATUS_SERVICE_PATH, HTTP_GET,
  4. securityManager->wrapRequest(std::bind(&NTPStatus::ntpStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)
  5. );
  6. }
  7. void NTPStatus::ntpStatus(AsyncWebServerRequest *request) {
  8. AsyncJsonResponse * response = new AsyncJsonResponse(MAX_NTP_STATUS_SIZE);
  9. JsonObject root = response->getRoot();
  10. // request time now first, this can sometimes force a sync
  11. time_t timeNow = now();
  12. timeStatus_t status = timeStatus();
  13. time_t lastSync = NTP.getLastNTPSync();
  14. root["status"] = (int) status;
  15. root["last_sync"] = lastSync;
  16. root["server"] = NTP.getNtpServerName();
  17. root["interval"] = NTP.getInterval();
  18. root["uptime"] = NTP.getUptime();
  19. // only add now to response if we have successfully synced
  20. if (status != timeNotSet){
  21. root["now"] = timeNow;
  22. }
  23. response->setLength();
  24. request->send(response);
  25. }