2018-02-26 00:11:31 +00:00
|
|
|
#ifndef NTPSettingsService_h
|
|
|
|
#define NTPSettingsService_h
|
|
|
|
|
2019-08-10 11:35:26 +00:00
|
|
|
#include <AdminSettingsService.h>
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
#include <TimeLib.h>
|
|
|
|
#include <NtpClientLib.h>
|
|
|
|
|
|
|
|
// default time server
|
|
|
|
#define NTP_SETTINGS_SERVICE_DEFAULT_SERVER "pool.ntp.org"
|
|
|
|
#define NTP_SETTINGS_SERVICE_DEFAULT_INTERVAL 3600
|
|
|
|
|
|
|
|
// min poll delay of 60 secs, max 1 day
|
|
|
|
#define NTP_SETTINGS_MIN_INTERVAL 60
|
|
|
|
#define NTP_SETTINGS_MAX_INTERVAL 86400
|
|
|
|
|
|
|
|
#define NTP_SETTINGS_FILE "/config/ntpSettings.json"
|
2018-04-01 09:35:23 +00:00
|
|
|
#define NTP_SETTINGS_SERVICE_PATH "/rest/ntpSettings"
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-05-29 22:48:16 +00:00
|
|
|
class NTPSettingsService : public AdminSettingsService {
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-07-14 21:13:26 +00:00
|
|
|
NTPSettingsService(FS* fs, SecurityManager* securityManager);
|
2018-02-26 00:11:31 +00:00
|
|
|
~NTPSettingsService();
|
|
|
|
|
|
|
|
void loop();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void readFromJsonObject(JsonObject& root);
|
|
|
|
void writeToJsonObject(JsonObject& root);
|
|
|
|
void onConfigUpdated();
|
|
|
|
|
|
|
|
private:
|
2018-04-01 09:35:23 +00:00
|
|
|
|
2018-02-26 00:11:31 +00:00
|
|
|
String _server;
|
|
|
|
int _interval;
|
|
|
|
|
|
|
|
bool _reconfigureNTP = false;
|
|
|
|
bool _syncEventTriggered = false;
|
|
|
|
NTPSyncEvent_t _ntpEvent;
|
|
|
|
|
2018-11-11 17:47:44 +00:00
|
|
|
#if defined(ESP8266)
|
|
|
|
WiFiEventHandler _onStationModeDisconnectedHandler;
|
|
|
|
WiFiEventHandler _onStationModeGotIPHandler;
|
|
|
|
|
2018-02-26 00:11:31 +00:00
|
|
|
void onStationModeGotIP(const WiFiEventStationModeGotIP& event);
|
|
|
|
void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
|
2018-11-11 17:47:44 +00:00
|
|
|
#elif defined(ESP_PLATFORM)
|
|
|
|
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
|
|
|
void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);
|
|
|
|
#endif
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
void configureNTP();
|
|
|
|
void processSyncEvent(NTPSyncEvent_t ntpEvent);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // end NTPSettingsService_h
|