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
|
|
|
|
2020-01-20 11:14:46 +00:00
|
|
|
#include <time.h>
|
|
|
|
#ifdef ESP32
|
|
|
|
#include <lwip/apps/sntp.h>
|
|
|
|
#elif defined(ESP8266)
|
|
|
|
#include <sntp.h>
|
|
|
|
#endif
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2020-01-20 11:14:46 +00:00
|
|
|
// default time zone
|
|
|
|
#define NTP_SETTINGS_SERVICE_DEFAULT_ENABLED true
|
|
|
|
#define NTP_SETTINGS_SERVICE_DEFAULT_TIME_ZONE_LABEL "Europe/London"
|
|
|
|
#define NTP_SETTINGS_SERVICE_DEFAULT_TIME_ZONE_FORMAT "GMT0BST,M3.5.0/1,M10.5.0"
|
|
|
|
#define NTP_SETTINGS_SERVICE_DEFAULT_SERVER "time.google.com"
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2020-02-01 08:44:26 +00:00
|
|
|
class NTPSettings {
|
|
|
|
public:
|
|
|
|
bool enabled;
|
|
|
|
String tzLabel;
|
|
|
|
String tzFormat;
|
|
|
|
String server;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NTPSettingsService : public AdminSettingsService<NTPSettings> {
|
2019-12-03 23:16:06 +00:00
|
|
|
public:
|
|
|
|
NTPSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
|
|
|
|
~NTPSettingsService();
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
void loop();
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
protected:
|
|
|
|
void readFromJsonObject(JsonObject& root);
|
|
|
|
void writeToJsonObject(JsonObject& root);
|
|
|
|
void onConfigUpdated();
|
2020-01-20 11:14:46 +00:00
|
|
|
void receivedNTPtime();
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
private:
|
|
|
|
bool _reconfigureNTP = false;
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-12-24 11:19:19 +00:00
|
|
|
#ifdef ESP32
|
|
|
|
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
|
|
|
void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);
|
|
|
|
#elif defined(ESP8266)
|
2019-12-03 23:16:06 +00:00
|
|
|
WiFiEventHandler _onStationModeDisconnectedHandler;
|
|
|
|
WiFiEventHandler _onStationModeGotIPHandler;
|
2018-11-11 17:47:44 +00:00
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
void onStationModeGotIP(const WiFiEventStationModeGotIP& event);
|
|
|
|
void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
|
2018-11-11 17:47:44 +00:00
|
|
|
#endif
|
2018-02-26 00:11:31 +00:00
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
void configureNTP();
|
2018-02-26 00:11:31 +00:00
|
|
|
};
|
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
#endif // end NTPSettingsService_h
|