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.

60 lines
1.5 KiB

  1. #ifndef NTPSettingsService_h
  2. #define NTPSettingsService_h
  3. #include <SettingsService.h>
  4. #include <TimeLib.h>
  5. #include <NtpClientLib.h>
  6. // default time server
  7. #define NTP_SETTINGS_SERVICE_DEFAULT_SERVER "pool.ntp.org"
  8. #define NTP_SETTINGS_SERVICE_DEFAULT_INTERVAL 3600
  9. // min poll delay of 60 secs, max 1 day
  10. #define NTP_SETTINGS_MIN_INTERVAL 60
  11. #define NTP_SETTINGS_MAX_INTERVAL 86400
  12. #define NTP_SETTINGS_FILE "/config/ntpSettings.json"
  13. #define NTP_SETTINGS_SERVICE_PATH "/rest/ntpSettings"
  14. class NTPSettingsService : public AdminSettingsService {
  15. public:
  16. NTPSettingsService(FS* fs, SecurityManager* securityManager);
  17. ~NTPSettingsService();
  18. void loop();
  19. protected:
  20. void readFromJsonObject(JsonObject& root);
  21. void writeToJsonObject(JsonObject& root);
  22. void onConfigUpdated();
  23. private:
  24. String _server;
  25. int _interval;
  26. bool _reconfigureNTP = false;
  27. bool _syncEventTriggered = false;
  28. NTPSyncEvent_t _ntpEvent;
  29. #if defined(ESP8266)
  30. WiFiEventHandler _onStationModeDisconnectedHandler;
  31. WiFiEventHandler _onStationModeGotIPHandler;
  32. void onStationModeGotIP(const WiFiEventStationModeGotIP& event);
  33. void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
  34. #elif defined(ESP_PLATFORM)
  35. void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
  36. void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);
  37. #endif
  38. void configureNTP();
  39. void processSyncEvent(NTPSyncEvent_t ntpEvent);
  40. };
  41. #endif // end NTPSettingsService_h