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.

61 lines
1.6 KiB

  1. #ifndef NTPSettingsService_h
  2. #define NTPSettingsService_h
  3. #include <AdminSettingsService.h>
  4. #include <time.h>
  5. #ifdef ESP32
  6. #include <lwip/apps/sntp.h>
  7. #elif defined(ESP8266)
  8. #include <sntp.h>
  9. #endif
  10. // default time zone
  11. #define NTP_SETTINGS_SERVICE_DEFAULT_ENABLED true
  12. #define NTP_SETTINGS_SERVICE_DEFAULT_TIME_ZONE_LABEL "Europe/London"
  13. #define NTP_SETTINGS_SERVICE_DEFAULT_TIME_ZONE_FORMAT "GMT0BST,M3.5.0/1,M10.5.0"
  14. #define NTP_SETTINGS_SERVICE_DEFAULT_SERVER "time.google.com"
  15. // min poll delay of 60 secs, max 1 day
  16. #define NTP_SETTINGS_MIN_INTERVAL 60
  17. #define NTP_SETTINGS_MAX_INTERVAL 86400
  18. #define NTP_SETTINGS_FILE "/config/ntpSettings.json"
  19. #define NTP_SETTINGS_SERVICE_PATH "/rest/ntpSettings"
  20. class NTPSettingsService : public AdminSettingsService {
  21. public:
  22. NTPSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
  23. ~NTPSettingsService();
  24. void loop();
  25. protected:
  26. void readFromJsonObject(JsonObject& root);
  27. void writeToJsonObject(JsonObject& root);
  28. void onConfigUpdated();
  29. void receivedNTPtime();
  30. private:
  31. bool _enabled;
  32. String _tzLabel;
  33. String _tzFormat;
  34. String _server;
  35. bool _reconfigureNTP = false;
  36. #ifdef ESP32
  37. void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
  38. void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);
  39. #elif defined(ESP8266)
  40. WiFiEventHandler _onStationModeDisconnectedHandler;
  41. WiFiEventHandler _onStationModeGotIPHandler;
  42. void onStationModeGotIP(const WiFiEventStationModeGotIP& event);
  43. void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
  44. #endif
  45. void configureNTP();
  46. };
  47. #endif // end NTPSettingsService_h