Skip to content

Commit

Permalink
Fix Energy TotalStartTime
Browse files Browse the repository at this point in the history
Fix Energy TotalStartTime when commands EnergyReset0 and/or EnergyReset3 used (#5373)
  • Loading branch information
arendst committed Mar 1, 2019
1 parent 4b69a7d commit f0a7a1f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions sonoff/_changelog.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* 6.4.1.19 20190222
* Add command SetOption37 for RGBCW color mapping (#5326)
* Add Korean language translations (#5344)
* Fix Energy TotalStartTime when commands EnergyReset0 and/or EnergyReset3 used (#5373)
*
* 6.4.1.18 20190221
* Fix some exceptions and watchdogs due to lack of stack space - part 1 (#5215)
Expand Down
15 changes: 11 additions & 4 deletions sonoff/support_rtc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ uint32_t local_time = 0;
uint32_t daylight_saving_time = 0;
uint32_t standard_time = 0;
uint32_t ntp_time = 0;
uint32_t midnight = 1451602800;
uint32_t midnight = 0;
uint32_t restart_time = 0;
int32_t time_timezone = 0;
uint8_t midnight_now = 0;
Expand Down Expand Up @@ -406,10 +406,17 @@ void RtcSecond(void)
if (!Settings.energy_kWhtotal_time) { Settings.energy_kWhtotal_time = local_time; }
}
BreakTime(local_time, RtcTime);
if (!RtcTime.hour && !RtcTime.minute && !RtcTime.second && RtcTime.valid) {
midnight = local_time;
midnight_now = 1;

if (RtcTime.valid) {
if (!midnight) {
midnight = local_time - (RtcTime.hour * 3600) - (RtcTime.minute * 60) - RtcTime.second;
}
if (!RtcTime.hour && !RtcTime.minute && !RtcTime.second) {
midnight = local_time;
midnight_now = 1;
}
}

RtcTime.year += 1970;
}

Expand Down
5 changes: 2 additions & 3 deletions sonoff/xdrv_01_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ const char HTTP_SCRIPT_CONSOL[] PROGMEM =
"lt=setTimeout(l,{a});"
"return false;"
"}"
"window.onload=l;"
"</script>";
"window.onload=l;";

const char HTTP_MODULE_TEMPLATE_REPLACE[] PROGMEM =
"\2%d'>%s (%d\3"; // \2 and \3 are used in below os.replace
Expand Down Expand Up @@ -2021,8 +2020,8 @@ void HandleConsole(void)

String page = FPSTR(HTTP_HEAD);
page.replace(F("{v}"), FPSTR(S_CONSOLE));
page += FPSTR(HTTP_SCRIPT_CONSOL);
page += FPSTR(HTTP_HEAD_STYLE);
page.replace(F("</script>"), FPSTR(HTTP_SCRIPT_CONSOL));
page += FPSTR(HTTP_FORM_CMND);
page += FPSTR(HTTP_BTN_MAIN);
ShowPage(page);
Expand Down
3 changes: 2 additions & 1 deletion sonoff/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ bool EnergyCommand(void)
Settings.energy_kWhtoday = energy_kWhtoday;
RtcSettings.energy_kWhtoday = energy_kWhtoday;
energy_daily = (float)energy_kWhtoday / 100000;
if (!RtcSettings.energy_kWhtotal && !energy_kWhtoday) { Settings.energy_kWhtotal_time = LocalTime(); }
break;
case 2:
Settings.energy_kWhyesterday = lnum *100;
Expand All @@ -403,7 +404,7 @@ bool EnergyCommand(void)
RtcSettings.energy_kWhtotal = lnum *100;
Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal;
energy_total = (float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000;
if (!energy_total) { Settings.energy_kWhtotal_time = LocalTime(); }
Settings.energy_kWhtotal_time = (!energy_kWhtoday) ? LocalTime() : Midnight();
break;
}
}
Expand Down

0 comments on commit f0a7a1f

Please sign in to comment.