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.

28 lines
913 B

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