From 0de07df099b2ce92bd0fefe73cfd6ca72fb1fd51 Mon Sep 17 00:00:00 2001 From: arendst Date: Thu, 24 Aug 2017 11:09:52 +0200 Subject: [PATCH] Fix possible Pow Exception 0 --- README.md | 2 +- sonoff/_releasenotes.ino | 6 +++++- sonoff/sonoff.ino | 15 ++++++++------- sonoff/xsns_hlw8012.ino | 22 +++++++++++++--------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 6458d091f..b8790513a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## Sonoff-Tasmota Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE. -Current version is **5.6.1c** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information. +Current version is **5.6.1d** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information. ### ATTENTION All versions diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index ac763e00e..634c74085 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,8 @@ -/* 5.6.1c +/* 5.6.1d + * Fix settings order during startup to allow for displaying debug messages + * Add more Sonoff Pow range checking (#772) + * + * 5.6.1c * Add more precision to Sonoff Pow period and power results using command WattRes 0|1 (#759) * * 5.6.1b diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index aeaa583b5..0fc4d27c7 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x05060103 // 5.6.1c +#define VERSION 0x05060104 // 5.6.1d enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL}; enum week_t {Last, First, Second, Third, Fourth}; @@ -2789,19 +2789,20 @@ void setup() osw_init(); - sysCfg.bootcount++; - snprintf_P(log, sizeof(log), PSTR("APP: Bootcount %d"), sysCfg.bootcount); - addLog(LOG_LEVEL_DEBUG, log); - stop_flash_rotate = sysCfg.flag.stop_flash_rotate; - savedatacounter = sysCfg.savedata; - seriallog_timer = SERIALLOG_TIMER; seriallog_level = sysCfg.seriallog_level; + seriallog_timer = SERIALLOG_TIMER; #ifndef USE_EMULATION sysCfg.flag.emulation = 0; #endif // USE_EMULATION syslog_level = (sysCfg.flag.emulation) ? 0 : sysCfg.syslog_level; + stop_flash_rotate = sysCfg.flag.stop_flash_rotate; + savedatacounter = sysCfg.savedata; sleep = sysCfg.sleep; + sysCfg.bootcount++; + snprintf_P(log, sizeof(log), PSTR("APP: Bootcount %d"), sysCfg.bootcount); + addLog(LOG_LEVEL_DEBUG, log); + GPIO_init(); if (Serial.baudRate() != Baudrate) { diff --git a/sonoff/xsns_hlw8012.ino b/sonoff/xsns_hlw8012.ino index 009ac8fa4..db08708d3 100644 --- a/sonoff/xsns_hlw8012.ino +++ b/sonoff/xsns_hlw8012.ino @@ -112,9 +112,11 @@ void hlw_200mS() if (hlw_EDcntr) { hlw_len = 10000 / hlw_EDcntr; hlw_EDcntr = 0; - hlw_temp = ((HLW_PREF * sysCfg.hlw_pcal) / hlw_len) / 36; - hlw_kWhtoday += hlw_temp; - rtcMem.hlw_kWhtoday = hlw_kWhtoday; + if (hlw_len) { + hlw_temp = ((HLW_PREF * sysCfg.hlw_pcal) / hlw_len) / 36; + hlw_kWhtoday += hlw_temp; + rtcMem.hlw_kWhtoday = hlw_kWhtoday; + } } if (rtcTime.Valid) { if (rtc_loctime() == rtc_midnight()) { @@ -184,8 +186,8 @@ void hlw_readEnergy(byte option, float &et, float &ed, float &e, float &w, float unsigned long hlw_w; unsigned long hlw_u; unsigned long hlw_i; - int hlw_period; - int hlw_interval; + uint16_t hlw_period; + uint16_t hlw_interval; //char log[LOGSZ]; //snprintf_P(log, sizeof(log), PSTR("HLW: CF %d, CF1U %d (%d), CF1I %d (%d)"), hlw_cf_plen, hlw_cf1u_plen, hlw_cf1u_pcntmax, hlw_cf1i_plen, hlw_cf1i_pcntmax); @@ -203,14 +205,16 @@ void hlw_readEnergy(byte option, float &et, float &ed, float &e, float &w, float } else { hlw_period = rtc_loctime() - hlw_lasttime; } + hlw_lasttime = rtc_loctime(); if (hlw_period) { - hlw_lasttime = rtc_loctime(); hlw_interval = 3600 / hlw_period; if (hlw_Ecntr) { hlw_len = hlw_period * 1000000 / hlw_Ecntr; - hlw_Ecntr = 0; - hlw_temp = ((HLW_PREF * sysCfg.hlw_pcal) / hlw_len) / hlw_interval; - e = (float)hlw_temp / 10; + if (hlw_interval && hlw_len) { + hlw_Ecntr = 0; + hlw_temp = ((HLW_PREF * sysCfg.hlw_pcal) / hlw_len) / hlw_interval; + e = (float)hlw_temp / 10; + } } } }