Fix Energy TotalStartTime

Fix Energy TotalStartTime when commands EnergyReset0 and/or EnergyReset3 used (#5373)
This commit is contained in:
Theo Arends 2019-03-01 12:08:41 +01:00
parent 4b69a7d115
commit f0a7a1f2a1
4 changed files with 16 additions and 8 deletions

View File

@ -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)

View File

@ -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;
@ -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;
}

View File

@ -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
@ -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);

View File

@ -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;
@ -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;
}
}