From 9356c02b4dbacf4b6f56e47cb4eff60a220f2803 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Thu, 26 Apr 2018 10:12:44 +0200 Subject: [PATCH 01/16] Set default upload port to serial --- platformio.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index e37162bf1..5ac5a1941 100644 --- a/platformio.ini +++ b/platformio.ini @@ -62,15 +62,15 @@ monitor_baud = 115200 ;upload_speed = 115200 upload_speed = 512000 upload_resetmethod = nodemcu -;upload_port = COM5 +upload_port = COM5 ; *** Upload file to OTA server using SCP ;upload_port = user@host:/path ;extra_scripts = pio/strip-floats.py, pio/sftp-uploader.py ; *** Upload file to OTA server using HTTP -upload_port = domus1:80/api/upload-arduino.php -extra_scripts = pio/strip-floats.py, pio/http-uploader.py +;upload_port = domus1:80/api/upload-arduino.php +;extra_scripts = pio/strip-floats.py, pio/http-uploader.py ; ********************************************************************* From 4675dbea1c52208c540128e416c3b597400fccb3 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Fri, 27 Apr 2018 18:06:19 +0200 Subject: [PATCH 02/16] Add rules variables and teleperiod trigger 5.12.0m * Add rule variables and teleperiod trigger to accomodate user HA messages --- sonoff/_releasenotes.ino | 1 + sonoff/sonoff.ino | 7 +++++- sonoff/xdrv_00_mqtt.ino | 3 ++- sonoff/xdrv_09_timers.ino | 8 +++---- sonoff/xdrv_10_rules.ino | 49 ++++++++++++++++++++++++++++++++------- sonoff/xsns_09_bmp.ino | 7 +++++- 6 files changed, 60 insertions(+), 15 deletions(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index c56d6fda0..4be23c8d7 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -3,6 +3,7 @@ * Remove sonoff-xxl * Add sonoff-classic, sonoff-allsensors and sonoff-knx * Add some coloring to important web buttons + * Add rule variables and teleperiod trigger to accomodate user HA messages * Add define MQTT_TELE_RETAIN compile option default set to 0 (#1071) * Add user selectable defines for Sunrise/set Dawn option (#2378) * Add random window to timers (#2447) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 71a2a33d4..ab223790a 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1462,7 +1462,12 @@ void PerformEverySecond() MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN); mqtt_data[0] = '\0'; - if (MqttShowSensor()) { MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); } + if (MqttShowSensor()) { + MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); +#ifdef USE_RULES + RulesTeleperiod(); // Allow rule based HA messages +#endif // USE_RULES + } } } diff --git a/sonoff/xdrv_00_mqtt.ino b/sonoff/xdrv_00_mqtt.ino index 7d47f37b5..8328cef82 100644 --- a/sonoff/xdrv_00_mqtt.ino +++ b/sonoff/xdrv_00_mqtt.ino @@ -648,7 +648,8 @@ bool MqttCommand() mqtt_data[0] = '\0'; } MqttPublishDirect(stemp1, false); - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); +// snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); + mqtt_data[0] = '\0'; } } } diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index 981609b41..aa1287f20 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -201,7 +201,7 @@ void ApplyTimerOffsets(Timer *duskdawn) if (timeBuffer > (uint16_t)duskdawn->time) { timeBuffer = 1440 - (timeBuffer - (uint16_t)duskdawn->time); duskdawn->days = duskdawn->days >> 1; - duskdawn->days = duskdawn->days |= (stored.days << 6); + duskdawn->days |= (stored.days << 6); } else { timeBuffer = (uint16_t)duskdawn->time - timeBuffer; } @@ -212,7 +212,7 @@ void ApplyTimerOffsets(Timer *duskdawn) if (timeBuffer > 1440) { timeBuffer -= 1440; duskdawn->days = duskdawn->days << 1; - duskdawn->days = duskdawn->days |= (stored.days >> 6); + duskdawn->days |= (stored.days >> 6); } } duskdawn->time = timeBuffer; @@ -279,8 +279,8 @@ void TimerEverySecond() #endif if (xtimer.arm) { set_time += timer_window[i]; // Add random time offset - if (set_time < 0) { set_time == 0; } // Stay today; - if (set_time > 1439) { set_time == 1439; } + if (set_time < 0) { set_time = 0; } // Stay today; + if (set_time > 1439) { set_time = 1439; } if (time == set_time) { if (xtimer.days & days) { Settings.timer[i].arm = xtimer.repeat; diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index afe6baa18..f92edcf55 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -62,6 +62,7 @@ \*********************************************************************************************/ #define MAX_RULE_TIMERS 8 +#define RULES_MAX_VARS 5 #ifndef ULONG_MAX #define ULONG_MAX 0xffffffffUL @@ -83,6 +84,7 @@ long rules_power = -1; uint32_t rules_triggers = 0; uint8_t rules_trigger_count = 0; +uint8_t rules_teleperiod = 0; /*******************************************************************************************/ @@ -146,6 +148,12 @@ bool RulesRuleMatch(String &event, String &rule) if (pos == -1) { return false; } // No # sign in rule String rule_task = rule.substring(0, pos); // "INA219" or "SYSTEM" + if (rules_teleperiod) { + int ppos = rule_task.indexOf("TELE-"); // "TELE-INA219" or "INA219" + if (ppos == -1) { return false; } // No pre-amble in rule + rule_task = rule.substring(5, pos); // "INA219" or "SYSTEM" + } + String rule_name = rule.substring(pos +1); // "CURRENT>0.100" or "BOOT" char compare = ' '; @@ -228,6 +236,8 @@ bool RulesRuleMatch(String &event, String &rule) bool RulesProcess() { bool serviced = false; + char vars[RULES_MAX_VARS][10] = { 0 }; + char stemp[10]; if (!Settings.flag.rules_enabled) { return serviced; } // Not enabled if (!strlen(Settings.rules)) { return serviced; } // No rules @@ -262,17 +272,32 @@ bool RulesProcess() rules_event_value = ""; String event = event_saved; if (RulesRuleMatch(event, event_trigger)) { - commands.replace(F("%value%"), rules_event_value); - char command[commands.length() +1]; - snprintf(command, sizeof(command), commands.c_str()); + commands.trim(); + String ucommand = commands; + ucommand.toUpperCase(); + if (ucommand.startsWith("VAR")) { + uint8_t idx = ucommand.charAt(3) - '1'; +// idx -= '1'; + if ((idx >= 0) && (idx < RULES_MAX_VARS)) { snprintf(vars[idx], sizeof(vars[idx]), rules_event_value.c_str()); } + } else { + commands.replace(F("%value%"), rules_event_value); + for (byte i = 0; i < RULES_MAX_VARS; i++) { + if (strlen(vars[i])) { + snprintf_P(stemp, sizeof(stemp), PSTR("%%var%d%%"), i +1); + commands.replace(stemp, vars[i]); + } + } + char command[commands.length() +1]; + snprintf(command, sizeof(command), commands.c_str()); - snprintf_P(log_data, sizeof(log_data), PSTR("RUL: %s performs \"%s\""), event_trigger.c_str(), command); - AddLog(LOG_LEVEL_INFO); + snprintf_P(log_data, sizeof(log_data), PSTR("RUL: %s performs \"%s\""), event_trigger.c_str(), command); + AddLog(LOG_LEVEL_INFO); -// snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, D_CMND_RULE, D_JSON_INITIATED); -// MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_RULE)); +// snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, D_CMND_RULE, D_JSON_INITIATED); +// MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_RULE)); - ExecuteCommand(command); + ExecuteCommand(command); + } serviced = true; } rules_trigger_count++; @@ -288,6 +313,7 @@ void RulesInit() Settings.flag.rules_enabled = 0; Settings.flag.rules_once = 0; } + rules_teleperiod = 0; } void RulesSetPower() @@ -344,6 +370,13 @@ void RulesEverySecond() } } +void RulesTeleperiod() +{ + rules_teleperiod = 1; + RulesProcess(); + rules_teleperiod = 0; +} + boolean RulesCommand() { char command[CMDSZ]; diff --git a/sonoff/xsns_09_bmp.ino b/sonoff/xsns_09_bmp.ino index 01eb29799..e6b4e03fd 100644 --- a/sonoff/xsns_09_bmp.ino +++ b/sonoff/xsns_09_bmp.ino @@ -465,7 +465,12 @@ void BmpShow(boolean json) mqtt_data, bmp_name, temperature, (bmp_model >= 2) ? json_humidity : "", pressure, (Settings.altitude != 0) ? json_sealevel : ""); #endif // USE_BME680 #ifdef USE_DOMOTICZ - if (0 == tele_period) DomoticzTempHumPressureSensor(temperature, humidity, pressure); + if (0 == tele_period) { + DomoticzTempHumPressureSensor(temperature, humidity, pressure); +#ifdef USE_BME680 + if (bmp_model >= 3) { DomoticzSensor(DZ_AIRQUALITY, (uint32_t)g); } +#endif // USE_BME680 + } #endif // USE_DOMOTICZ #ifdef USE_KNX From e1011d3cdd8ac55e556169482dd2c82c24b00e12 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sat, 28 Apr 2018 11:17:16 +0200 Subject: [PATCH 03/16] Disable sleep on core 2.4.1 5.12.0m * Disable sleep when using Esp/Arduino core 2.4.1 (#2559) --- sonoff/_releasenotes.ino | 1 + sonoff/support.ino | 2 ++ 2 files changed, 3 insertions(+) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 4be23c8d7..725ce14e3 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,6 +1,7 @@ /* 5.12.0m * Reinit timers to accomodate random window (#2447) * Remove sonoff-xxl + * Disable sleep when using Esp/Arduino core 2.4.1 (#2559) * Add sonoff-classic, sonoff-allsensors and sonoff-knx * Add some coloring to important web buttons * Add rule variables and teleperiod trigger to accomodate user HA messages diff --git a/sonoff/support.ino b/sonoff/support.ino index 8bc76d6a8..37e2139bb 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -615,7 +615,9 @@ void WifiBegin(uint8_t flag) delay(200); WiFi.mode(WIFI_STA); // Disable AP mode if (Settings.sleep) { +#ifndef ARDUINO_ESP8266_RELEASE_2_4_1 // See https://github.com/arendst/Sonoff-Tasmota/issues/2559 WiFi.setSleepMode(WIFI_LIGHT_SLEEP); // Allow light sleep during idle times +#endif } // if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { // WiFi.setPhyMode(WIFI_PHY_MODE_11N); From c8352351413315e034b708f5e4a3f92f4c6a8c6b Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sat, 28 Apr 2018 15:55:38 +0200 Subject: [PATCH 04/16] v5.12.0n - Change ADS1115 and Counter JSON 5.12.0n * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} --- README.md | 4 ++-- sonoff/_releasenotes.ino | 7 ++++++- sonoff/sonoff.ino | 2 +- sonoff/support.ino | 2 +- sonoff/xsns_01_counter.ino | 15 ++++++++++++++- sonoff/xsns_12_ads1115.ino | 2 +- sonoff/xsns_12_ads1115_i2cdev.ino | 2 +- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a15c9ab91..8d55383d2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development: [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **5.12.0m** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.12.0n** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### Quick install Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki. @@ -133,7 +133,7 @@ Different firmware images are released based on Features and Sensors selection g |--------------------------------|--------|---------|---------|------|------------| | ESP/Arduino lib v2.3.0 | 526k | 488k | 427k | 535k | 549k | | ESP/Arduino lib v2.4.0 | 531k | 496k | 435k | 540k | 552k | -| ESP/Arduino lib v2.4.1 | 533k | 498k | 436k | 542k | 554k | +| ESP/Arduino lib v2.4.1 | 534k | 499k | 437k | 543k | 555k | ### Contribute You can contribute to Sonoff-Tasmota by diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 725ce14e3..ec42dee40 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,9 @@ -/* 5.12.0m +/* 5.12.0n + * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) + * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules + * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} + * + * 5.12.0m * Reinit timers to accomodate random window (#2447) * Remove sonoff-xxl * Disable sleep when using Esp/Arduino core 2.4.1 (#2559) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index ab223790a..2da537983 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050C000D // 5.12.0m +#define VERSION 0x050C000E // 5.12.0n // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) diff --git a/sonoff/support.ino b/sonoff/support.ino index 37e2139bb..7ff973b2d 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1396,7 +1396,7 @@ void AdcShow(boolean json) analog >>= 5; if (json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_ANALOG_INPUT "0\":%d"), mqtt_data, analog); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"ANALOG\":{\"A0\":%d}"), mqtt_data, analog); #ifdef USE_WEBSERVER } else { snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ANALOG, mqtt_data, "", 0, analog); diff --git a/sonoff/xsns_01_counter.ino b/sonoff/xsns_01_counter.ino index 397f3d853..d1cb5da5b 100644 --- a/sonoff/xsns_01_counter.ino +++ b/sonoff/xsns_01_counter.ino @@ -90,9 +90,11 @@ const char HTTP_SNS_COUNTER[] PROGMEM = void CounterShow(boolean json) { + char stemp[10]; char counter[16]; byte dsxflg = 0; + byte header = 0; for (byte i = 0; i < MAX_COUNTERS; i++) { if (pin[GPIO_CNTR1 +i] < 99) { if (bitRead(Settings.pulse_counter_type, i)) { @@ -103,7 +105,13 @@ void CounterShow(boolean json) } if (json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_COUNTER "%d\":%s"), mqtt_data, i +1, counter); + if (!header) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"COUNTER\":{"), mqtt_data); + stemp[0] = '\0'; + } + header++; + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"C%d\":%s"), mqtt_data, stemp, i +1, counter); + strcpy(stemp, ","); #ifdef USE_DOMOTICZ if ((0 == tele_period) && (1 == dsxflg)) { DomoticzSensor(DZ_COUNT, RtcSettings.pulse_counter[i]); @@ -117,6 +125,11 @@ void CounterShow(boolean json) } } } + if (json) { + if (header) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data); + } + } } /*********************************************************************************************\ diff --git a/sonoff/xsns_12_ads1115.ino b/sonoff/xsns_12_ads1115.ino index 19c3ccf8a..f1279a732 100644 --- a/sonoff/xsns_12_ads1115.ino +++ b/sonoff/xsns_12_ads1115.ino @@ -190,7 +190,7 @@ void Ads1115Show(boolean json) stemp[0] = '\0'; } dsxflg++; - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_JSON_ANALOG_INPUT "%d\":%d"), mqtt_data, stemp, i, adc_value); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"A%d\":%d"), mqtt_data, stemp, i, adc_value); strcpy(stemp, ","); #ifdef USE_WEBSERVER } else { diff --git a/sonoff/xsns_12_ads1115_i2cdev.ino b/sonoff/xsns_12_ads1115_i2cdev.ino index 692040743..d3748ec7a 100644 --- a/sonoff/xsns_12_ads1115_i2cdev.ino +++ b/sonoff/xsns_12_ads1115_i2cdev.ino @@ -110,7 +110,7 @@ void Ads1115Show(boolean json) stemp[0] = '\0'; } dsxflg++; - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_JSON_ANALOG_INPUT "%d\":%d"), mqtt_data, stemp, i, adc_value); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"A%d\":%d"), mqtt_data, stemp, i, adc_value); strcpy(stemp, ","); #ifdef USE_WEBSERVER } else { From 44598e5fc4a2d1a12dc86d721272587c8394c66f Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sat, 28 Apr 2018 18:18:37 +0200 Subject: [PATCH 05/16] Add ANALOG#A0div10 trigger to rules 5.12.0n * Add ANALOG#A0div10 trigger to rules to be used in rule like on analog#a0div10 do publish cmnd/ailight/dimmer %value% endon --- sonoff/_releasenotes.ino | 1 + sonoff/support.ino | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index ec42dee40..d7bed584e 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -2,6 +2,7 @@ * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} + * Add ANALOG#A0div10 trigger to rules to be used in rule like on analog#a0div10 do publish cmnd/ailight/dimmer %value% endon * * 5.12.0m * Reinit timers to accomodate random window (#2447) diff --git a/sonoff/support.ino b/sonoff/support.ino index 7ff973b2d..da95e4f25 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1386,7 +1386,10 @@ void RtcInit() * ADC support \*********************************************************************************************/ -void AdcShow(boolean json) +uint8_t adc_counter = 0; +uint16_t adc_last_value = 0; + +uint16_t AdcRead() { uint16_t analog = 0; for (byte i = 0; i < 32; i++) { @@ -1394,6 +1397,26 @@ void AdcShow(boolean json) delay(1); } analog >>= 5; + return analog; +} + +void AdcEvery50ms() +{ + adc_counter++; + if (!(adc_counter % 4)) { + uint16_t new_value = AdcRead(); + if ((new_value < adc_last_value -10) || (new_value > adc_last_value +10)) { + adc_last_value = new_value; + uint16_t value = adc_last_value / 10; + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"ANALOG\":{\"A0div10\":%d}}"), (0 == value) ? 1 : (value > 99) ? 100 : value); + RulesProcess(); + } + } +} + +void AdcShow(boolean json) +{ + uint16_t analog = AdcRead(); if (json) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"ANALOG\":{\"A0\":%d}"), mqtt_data, analog); @@ -1416,6 +1439,9 @@ boolean Xsns02(byte function) if (pin[GPIO_ADC0] < 99) { switch (function) { + case FUNC_EVERY_50_MSECOND: + AdcEvery50ms(); + break; case FUNC_JSON_APPEND: AdcShow(1); break; From 39f56cff3af0a470367a0477a138f06ef8214adf Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sun, 29 Apr 2018 10:35:14 +0200 Subject: [PATCH 06/16] Fix Bug on KNX Driver Fix Bug on KNX Driver #2568 --- sonoff/xdrv_11_knx.ino | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino index 7084973b9..3853284a2 100644 --- a/sonoff/xdrv_11_knx.ino +++ b/sonoff/xdrv_11_knx.ino @@ -548,7 +548,7 @@ void KnxSensor(byte sensor_type, float value) knx.write_2byte_float(KNX_addr, value); snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_KNX "%s " D_SENT_TO " %d.%d.%d "), - device_param_ga[sensor_type], + device_param_ga[sensor_type -1], KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member); AddLog(LOG_LEVEL_INFO); @@ -741,9 +741,13 @@ void HandleKNXConfiguration() page.replace(F("GAarea"), F("CB_AREA")); page.replace(F("GAfdef"), F("CB_FDEF")); page += FPSTR(HTTP_FORM_KNX4); + byte j; for (byte i = 0; i < KNX_MAX_device_param ; i++) { - if ( device_param[i].show ) + // Check How many Relays are available and add: RelayX and TogleRelayX + if ( (i > 8) && (i < 16) ) { j=i-8; } else { j=i; } + if ( i == 8 ) { j = 0; } + if ( device_param[j].show ) { page += FPSTR(HTTP_FORM_KNX_OPT); page.replace(F("{vop}"), String(device_param[i].type)); From 36da4794d296aebe6f5e584fe164784a6ce7308c Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sun, 29 Apr 2018 13:45:23 +0200 Subject: [PATCH 07/16] Fix some language files Fix language files and allow Analog#A0div10 from 0 to 100 --- sonoff/language/cs-CZ.h | 4 ++-- sonoff/language/el-GR.h | 4 ++-- sonoff/language/en-GB.h | 2 +- sonoff/support.ino | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index 51296a577..a52f31901 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -28,7 +28,7 @@ * Use online command StateText to translate ON, OFF, HOLD and TOGGLE. * Use online command Prefix to translate cmnd, stat and tele. * - * Updated until v5.12.0m + * Updated until v5.12.0n \*********************************************************************/ //#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English) @@ -43,7 +43,7 @@ #define D_HOUR_MINUTE_SEPARATOR ":" #define D_MINUTE_SECOND_SEPARATOR ":" -#define D_DAY3LIST "Po Út St Čt Pá So Ne " +#define D_DAY3LIST "Ne Po Út St Čt Pá So " #define D_MONTH3LIST "LedÚnoBřeDubKvěČvnČvcSrpZářŘíjLisPro" // Non JSON decimal separator diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 7eff7094a..e4280b092 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -1,7 +1,7 @@ /* el-GR.h - localization for Greek - Greece for Sonoff-Tasmota - Copyright (C) 2018 Harry Kandiloros + Copyright (C) 2018 Kan3Nas This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ * Use online command StateText to translate ON, OFF, HOLD and TOGGLE. * Use online command Prefix to translate cmnd, stat and tele. * - * Updated until v5.12.0m + * Updated until v5.12.0n \*********************************************************************/ //#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English) diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index a57d18fd9..ade787b9e 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -28,7 +28,7 @@ * Use online command StateText to translate ON, OFF, HOLD and TOGGLE. * Use online command Prefix to translate cmnd, stat and tele. * - * Updated until v5.12.0l + * Updated until v5.12.0n \*********************************************************************/ //#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English) diff --git a/sonoff/support.ino b/sonoff/support.ino index da95e4f25..78ac10c0c 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1408,7 +1408,7 @@ void AdcEvery50ms() if ((new_value < adc_last_value -10) || (new_value > adc_last_value +10)) { adc_last_value = new_value; uint16_t value = adc_last_value / 10; - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"ANALOG\":{\"A0div10\":%d}}"), (0 == value) ? 1 : (value > 99) ? 100 : value); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"ANALOG\":{\"A0div10\":%d}}"), (value > 99) ? 100 : value); RulesProcess(); } } From c86a9f8e5321f86dc60a2370f6ecc59c431afb30 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sun, 29 Apr 2018 15:29:43 +0200 Subject: [PATCH 08/16] Fix Energy Today and Yesterday overflow 5.12.0o * Fix Energy Today and Yesterday overflow (#2543) --- README.md | 2 +- sonoff/_releasenotes.ino | 5 ++++- sonoff/settings.ino | 6 +++++- sonoff/sonoff.ino | 2 +- sonoff/xdrv_03_energy.ino | 35 ++++++++++++++++++----------------- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8d55383d2..f4b869751 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development: [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **5.12.0n** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.12.0o** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### Quick install Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki. diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index d7bed584e..804fc4068 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,7 @@ -/* 5.12.0n +/* 5.12.0o + * Fix Energy Today and Yesterday overflow (#2543) + * + * 5.12.0n * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 579862457..059383d72 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -851,7 +851,11 @@ void SettingsDelta() Settings.knx_CB_registered = 0; memset(&Settings.knx_physsical_addr, 0x00, 0x800 - 0x6b8); // Reset until 0x800 for future use } - + if (Settings.version < 0x050C000F) { + Settings.energy_kWhtoday /= 1000; + Settings.energy_kWhyesterday /= 1000; + RtcSettings.energy_kWhtoday /= 1000; + } Settings.version = VERSION; SettingsSave(1); } diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 2da537983..ef8708617 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050C000E // 5.12.0n +#define VERSION 0x050C000F // 5.12.0o // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index fc70751bf..db43cc670 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -47,11 +47,12 @@ float energy_voltage = 0; // 123.1 V float energy_current = 0; // 123.123 A float energy_power = 0; // 123.1 W float energy_power_factor = 0; // 0.12 -float energy_daily = 0; // 12.123 kWh +float energy_daily = 0; // 123.123 kWh float energy_total = 0; // 12345.12345 kWh float energy_start = 0; // 12345.12345 kWh total previous -unsigned long energy_kWhtoday; // 1212312345 Wh * 10^-5 (deca micro Watt hours) - 5763924 = 0.05763924 kWh = 0.058 kWh = energy_daily -unsigned long energy_period = 0; // 1212312345 Wh * 10^-5 (deca micro Watt hours) - 5763924 = 0.05763924 kWh = 0.058 kWh = energy_daily +unsigned long energy_kWhtoday; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = energy_daily +unsigned long energy_period = 0; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = energy_daily + float energy_power_last[3] = { 0 }; uint8_t energy_power_delta = 0; @@ -82,8 +83,8 @@ Ticker ticker_energy; void EnergyUpdateToday() { RtcSettings.energy_kWhtoday = energy_kWhtoday; - energy_daily = (float)energy_kWhtoday / 100000000; - energy_total = (float)(RtcSettings.energy_kWhtotal + (energy_kWhtoday / 1000)) / 100000; + energy_daily = (float)energy_kWhtoday / 100000; + energy_total = (float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000; } /*********************************************************************************************\ @@ -156,7 +157,7 @@ void HlwEverySecond() hlw_len = 10000 / hlw_energy_period_counter; hlw_energy_period_counter = 0; if (hlw_len) { - energy_kWhtoday += ((HLW_PREF * Settings.energy_power_calibration) / hlw_len) / 36; + energy_kWhtoday += ((HLW_PREF * Settings.energy_power_calibration) / hlw_len) / 36000; EnergyUpdateToday(); } } @@ -390,7 +391,7 @@ void CseEverySecond() } if (cf_frequency && energy_power) { cf_pulses_last_time = cf_pulses; - energy_kWhtoday += (cf_frequency * Settings.energy_power_calibration) / 36; + energy_kWhtoday += (cf_frequency * Settings.energy_power_calibration) / 36000; EnergyUpdateToday(); } } @@ -539,7 +540,7 @@ void PzemEvery200ms() break; case 4: // Total energy as 99999Wh if (!energy_start || (value < energy_start)) energy_start = value; // Init after restart and hanlde roll-over if any - energy_kWhtoday += (value - energy_start) * 100000; + energy_kWhtoday += (value - energy_start) * 100; energy_start = value; EnergyUpdateToday(); break; @@ -579,7 +580,7 @@ void Energy200ms() if (RtcTime.valid) { if (LocalTime() == Midnight()) { Settings.energy_kWhyesterday = energy_kWhtoday; - Settings.energy_kWhtotal += (energy_kWhtoday / 1000); + Settings.energy_kWhtotal += energy_kWhtoday; RtcSettings.energy_kWhtotal = Settings.energy_kWhtotal; energy_kWhtoday = 0; energy_period = energy_kWhtoday; @@ -851,14 +852,14 @@ boolean EnergyCommand() if (p != XdrvMailbox.data) { switch (XdrvMailbox.index) { case 1: - energy_kWhtoday = lnum *100000; + energy_kWhtoday = lnum *100; energy_period = energy_kWhtoday; Settings.energy_kWhtoday = energy_kWhtoday; RtcSettings.energy_kWhtoday = energy_kWhtoday; - energy_daily = (float)energy_kWhtoday / 100000000; + energy_daily = (float)energy_kWhtoday / 100000; break; case 2: - Settings.energy_kWhyesterday = lnum *100000; + Settings.energy_kWhyesterday = lnum *100; break; case 3: RtcSettings.energy_kWhtotal = lnum *100; @@ -869,9 +870,9 @@ boolean EnergyCommand() char energy_yesterday_chr[10]; char stoday_energy[10]; char energy_total_chr[10]; - dtostrfd((float)Settings.energy_kWhyesterday / 100000000, Settings.flag2.energy_resolution, energy_yesterday_chr); - dtostrfd((float)RtcSettings.energy_kWhtoday / 100000000, Settings.flag2.energy_resolution, stoday_energy); - dtostrfd((float)(RtcSettings.energy_kWhtotal + (energy_kWhtoday / 1000)) / 100000, Settings.flag2.energy_resolution, energy_total_chr); + dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr); + dtostrfd((float)RtcSettings.energy_kWhtoday / 100000, Settings.flag2.energy_resolution, stoday_energy); + dtostrfd((float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000, Settings.flag2.energy_resolution, energy_total_chr); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":{\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s}}"), command, energy_total_chr, energy_yesterday_chr, stoday_energy); status_flag = 1; @@ -1073,7 +1074,7 @@ void EnergyShow(boolean json) float energy = 0; if (show_energy_period) { - if (energy_period) energy = (float)(energy_kWhtoday - energy_period) / 100000; + if (energy_period) energy = (float)(energy_kWhtoday - energy_period) / 100; energy_period = energy_kWhtoday; } @@ -1084,7 +1085,7 @@ void EnergyShow(boolean json) dtostrfd(energy_voltage, Settings.flag2.voltage_resolution, energy_voltage_chr); dtostrfd(energy_current, Settings.flag2.current_resolution, energy_current_chr); dtostrfd(energy_power_factor, 2, energy_power_factor_chr); - dtostrfd((float)Settings.energy_kWhyesterday / 100000000, Settings.flag2.energy_resolution, energy_yesterday_chr); + dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr); if (json) { snprintf_P(speriod, sizeof(speriod), PSTR(",\"" D_JSON_PERIOD "\":%s"), energy_period_chr); From 67aaa2777c89d04c789d4b762385b997c5710a36 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Mon, 30 Apr 2018 11:10:38 +0200 Subject: [PATCH 09/16] Revert "Fix Energy Today and Yesterday overflow" This reverts commit c86a9f8e5321f86dc60a2370f6ecc59c431afb30. --- README.md | 2 +- sonoff/_releasenotes.ino | 5 +---- sonoff/settings.ino | 6 +----- sonoff/sonoff.ino | 2 +- sonoff/xdrv_03_energy.ino | 35 +++++++++++++++++------------------ 5 files changed, 21 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index f4b869751..8d55383d2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development: [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **5.12.0o** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.12.0n** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### Quick install Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki. diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 804fc4068..d7bed584e 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,7 +1,4 @@ -/* 5.12.0o - * Fix Energy Today and Yesterday overflow (#2543) - * - * 5.12.0n +/* 5.12.0n * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 059383d72..579862457 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -851,11 +851,7 @@ void SettingsDelta() Settings.knx_CB_registered = 0; memset(&Settings.knx_physsical_addr, 0x00, 0x800 - 0x6b8); // Reset until 0x800 for future use } - if (Settings.version < 0x050C000F) { - Settings.energy_kWhtoday /= 1000; - Settings.energy_kWhyesterday /= 1000; - RtcSettings.energy_kWhtoday /= 1000; - } + Settings.version = VERSION; SettingsSave(1); } diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index ef8708617..2da537983 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050C000F // 5.12.0o +#define VERSION 0x050C000E // 5.12.0n // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index db43cc670..fc70751bf 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -47,12 +47,11 @@ float energy_voltage = 0; // 123.1 V float energy_current = 0; // 123.123 A float energy_power = 0; // 123.1 W float energy_power_factor = 0; // 0.12 -float energy_daily = 0; // 123.123 kWh +float energy_daily = 0; // 12.123 kWh float energy_total = 0; // 12345.12345 kWh float energy_start = 0; // 12345.12345 kWh total previous -unsigned long energy_kWhtoday; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = energy_daily -unsigned long energy_period = 0; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = energy_daily - +unsigned long energy_kWhtoday; // 1212312345 Wh * 10^-5 (deca micro Watt hours) - 5763924 = 0.05763924 kWh = 0.058 kWh = energy_daily +unsigned long energy_period = 0; // 1212312345 Wh * 10^-5 (deca micro Watt hours) - 5763924 = 0.05763924 kWh = 0.058 kWh = energy_daily float energy_power_last[3] = { 0 }; uint8_t energy_power_delta = 0; @@ -83,8 +82,8 @@ Ticker ticker_energy; void EnergyUpdateToday() { RtcSettings.energy_kWhtoday = energy_kWhtoday; - energy_daily = (float)energy_kWhtoday / 100000; - energy_total = (float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000; + energy_daily = (float)energy_kWhtoday / 100000000; + energy_total = (float)(RtcSettings.energy_kWhtotal + (energy_kWhtoday / 1000)) / 100000; } /*********************************************************************************************\ @@ -157,7 +156,7 @@ void HlwEverySecond() hlw_len = 10000 / hlw_energy_period_counter; hlw_energy_period_counter = 0; if (hlw_len) { - energy_kWhtoday += ((HLW_PREF * Settings.energy_power_calibration) / hlw_len) / 36000; + energy_kWhtoday += ((HLW_PREF * Settings.energy_power_calibration) / hlw_len) / 36; EnergyUpdateToday(); } } @@ -391,7 +390,7 @@ void CseEverySecond() } if (cf_frequency && energy_power) { cf_pulses_last_time = cf_pulses; - energy_kWhtoday += (cf_frequency * Settings.energy_power_calibration) / 36000; + energy_kWhtoday += (cf_frequency * Settings.energy_power_calibration) / 36; EnergyUpdateToday(); } } @@ -540,7 +539,7 @@ void PzemEvery200ms() break; case 4: // Total energy as 99999Wh if (!energy_start || (value < energy_start)) energy_start = value; // Init after restart and hanlde roll-over if any - energy_kWhtoday += (value - energy_start) * 100; + energy_kWhtoday += (value - energy_start) * 100000; energy_start = value; EnergyUpdateToday(); break; @@ -580,7 +579,7 @@ void Energy200ms() if (RtcTime.valid) { if (LocalTime() == Midnight()) { Settings.energy_kWhyesterday = energy_kWhtoday; - Settings.energy_kWhtotal += energy_kWhtoday; + Settings.energy_kWhtotal += (energy_kWhtoday / 1000); RtcSettings.energy_kWhtotal = Settings.energy_kWhtotal; energy_kWhtoday = 0; energy_period = energy_kWhtoday; @@ -852,14 +851,14 @@ boolean EnergyCommand() if (p != XdrvMailbox.data) { switch (XdrvMailbox.index) { case 1: - energy_kWhtoday = lnum *100; + energy_kWhtoday = lnum *100000; energy_period = energy_kWhtoday; Settings.energy_kWhtoday = energy_kWhtoday; RtcSettings.energy_kWhtoday = energy_kWhtoday; - energy_daily = (float)energy_kWhtoday / 100000; + energy_daily = (float)energy_kWhtoday / 100000000; break; case 2: - Settings.energy_kWhyesterday = lnum *100; + Settings.energy_kWhyesterday = lnum *100000; break; case 3: RtcSettings.energy_kWhtotal = lnum *100; @@ -870,9 +869,9 @@ boolean EnergyCommand() char energy_yesterday_chr[10]; char stoday_energy[10]; char energy_total_chr[10]; - dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr); - dtostrfd((float)RtcSettings.energy_kWhtoday / 100000, Settings.flag2.energy_resolution, stoday_energy); - dtostrfd((float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000, Settings.flag2.energy_resolution, energy_total_chr); + dtostrfd((float)Settings.energy_kWhyesterday / 100000000, Settings.flag2.energy_resolution, energy_yesterday_chr); + dtostrfd((float)RtcSettings.energy_kWhtoday / 100000000, Settings.flag2.energy_resolution, stoday_energy); + dtostrfd((float)(RtcSettings.energy_kWhtotal + (energy_kWhtoday / 1000)) / 100000, Settings.flag2.energy_resolution, energy_total_chr); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":{\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s}}"), command, energy_total_chr, energy_yesterday_chr, stoday_energy); status_flag = 1; @@ -1074,7 +1073,7 @@ void EnergyShow(boolean json) float energy = 0; if (show_energy_period) { - if (energy_period) energy = (float)(energy_kWhtoday - energy_period) / 100; + if (energy_period) energy = (float)(energy_kWhtoday - energy_period) / 100000; energy_period = energy_kWhtoday; } @@ -1085,7 +1084,7 @@ void EnergyShow(boolean json) dtostrfd(energy_voltage, Settings.flag2.voltage_resolution, energy_voltage_chr); dtostrfd(energy_current, Settings.flag2.current_resolution, energy_current_chr); dtostrfd(energy_power_factor, 2, energy_power_factor_chr); - dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr); + dtostrfd((float)Settings.energy_kWhyesterday / 100000000, Settings.flag2.energy_resolution, energy_yesterday_chr); if (json) { snprintf_P(speriod, sizeof(speriod), PSTR(",\"" D_JSON_PERIOD "\":%s"), energy_period_chr); From 040a7adaf18ac30241a09895b899bf922ed61cdc Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Mon, 30 Apr 2018 12:07:48 +0200 Subject: [PATCH 10/16] v5.12.0o - Fix Energy Today overflow 5.12.0o * Fix Energy Today and Yesterday overflow (#2543) --- README.md | 2 +- sonoff/_releasenotes.ino | 5 ++++- sonoff/settings.ino | 6 +++++- sonoff/sonoff.ino | 2 +- sonoff/xdrv_03_energy.ino | 43 +++++++++++++++++++++++---------------- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8d55383d2..f4b869751 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development: [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **5.12.0n** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.12.0o** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### Quick install Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki. diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index d7bed584e..804fc4068 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,7 @@ -/* 5.12.0n +/* 5.12.0o + * Fix Energy Today and Yesterday overflow (#2543) + * + * 5.12.0n * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 579862457..059383d72 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -851,7 +851,11 @@ void SettingsDelta() Settings.knx_CB_registered = 0; memset(&Settings.knx_physsical_addr, 0x00, 0x800 - 0x6b8); // Reset until 0x800 for future use } - + if (Settings.version < 0x050C000F) { + Settings.energy_kWhtoday /= 1000; + Settings.energy_kWhyesterday /= 1000; + RtcSettings.energy_kWhtoday /= 1000; + } Settings.version = VERSION; SettingsSave(1); } diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 2da537983..ef8708617 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050C000E // 5.12.0n +#define VERSION 0x050C000F // 5.12.0o // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index fc70751bf..264613429 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -47,11 +47,12 @@ float energy_voltage = 0; // 123.1 V float energy_current = 0; // 123.123 A float energy_power = 0; // 123.1 W float energy_power_factor = 0; // 0.12 -float energy_daily = 0; // 12.123 kWh +float energy_daily = 0; // 123.123 kWh float energy_total = 0; // 12345.12345 kWh float energy_start = 0; // 12345.12345 kWh total previous -unsigned long energy_kWhtoday; // 1212312345 Wh * 10^-5 (deca micro Watt hours) - 5763924 = 0.05763924 kWh = 0.058 kWh = energy_daily -unsigned long energy_period = 0; // 1212312345 Wh * 10^-5 (deca micro Watt hours) - 5763924 = 0.05763924 kWh = 0.058 kWh = energy_daily +unsigned long energy_kWhtoday_delta = 0; // 1212312345 Wh 10^-5 (deca micro Watt hours) - Overflows to energy_kWhtoday (HLW and CSE only) +unsigned long energy_kWhtoday; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = energy_daily +unsigned long energy_period = 0; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = energy_daily float energy_power_last[3] = { 0 }; uint8_t energy_power_delta = 0; @@ -81,9 +82,14 @@ Ticker ticker_energy; void EnergyUpdateToday() { + if (energy_kWhtoday_delta > 1000) { + unsigned long delta = energy_kWhtoday_delta / 1000; + energy_kWhtoday_delta -= (delta * 1000); + energy_kWhtoday += delta; + } RtcSettings.energy_kWhtoday = energy_kWhtoday; - energy_daily = (float)energy_kWhtoday / 100000000; - energy_total = (float)(RtcSettings.energy_kWhtotal + (energy_kWhtoday / 1000)) / 100000; + energy_daily = (float)energy_kWhtoday / 100000; + energy_total = (float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000; } /*********************************************************************************************\ @@ -156,7 +162,7 @@ void HlwEverySecond() hlw_len = 10000 / hlw_energy_period_counter; hlw_energy_period_counter = 0; if (hlw_len) { - energy_kWhtoday += ((HLW_PREF * Settings.energy_power_calibration) / hlw_len) / 36; + energy_kWhtoday_delta += ((HLW_PREF * Settings.energy_power_calibration) / hlw_len) / 36; EnergyUpdateToday(); } } @@ -390,7 +396,7 @@ void CseEverySecond() } if (cf_frequency && energy_power) { cf_pulses_last_time = cf_pulses; - energy_kWhtoday += (cf_frequency * Settings.energy_power_calibration) / 36; + energy_kWhtoday_delta += (cf_frequency * Settings.energy_power_calibration) / 36; EnergyUpdateToday(); } } @@ -539,7 +545,7 @@ void PzemEvery200ms() break; case 4: // Total energy as 99999Wh if (!energy_start || (value < energy_start)) energy_start = value; // Init after restart and hanlde roll-over if any - energy_kWhtoday += (value - energy_start) * 100000; + energy_kWhtoday += (value - energy_start) * 100; energy_start = value; EnergyUpdateToday(); break; @@ -579,9 +585,10 @@ void Energy200ms() if (RtcTime.valid) { if (LocalTime() == Midnight()) { Settings.energy_kWhyesterday = energy_kWhtoday; - Settings.energy_kWhtotal += (energy_kWhtoday / 1000); + Settings.energy_kWhtotal += energy_kWhtoday; RtcSettings.energy_kWhtotal = Settings.energy_kWhtotal; energy_kWhtoday = 0; + energy_kWhtoday_delta = 0; energy_period = energy_kWhtoday; EnergyUpdateToday(); energy_max_energy_state = 3; @@ -851,14 +858,15 @@ boolean EnergyCommand() if (p != XdrvMailbox.data) { switch (XdrvMailbox.index) { case 1: - energy_kWhtoday = lnum *100000; + energy_kWhtoday = lnum *100; + energy_kWhtoday_delta = 0; energy_period = energy_kWhtoday; Settings.energy_kWhtoday = energy_kWhtoday; RtcSettings.energy_kWhtoday = energy_kWhtoday; - energy_daily = (float)energy_kWhtoday / 100000000; + energy_daily = (float)energy_kWhtoday / 100000; break; case 2: - Settings.energy_kWhyesterday = lnum *100000; + Settings.energy_kWhyesterday = lnum *100; break; case 3: RtcSettings.energy_kWhtotal = lnum *100; @@ -869,9 +877,9 @@ boolean EnergyCommand() char energy_yesterday_chr[10]; char stoday_energy[10]; char energy_total_chr[10]; - dtostrfd((float)Settings.energy_kWhyesterday / 100000000, Settings.flag2.energy_resolution, energy_yesterday_chr); - dtostrfd((float)RtcSettings.energy_kWhtoday / 100000000, Settings.flag2.energy_resolution, stoday_energy); - dtostrfd((float)(RtcSettings.energy_kWhtotal + (energy_kWhtoday / 1000)) / 100000, Settings.flag2.energy_resolution, energy_total_chr); + dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr); + dtostrfd((float)RtcSettings.energy_kWhtoday / 100000, Settings.flag2.energy_resolution, stoday_energy); + dtostrfd((float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000, Settings.flag2.energy_resolution, energy_total_chr); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":{\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s}}"), command, energy_total_chr, energy_yesterday_chr, stoday_energy); status_flag = 1; @@ -1040,6 +1048,7 @@ void EnergySnsInit() if (energy_flg) { energy_kWhtoday = (RtcSettingsValid()) ? RtcSettings.energy_kWhtoday : (RtcTime.day_of_year == Settings.energy_kWhdoy) ? Settings.energy_kWhtoday : 0; + energy_kWhtoday_delta = 0; energy_period = energy_kWhtoday; EnergyUpdateToday(); ticker_energy.attach_ms(200, Energy200ms); @@ -1073,7 +1082,7 @@ void EnergyShow(boolean json) float energy = 0; if (show_energy_period) { - if (energy_period) energy = (float)(energy_kWhtoday - energy_period) / 100000; + if (energy_period) energy = (float)(energy_kWhtoday - energy_period) / 100; energy_period = energy_kWhtoday; } @@ -1084,7 +1093,7 @@ void EnergyShow(boolean json) dtostrfd(energy_voltage, Settings.flag2.voltage_resolution, energy_voltage_chr); dtostrfd(energy_current, Settings.flag2.current_resolution, energy_current_chr); dtostrfd(energy_power_factor, 2, energy_power_factor_chr); - dtostrfd((float)Settings.energy_kWhyesterday / 100000000, Settings.flag2.energy_resolution, energy_yesterday_chr); + dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr); if (json) { snprintf_P(speriod, sizeof(speriod), PSTR(",\"" D_JSON_PERIOD "\":%s"), energy_period_chr); From 2c94ecfb6d1d1531d42cd655fafce83845fd2fbc Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Mon, 30 Apr 2018 14:18:46 +0200 Subject: [PATCH 11/16] Fix uptime 17651+ days 5.12.0o * Fix NTP sync to Thu Jan 01 08:00:10 1970 results in uptime 17651+ days (core2.4.1/sdk2.2.1) --- sonoff/_releasenotes.ino | 1 + sonoff/support.ino | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 804fc4068..0cb14f97b 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,5 +1,6 @@ /* 5.12.0o * Fix Energy Today and Yesterday overflow (#2543) + * Fix NTP sync to Thu Jan 01 08:00:10 1970 results in uptime 17651+ days (core2.4.1/sdk2.2.1) * * 5.12.0n * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) diff --git a/sonoff/support.ino b/sonoff/support.ino index 78ac10c0c..a33c81a1a 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1314,7 +1314,7 @@ void RtcSecond() uint8_t offset = (uptime < 30) ? RtcTime.second : (((ESP.getChipId() & 0xF) * 3) + 3) ; // First try ASAP to sync. If fails try once every 60 seconds based on chip id if ((WL_CONNECTED == WiFi.status()) && (offset == RtcTime.second) && ((RtcTime.year < 2016) || (ntp_sync_minute == RtcTime.minute))) { ntp_time = sntp_get_current_timestamp(); - if (ntp_time) { + if (ntp_time > 1451602800) { // Fix NTP bug in core 2.4.1/SDK 2.2.1 (returns Thu Jan 01 08:00:10 1970 after power on) utc_time = ntp_time; ntp_sync_minute = 60; // Sync so block further requests if (restart_time == 0) { From 962a50452c55f3ae3a06d808c53af82960597426 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Mon, 30 Apr 2018 17:35:42 +0200 Subject: [PATCH 12/16] v5.13.0 Sync with master --- README.md | 2 +- sonoff/_releasenotes.ino | 188 +++++++++++++++------------------------ sonoff/sonoff.ino | 2 +- 3 files changed, 76 insertions(+), 116 deletions(-) diff --git a/README.md b/README.md index f4b869751..7b38ad191 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development: [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **5.12.0o** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.13.0** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### Quick install Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki. diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 0cb14f97b..d08e1bb39 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,118 +1,49 @@ -/* 5.12.0o - * Fix Energy Today and Yesterday overflow (#2543) - * Fix NTP sync to Thu Jan 01 08:00:10 1970 results in uptime 17651+ days (core2.4.1/sdk2.2.1) - * - * 5.12.0n - * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) - * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules - * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} - * Add ANALOG#A0div10 trigger to rules to be used in rule like on analog#a0div10 do publish cmnd/ailight/dimmer %value% endon - * - * 5.12.0m - * Reinit timers to accomodate random window (#2447) - * Remove sonoff-xxl - * Disable sleep when using Esp/Arduino core 2.4.1 (#2559) - * Add sonoff-classic, sonoff-allsensors and sonoff-knx - * Add some coloring to important web buttons - * Add rule variables and teleperiod trigger to accomodate user HA messages - * Add define MQTT_TELE_RETAIN compile option default set to 0 (#1071) - * Add user selectable defines for Sunrise/set Dawn option (#2378) - * Add random window to timers (#2447) - * Add optional KNX IP Protocol Support (#2402) - * Add Greek language file (#2491) - * Add Bulgarian language file - * Add support for sensor HC-SR04 ultrasonic (#113, #1964, #2444) - * Add support for Sonoff Pow R2 (#2340) - * Add GPIO_User to GPIO02 for all Sonoff T1 (#2524) - * Fix compile error when using ESP/Arduino library v2.3.0 by reverting KNX async UDP library to default UDP library (#2488, #2492, #2493) - * Fix configuration filename truncation when it contains spaces (#2484, #2490) - * - * 5.12.0l - * Release rules up to 511 characters - * Prepare for feature release - call on translators to update their language files - * Add timer sunrise and sunset offset (#2378) - * Fix negative Latitude and Longitude value entry (#2461) - * Fix sunrise and sunset calculation (#2461) - * - * 5.12.0k - * Prepare for simple rules of up to 255 characters by enlarging Settings area to now 2048 bytes - * Change Timer parameter name from Power to Action - * Add commands Publish, Rule, RuleTimer and Event. See Wiki about Rule restriction, usage and examples - * Fix freeing more code space when emulation is disabled (#1592) - * Fix update temperature on DS18x20 drivers (#2328) - * Fix compile error when not defined USE_TIMERS (#2400) - * - * 5.12.0j - * Add optional Sunrise and Sunset timers with commands Latitide and Longitude to be enabled with define USE_SUNRISE in user_config.h (#2317) - * - * 5.12.0i - * Add 16 timers using commands Timer and Timers (#1091) - * Add commands Timer 0 to clear timer and Timer 1..16 to copy timer - * Add optional Timer configuration webpage to be enabled in user_config.h with define USE_TIMERS_WEB - * Add hexadecimal Data entry to command IrSend using 0x notation (#1290, #2314) - * Add Domoticz Battery and RSSI Quality (#1604) - * Add Home Assistant MQTT Discovery for Buttons and change SetOption19 response (#2277) - * Add support for SGP30 gas and air quality sensor (#2307) - * Add multiple color entry support for command Led like Led2 120000 001200 000012 setting led2 as Red, Led3 as Green and Led4 as Blue (#2303) - * Add hexadecimal RGB color entry on RGBCW leds (#2304) +/* 5.13.0 20180430 + * Change platformio option sonoff-ds18x20 to sonoff-allsensors enabling ds18x20 and all other sensors in one image + * Change status display of Ssid and SetOption + * Change default option SetOption15 from 0 to 1 providing better initial PWM experience * Change webpage parameter communication - * Change Timer parameter Device to more obvious Output * Change max number of commands in Backlog from 15 to 30 and ignore commands overflowing + * Change TSL2561 driver to joba library and delete Adafruit library (#1644) + * Change default parameters in user_config.h to undefined for easy installation (#1851) + * Change max user configurable hold time from 10 to 25 seconds (#1851) + * Change Sonoff SC JSON format (#1939) + * Change Polish language to using Diacritics (#2005) * Change user_config_override usage by providing user_config_override_sample.h (#2228) * Change MQTT response topic for Energy changes from ENERGY to SENSOR (#2229, #2251) * Change default Reset configuration time from 4 seconds to 40 seconds on Button hold (#2268) - * - * 5.12.0h - * Add optional Arduino OTA support to be enabled in user_config.h (#1998) - * Add support for Software Serial bridge using commands SerialDelimiter, SBaudrate and SSerialSend. Supports 8N1 and text only (#2190) - * Add support for Hardware Serial bridge using commands SerialDelimiter, Baudrate and SerialSend. Supports 8N1 and text only (#2182) - * Add support for Zengge WF017 PWM Led strip controller (#2202) - * Add PWM status to command State if PWM enabled (#2203) - * Add command HSBColor Hue,Sat,Bri (#1642, #2203) - * Add command Channel 0..100 to control dimmer value for individual color channels (#2111, #2203) - * Add Channel status information (#2211) - * Add all FriendlyNames to Status information (#2208) - * Change status display of Ssid and SetOption - * Change default option SetOption15 from 0 to 1 providing better initial PWM experience - * - * 5.12.0f - * Add compile time support for WS2812 BRG and RBG led configurations to be defined in user_config.h (#1690) - * - * 5.12.0e - * Add Domoticz dust (custom) sensors to PMS5003 and NovaFitness SDS drivers as PM1, PM2.5 and PM10 - * Add a second TLS fingerprint to allow switching keys in TLS mode (#2033, #2102) - * Add display of remaining pulse time to command PulseTime (#2085) - * Add additional time offset to Wifi Retry based on device mac address (#2089) - * Add command Color6 RRGGBB for Clock hour marker color and command Rotation pixels for Clock rotation (#2092) - * Add HTML language header in local language (#2123) - * Add command PowerDelta 0..100 (percentage) to Energy monitoring devices to report on active power load change (#2157) - * Add Restart Reason to Status 1 report (#2161) - * Fix MAX31850 higher temperatures (#1269) - * - * 5.12.0d - * Add support for optional MQTT drivers to be selected in user_config.h (#1992) - * Add Portuguese language file - * Add compiler check for stable lwIP version v1.4 (#1940) - * Add always suffix with device number in Mqtt discovery topic (#1962) - * Add diacritics to Polish language file (#2005) - * Add Hungarian language file (#2024) - * Add Czech language file - * Add Chinese (Traditional) in Taiwan language file (#2108) - * Add support for Nova Fitness SDS011 and possibly SDS021 particle concentration sensor (#2070) - * Add single decimal precision to Nova Fitness SDS0x1 sensor values (#2093) - * Add support for multiple SHT3X sensors (#1949, #2110) - * Add Sonoff SC domoticz support for Sound level as Counter and Air quality (#2118) - * Fix MQTT TLS fingerprint validation (#2033) - * - * 5.12.0c + * Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560) + * Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules + * Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}} * Fix intermittent exception when dns lookup is used while sleep is enabled * Fix 5.4.0 regression turning off single press after button hold during 4x hold time * Fix possible wifi connection problem by erasing sdk configuration parameters - * Change Polish language to using Diacritics (#2005) - * - * 5.12.0b + * Fix NTP sync to Thu Jan 01 08:00:10 1970 results in uptime 17651+ days (core2.4.1/sdk2.2.1) + * Fix MAX31850 higher temperatures (#1269) + * Fix freeing more code space when emulation is disabled (#1592) + * Fix providing web page configuratin option for Friendly Name when no device (relay or light) is configured (#1850) + * Fix compile error when define HOME_ASSISTANT_DISCOVERY_ENABLE is not set (#1937) + * Fix MQTT TLS fingerprint validation (#2033) + * Fix update temperature on DS18x20 drivers (#2328) + * Fix compile error when not defined USE_TIMERS (#2400) + * Fix configuration filename truncation when it contains spaces (#2484, #2490) + * Fix Energy Today and Yesterday overflow (#2543) * Add serial debug info + * Add Portuguese language file + * Add Czech language file + * Add Bulgarian language file + * Add Domoticz dust (custom) sensors to PMS5003 and NovaFitness SDS drivers as PM1, PM2.5 and PM10 + * Add commands Publish, Rule, RuleTimer and Event. See Wiki about Rule restriction, usage and examples + * Add sonoff-classic, sonoff-allsensors and sonoff-knx + * Add some coloring to important web buttons + * Add support for sensor HC-SR04 ultrasonic (#113, #1964, #2444) + * Add define MQTT_TELE_RETAIN compile option default set to 0 (#1071) + * Add 16 timers using commands Timer and Timers (#1091) + * Add optional Timer configuration webpage to be enabled in user_config.h with define USE_TIMERS_WEB * Add Multichannel Gas sensor using MultiChannel_Gas_Sensor library (#1245) + * Add Domoticz Battery and RSSI Quality (#1604) + * Add command HSBColor Hue,Sat,Bri (#1642, #2203) + * Add compile time support for WS2812 BRG and RBG led configurations to be defined in user_config.h (#1690) * Add optional usage of %d or %X suffices in MQTT client to append chipid (#1871) * Add optional usage of %d or %X suffices in MQTT topic to append chipid (#1871) * Add optional usage of %d or %04d in ota url to be replaced with chipid (#1871) @@ -122,17 +53,46 @@ * Add Webserver upload preflight request support (#1927) * Add Home Assistant clear other device (#1931) * Add Restart time to Status 1 (#1938) - * Change TSL2561 driver to joba library and delete Adafruit library (#1644) - * Change Sonoff SC JSON format (#1939) - * Fix compile error when define HOME_ASSISTANT_DISCOVERY_ENABLE is not set (#1937) * Add optional TSL2561 driver using library Joba_Tsl2561 to be enabled in user_config.h with define USE_TSL2561_JOBA (#1951) * Add support for sensor SHTC3 (#1967) - * - * 5.12.0a - * Change platformio option sonoff-ds18x20 to sonoff-allsensors enabling ds18x20 and all other sensors in one image - * Fix providing web page configuratin option for Friendly Name when no device (relay or light) is configured (#1850) - * Change default parameters in user_config.h to undefined for easy installation (#1851) - * Change max user configurable hold time from 10 to 25 seconds (#1851) + * Add compiler check for stable lwIP version v1.4 (#1940) + * Add support for multiple SHT3X sensors (#1949, #2110) + * Add always suffix with device number in Mqtt discovery topic (#1962) + * Add support for optional MQTT drivers to be selected in user_config.h (#1992) + * Add optional Arduino OTA support to be enabled in user_config.h (#1998) + * Add diacritics to Polish language file (#2005) + * Add Hungarian language file (#2024) + * Add support for Nova Fitness SDS011 and possibly SDS021 particle concentration sensor (#2070) + * Add single decimal precision to Nova Fitness SDS0x1 sensor values (#2093) + * Add Chinese (Traditional) in Taiwan language file (#2108) + * Add Sonoff SC domoticz support for Sound level as Counter and Air quality (#2118) + * Add a second TLS fingerprint to allow switching keys in TLS mode (#2033, #2102) + * Add display of remaining pulse time to command PulseTime (#2085) + * Add additional time offset to Wifi Retry based on device mac address (#2089) + * Add command Color6 RRGGBB for Clock hour marker color and command Rotation pixels for Clock rotation (#2092) + * Add HTML language header in local language (#2123) + * Add command PowerDelta 0..100 (percentage) to Energy monitoring devices to report on active power load change (#2157) + * Add Restart Reason to Status 1 report (#2161) + * Add command Channel 0..100 to control dimmer value for individual color channels (#2111, #2203) + * Add support for Hardware Serial bridge using commands SerialDelimiter, Baudrate and SerialSend. Supports 8N1 and text only (#2182) + * Add support for Software Serial bridge using commands SerialDelimiter, SBaudrate and SSerialSend. Supports 8N1 and text only (#2190) + * Add support for Zengge WF017 PWM Led strip controller (#2202) + * Add PWM status to command State if PWM enabled (#2203) + * Add all FriendlyNames to Status information (#2208) + * Add Channel status information (#2211) + * Add hexadecimal Data entry to command IrSend using 0x notation (#1290, #2314) + * Add Home Assistant MQTT Discovery for Buttons and change SetOption19 response (#2277) + * Add multiple color entry support for command Led like Led2 120000 001200 000012 setting led2 as Red, Led3 as Green and Led4 as Blue (#2303) + * Add hexadecimal RGB color entry on RGBCW leds (#2304) + * Add support for SGP30 gas and air quality sensor (#2307) + * Add optional Sunrise and Sunset timers with commands Latitide and Longitude to be enabled with define USE_SUNRISE in user_config.h (#2317) + * Add timer sunrise and sunset offset (#2378) + * Add user selectable defines for Sunrise/set Dawn option (#2378) + * Add optional KNX IP Protocol Support (#2402) + * Add random window to timers (#2447) + * Add Greek language file (#2491) + * Add support for Sonoff Pow R2 (#2340) + * Add GPIO_User to GPIO02 for all Sonoff T1 (#2524) * * 5.12.0 20180209 * Change library PubSubClient.h define MQTT_MAX_PACKET_SIZE from 512 to 1000 for Home Assistant support diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index ef8708617..a3f7b2866 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050C000F // 5.12.0o +#define VERSION 0x050D0000 // 5.13.0 // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) From d629b8ce2a4ba1288793b97474fe63fb429adc8e Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Tue, 1 May 2018 11:28:36 +0200 Subject: [PATCH 13/16] v5.13.0a - Fix JSON buffer size 5.13.0a * Fix JSON buffers size too small for execution in some situations (#2580) --- README.md | 2 +- sonoff/_releasenotes.ino | 5 ++++- sonoff/sonoff.ino | 2 +- sonoff/xdrv_09_timers.ino | 2 +- sonoff/xdrv_10_rules.ino | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7b38ad191..19bf193a6 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development: [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **5.13.0** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.13.0a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### Quick install Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki. diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index d08e1bb39..3bb2238c9 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,7 @@ -/* 5.13.0 20180430 +/* 5.13.0a + * Fix JSON buffers size too small for execution in some situations (#2580) + * + * 5.13.0 20180430 * Change platformio option sonoff-ds18x20 to sonoff-allsensors enabling ds18x20 and all other sensors in one image * Change status display of Ssid and SetOption * Change default option SetOption15 from 0 to 1 providing better initial PWM experience diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index a3f7b2866..554a4858e 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050D0000 // 5.13.0 +#define VERSION 0x050D0001 // 5.13.0a // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index aa1287f20..e85349da7 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -354,7 +354,7 @@ boolean TimerCommand() #ifndef USE_RULES if (devices_present) { #endif - StaticJsonBuffer<200> jsonBuffer; + StaticJsonBuffer<256> jsonBuffer; JsonObject& root = jsonBuffer.parseObject(dataBufUc); if (!root.success()) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_TIMER "%d\":\"" D_JSON_INVALID_JSON "\"}"), index); // JSON decode failed diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index f92edcf55..b07bea5b7 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -181,7 +181,7 @@ bool RulesRuleMatch(String &event, String &rule) } // Step2: Search rule_task and rule_name - StaticJsonBuffer<400> jsonBuf; + StaticJsonBuffer<1024> jsonBuf; JsonObject &root = jsonBuf.parseObject(event); if (!root.success()) { return false; } // No valid JSON data From 1fb9c0e531b87d83d8d7f279dab705f85d677bef Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Tue, 1 May 2018 12:42:17 +0200 Subject: [PATCH 14/16] v5.13.0a - Add optional module select not to be used 5.13.0a * Add define MODULE for user selecting default model although it preferably should not be changed (#569, #2589) --- README.md | 2 +- sonoff/_releasenotes.ino | 1 + sonoff/sonoff.h | 2 -- sonoff/sonoff_post.h | 4 ++++ sonoff/user_config.h | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 19bf193a6..5c369b928 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! [![GitHub stars](https://img.shields.io/github/stars/arendst/Sonoff-Tasmota.svg?style=social&label=Star)](https://github.com/arendst/Sonoff-Tasmota/stargazers) [![GitHub forks](https://img.shields.io/github/forks/arendst/Sonoff-Tasmota.svg?style=social&label=Fork)](https://github.com/arendst/Sonoff-Tasmota/network) -### Development: +### Development [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) Current version is **5.13.0a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 3bb2238c9..0bbf1e7bf 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,5 +1,6 @@ /* 5.13.0a * Fix JSON buffers size too small for execution in some situations (#2580) + * Add define MODULE for user selecting default model (#569, #2589) * * 5.13.0 20180430 * Change platformio option sonoff-ds18x20 to sonoff-allsensors enabling ds18x20 and all other sensors in one image diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 296046c85..a2eecea4f 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -52,8 +52,6 @@ typedef unsigned long power_t; // Power (Relay) type #define MAX_KNX_CB 10 // Max number of KNX Group Addresses to write that can be set #define MAX_RULE_SIZE 512 // Max number of characters in rules -#define MODULE SONOFF_BASIC // [Module] Select default model - #define MQTT_TOKEN_PREFIX "%prefix%" // To be substituted by mqtt_prefix[x] #define MQTT_TOKEN_TOPIC "%topic%" // To be substituted by mqtt_topic, mqtt_grptopic, mqtt_buttontopic, mqtt_switchtopic diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h index 1d6ba7878..ef1dfbfd9 100644 --- a/sonoff/sonoff_post.h +++ b/sonoff/sonoff_post.h @@ -46,6 +46,10 @@ void KNX_CB_Action(message_t const &msg, void *arg); * Default global defines \*********************************************************************************************/ +#ifndef MODULE +#define MODULE SONOFF_BASIC // [Module] Select default model +#endif + #define USE_DHT // Default DHT11 sensor needs no external library /*********************************************************************************************\ diff --git a/sonoff/user_config.h b/sonoff/user_config.h index 6bfa6e1cd..83b9a346f 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -48,6 +48,7 @@ // -- Project ------------------------------------- #define PROJECT "sonoff" // PROJECT is used as the default topic delimiter +#define MODULE SONOFF_BASIC // [Module] Select default model from sonoff_template.h (Should not be changed) #define SAVE_DATA 1 // [SaveData] Save changed parameters to Flash (0 = disable, 1 - 3600 seconds) #define SAVE_STATE 1 // [SetOption0] Save changed power state to Flash (0 = disable, 1 = enable) From 69ef562b36bf0e56472af8f3feba976cfed8a716 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Tue, 1 May 2018 18:02:45 +0200 Subject: [PATCH 15/16] Fix configuration restore 5.13.0a * Fix configuration restore (#2591) --- sonoff/_releasenotes.ino | 3 ++- sonoff/webserver.ino | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 0bbf1e7bf..2efcefcd7 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,6 +1,7 @@ /* 5.13.0a * Fix JSON buffers size too small for execution in some situations (#2580) - * Add define MODULE for user selecting default model (#569, #2589) + * Add define MODULE for user selecting default model although it preferably should not be changed (#569, #2589) + * Fix configuration restore (#2591) * * 5.13.0 20180430 * Change platformio option sonoff-ds18x20 to sonoff-allsensors enabling ds18x20 and all other sensors in one image diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino index f82fa2e6d..9c9be2a42 100644 --- a/sonoff/webserver.ino +++ b/sonoff/webserver.ino @@ -328,6 +328,8 @@ uint8_t webserver_state = HTTP_OFF; uint8_t upload_error = 0; uint8_t upload_file_type; uint8_t upload_progress_dot_count; +uint8_t config_block_count = 0; +uint8_t config_xor_on = 0; // Helper function to avoid code duplication (saves 4k Flash) static void WebGetArg(const char* arg, char* out, size_t max) @@ -1317,17 +1319,14 @@ void HandleUploadLoop() } upload_progress_dot_count = 0; } else if (!upload_error && (UPLOAD_FILE_WRITE == upload.status)) { - if (0 == upload.totalSize) - { + if (0 == upload.totalSize) { if (upload_file_type) { if (upload.buf[0] != CONFIG_FILE_SIGN) { upload_error = 8; return; } - if (upload.currentSize > sizeof(Settings)) { - upload_error = 9; - return; - } + config_xor_on = upload.buf[1]; + config_block_count = 0; } else { if (upload.buf[0] != 0xE9) { upload_error = 3; @@ -1343,14 +1342,24 @@ void HandleUploadLoop() } if (upload_file_type) { // config if (!upload_error) { - if (upload.buf[1]) { + if (upload.currentSize > (sizeof(Settings) - (config_block_count * HTTP_UPLOAD_BUFLEN))) { + if (config_block_count) { SettingsDefault(); } + upload_error = 9; + return; + } + if (config_xor_on) { for (uint16_t i = 2; i < upload.currentSize; i++) { upload.buf[i] ^= (CONFIG_FILE_XOR +i); } } - SettingsDefaultSet2(); - memcpy((char*)&Settings +16, upload.buf +16, upload.currentSize -16); - memcpy((char*)&Settings +8, upload.buf +8, 4); // Restore version and auto upgrade + if (0 == config_block_count) { + SettingsDefaultSet2(); + memcpy((char*)&Settings +16, upload.buf +16, upload.currentSize -16); + memcpy((char*)&Settings +8, upload.buf +8, 4); // Restore version and auto upgrade + } else { + memcpy((char*)&Settings +(config_block_count * HTTP_UPLOAD_BUFLEN), upload.buf, upload.currentSize); + } + config_block_count++; } } else { // firmware if (!upload_error && (Update.write(upload.buf, upload.currentSize) != upload.currentSize)) { From 036b958f76c63f66dd14900bf994bbfe20651024 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Wed, 2 May 2018 10:15:50 +0200 Subject: [PATCH 16/16] v5.13.1a - Update otaurl 5.13.1a * Change user_config.h otaurl to http://sonoff.maddox.co.uk/tasmota/sonoff.bin (#2588, #2602) --- README.md | 2 +- sonoff/_releasenotes.ino | 5 ++++- sonoff/sonoff.ino | 2 +- sonoff/user_config.h | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5c369b928..4845199a5 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **5.13.0a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.13.1a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### Quick install Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki. diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 2efcefcd7..8236aae15 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,7 @@ -/* 5.13.0a +/* 5.13.1a + * Change user_config.h otaurl to http://sonoff.maddox.co.uk/tasmota/sonoff.bin (#2588, #2602) + * + * 5.13.1 20180501 * Fix JSON buffers size too small for execution in some situations (#2580) * Add define MODULE for user selecting default model although it preferably should not be changed (#569, #2589) * Fix configuration restore (#2591) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 554a4858e..e6565c286 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050D0001 // 5.13.0a +#define VERSION 0x050D0101 // 5.13.1a // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) diff --git a/sonoff/user_config.h b/sonoff/user_config.h index 83b9a346f..1e880ec22 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -74,7 +74,7 @@ #define WEB_LOG_LEVEL LOG_LEVEL_INFO // [WebLog] (LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE) // -- Ota ----------------------------------------- -#define OTA_URL "http://sonoff.maddox.co.uk/tasmota/sonoff.ino.bin" // [OtaUrl] +#define OTA_URL "http://sonoff.maddox.co.uk/tasmota/sonoff.bin" // [OtaUrl] // -- MQTT ---------------------------------------- #define MQTT_USE 1 // [SetOption3] Select default MQTT use (0 = Off, 1 = On)