Skip to content

Commit

Permalink
v1.18-fas
Browse files Browse the repository at this point in the history
* #62 DaylightSavingTime Fix
  • Loading branch information
fashberg committed Oct 25, 2020
1 parent ac27f10 commit 274a38e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

## Version 1.18.beta1-fas
## Version 1.18-fas

* Fixed Relay State Calculation #26 again
* Daylight Saving Bug #62 fixed

## Version 1.17-fas

Expand Down
2 changes: 1 addition & 1 deletion Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ In settings menu of MCU (option 4) you can switch between internal (IN), externa
| Europe/Berlin | 99 | 0,3,0,2,120 | 0,10,0,3,60 | DST from last Sunday in March at 2 o'clock with 2h Offset from UTC and ends at last sunday in October at 3 o clock with 1 hour offset during standard time
| Europe/London | 99 | 0,3,0,2,60 | 0,10,0,3,0 | DST from last Sunday in March at 2 o'clock with 1h Offset from UTC and ends at last sunday in October at 3 o clock with no offset during standard time
| America/New_York | 99 | 2,3,0,2,-240 | 1,11,0,2,-300 | DST from 2nd Sunday in March at 2 o'clock with -4h Offset from UTC and ends at first sunday in November at 3 o clock with -5h offset during standard time
| Australia/Sydney | 99 | 1,10,1,2,660 | 1,4,1,3,600 | DST from first Sunday in October at 3 o'clock with 11h Offset from UTC and ends at first sunday in April at 2 o clock with 10h offset during standard time
| Australia/Sydney | 99 | 1,10,1,2,660 | 1,4,1,3,600 | DST from first Sunday in October at 2 o'clock with 11h Offset from UTC and ends at first sunday in April at 3 o clock with 10h offset during standard time

## 5. Troubleshooting

Expand Down
24 changes: 21 additions & 3 deletions WThermostat/WClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#include "../lib/WAdapter/WAdapter/WNetwork.h"
#include "Arduino.h"

//#define NTPTESTSTART 1585555170 // Full Hour Test
//#define NTPTESTSTART (1585447200 - 70 - (1*60*60)) // DST Test Berlin
//#define NTPTESTSTART (1603594800 - 70 - (2*60*60)) // STD Test Berlin
//#define NTPTESTSTART (1586055600 - 70 - (11*60*60)) // STD Test Sydney
//#define NTPTESTSTART (1601776800 - 70 - (10*60*60)) // DST Test Sydney

const static char* DEFAULT_NTP_SERVER PROGMEM = "pool.ntp.org";
const static char* DEFAULT_TIME_ZONE PROGMEM = "99";
const static char* DEFAULT_TIME_DST PROGMEM = "0,3,0,2,120";
Expand Down Expand Up @@ -219,8 +225,9 @@ class WClock : public WDevice {
network->logHeap(PSTR("NTP GotTime"));
uint32_t oldutc = getEpochTime();
ntpTime = ntpClient.getEpochTime();
//ntpTime = 1603587544; // DST-Test
//ntpTime = 1585555170; // Full Hour Test
#ifdef NTPTESTSTART
ntpTime = NTPTESTSTART + (millis()/1000);
#endif
if (ntpTime > START_VALID_TIME) {
if (validTime->getBoolean()){
// don't save first diff
Expand Down Expand Up @@ -267,15 +274,20 @@ class WClock : public WDevice {
} else {
int32_t dstoffset = this->timeRuleDst.offset * SECS_PER_MIN;
int32_t stdoffset = this->timeRuleStd.offset * SECS_PER_MIN;
if (Rtc.standard_time > Rtc.daylight_saving_time) {

if (Rtc.standard_time < Rtc.daylight_saving_time) {
// Southern hemisphere
network->log()->trace(F("This year switch to DST/STD: %d / %d (Southern)"),
Rtc.daylight_saving_time, Rtc.standard_time);
if ((Rtc.utc_time >= (Rtc.standard_time - dstoffset)) && (Rtc.utc_time < (Rtc.daylight_saving_time - stdoffset))) {
newTz = stdoffset; // Standard Time
} else {
newTz = dstoffset; // Daylight Saving Time
}
} else {
// Northern hemisphere
network->log()->trace(F("This year switch to DST/STD: %d / %d (Northern)"),
Rtc.standard_time, Rtc.daylight_saving_time);
if ((Rtc.utc_time >= (Rtc.daylight_saving_time - stdoffset)) && (Rtc.utc_time < (Rtc.standard_time - dstoffset))) {
newTz = dstoffset; // Daylight Saving Time
} else {
Expand Down Expand Up @@ -323,10 +335,16 @@ class WClock : public WDevice {
}

unsigned long getEpochTime() {
#ifdef NTPTESTSTART
return NTPTESTSTART + (millis()/1000);
#endif
return (lastNtpSync > 0 ? ntpClient.getEpochTime() : 0);
}

unsigned long getEpochTimeLocal() {
#ifdef NTPTESTSTART
return (lastNtpSync > 0 ? NTPTESTSTART + (millis()/1000) + getOffset() : 0);
#endif
return (lastNtpSync > 0 ? ntpClient.getEpochTime() + getOffset() : 0);
}

Expand Down

0 comments on commit 274a38e

Please sign in to comment.