|
|
|
@@ -9,20 +9,23 @@ |
|
|
|
|
|
|
|
WiFiUDP ntpUDP; |
|
|
|
|
|
|
|
// Set up your base timezone offset in seconds (e.g., UTC+2 for Baar, Switzerland is 3600) |
|
|
|
// Set up your base timezone offset in seconds (e.g., UTC+1 for Baar, Switzerland is 3600) |
|
|
|
const long gmtOffset_sec = 3600; |
|
|
|
|
|
|
|
// Set up DST offset in seconds (1 hour = 3600 seconds) |
|
|
|
const long daylightOffset_sec = 3600; |
|
|
|
|
|
|
|
TimerManager::TimerManager(ConfigManager &configManager) |
|
|
|
: configManager(configManager), ntpClient(ntpUDP, "pool.ntp.org", 3600) { |
|
|
|
ntpClient.begin(); |
|
|
|
: configManager(configManager), ntpClient(ntpUDP, "pool.ntp.org", gmtOffset_sec) { |
|
|
|
} |
|
|
|
|
|
|
|
TimerManager::~TimerManager() { |
|
|
|
} |
|
|
|
|
|
|
|
void TimerManager::begin() { |
|
|
|
ntpClient.begin(); |
|
|
|
} |
|
|
|
|
|
|
|
void TimerManager::onTimerIntervalChange(String timerIntervalName, const char *timerInterval) { |
|
|
|
TimeInterval interval; |
|
|
|
parseTimeInterval(timerInterval, interval); |
|
|
|
@@ -75,13 +78,16 @@ bool TimerManager::isNowInTimeInterval() { |
|
|
|
|
|
|
|
Config cfg = configManager.getConfig(); |
|
|
|
ntpClient.update(); |
|
|
|
uint32_t epochTime = ntpClient.getEpochTime(); |
|
|
|
time_t localTime = epochTime + gmtOffset_sec; |
|
|
|
|
|
|
|
if (isDST(month(localTime), day(localTime), weekday(localTime))) { |
|
|
|
time_t localEpochTime = ntpClient.getEpochTime() + gmtOffset_sec; |
|
|
|
time_t localTime = ntpClient.getHours() * 3600 + ntpClient.getMinutes() * 60 + ntpClient.getSeconds(); |
|
|
|
bool isDst = isDST(month(localEpochTime), day(localEpochTime), weekday(localEpochTime)); |
|
|
|
if (isDst) { |
|
|
|
localTime += daylightOffset_sec; |
|
|
|
} |
|
|
|
|
|
|
|
Serial.print("isDST: "); |
|
|
|
Serial.println(isDst ? "true" : "false"); |
|
|
|
Serial.println(ntpClient.getFormattedTime()); |
|
|
|
Serial.print("localTime: "); |
|
|
|
Serial.println(secondsToFormatedTime(localTime)); |
|
|
|
|
|
|
|
@@ -117,11 +123,12 @@ bool TimerManager::isInInterval(uint32_t now, const TimeInterval &interval) { |
|
|
|
} |
|
|
|
|
|
|
|
String TimerManager::secondsToFormatedTime(uint32_t seconds) { |
|
|
|
|
|
|
|
uint8_t hour = seconds / 3600; |
|
|
|
uint8_t _seconds = seconds % 3600; |
|
|
|
seconds %= 3600; |
|
|
|
|
|
|
|
uint8_t minute = _seconds / 60; |
|
|
|
uint8_t second = _seconds % 60; |
|
|
|
uint8_t minute = seconds / 60; |
|
|
|
uint8_t second = seconds % 60; |
|
|
|
|
|
|
|
char buffer[9]; // "HH:mm:ss" + '\0' |
|
|
|
snprintf(buffer, sizeof(buffer), "%02u:%02u:%02u", |