From ee8a698ca5c23890ea7f680816325f91b8af8895 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Wed, 29 Aug 2018 14:21:13 -0300 Subject: [PATCH 01/25] Added command TIMERS 2 to toggle global timers enable flag #3308 --- sonoff/xdrv_09_timers.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index f74a8d28e..229b55d69 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -455,6 +455,9 @@ boolean TimerCommand() if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { Settings.flag3.timers_enable = XdrvMailbox.payload; } + if (XdrvMailbox.payload == 2) { + Settings.flag3.timers_enable = !Settings.flag3.timers_enable; + } } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, GetStateText(Settings.flag3.timers_enable)); @@ -752,4 +755,4 @@ boolean Xdrv09(byte function) return result; } -#endif // USE_TIMERS \ No newline at end of file +#endif // USE_TIMERS From 452ad6c72ef7f9758e262add4640f03f02f8cc4d Mon Sep 17 00:00:00 2001 From: andrethomas Date: Thu, 30 Aug 2018 00:03:56 +0200 Subject: [PATCH 02/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0084c7286..f8f9c92ac 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! See [RELEASENOTES.md](https://github.com/arendst/Sonoff-Tasmota/blob/development/RELEASENOTES.md) for release information and [sonoff/_changelog.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_changelog.ino) for detailed change information. -The compiled development versions from current codebase are built around 6AM GMT+2 everyday and posted at http://thehackbox.org/tasmota/ (this web address can be used for OTA too). +The compiled development versions from current codebase are built around 6AM GMT+2 everyday and posted at http://thehackbox.org/tasmota/ (this web address can be used for OTA too). Remember that these are based on the current development codebase and it is not recommended to flash devices in hard to reach places with this firmware. ### Disclaimer :warning: **DANGER OF ELECTROCUTION** :warning: From b9a875d6fbd2e1ddd023b2dbbe320eef074905ad Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 30 Aug 2018 12:22:24 +0200 Subject: [PATCH 03/25] 6.1.1.14 Add boot loop detection Add boot loop detection and try to fix --- sonoff/_changelog.ino | 5 ++++- sonoff/i18n.h | 1 + sonoff/settings.h | 6 ++++-- sonoff/sonoff.h | 1 + sonoff/sonoff.ino | 34 +++++++++++++++++++++++++++++----- sonoff/sonoff_version.h | 2 +- sonoff/support.ino | 9 +++++++++ sonoff/xdrv_02_webserver.ino | 6 +++--- sonoff/xdrv_09_timers.ino | 2 +- 9 files changed, 53 insertions(+), 13 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 0629de523..dcc60cc55 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,7 @@ -/* 6.1.1.13 20180828 +/* 6.1.1.14 20180830 + * Add boot loop detection and try to fix + * + * 6.1.1.13 20180828 * Fix 6.1.1.12 regression of Mem and Var default handling (#3618) * Optimizations * Change define USE_ALL_SENSORS to USE_SENSORS as it doesn't contain all sensors due to duplicate I2C addresses diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 3d63f73f5..107710678 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -236,6 +236,7 @@ #define D_CMND_SERIALSEND "SerialSend" #define D_CMND_SERIALDELIMITER "SerialDelimiter" #define D_CMND_BAUDRATE "Baudrate" +#define D_LOG_SOME_SETTINGS_RESET "Some settings have been reset" // Commands xdrv_01_mqtt.ino #define D_CMND_MQTTHOST "MqttHost" diff --git a/sonoff/settings.h b/sonoff/settings.h index 618ef0b54..6eabc5c7c 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -94,7 +94,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t spare28 : 1; uint32_t spare29 : 1; uint32_t spare30 : 1; - uint32_t spare31 : 1; + uint32_t user_esp8285_enable : 1; // bit 31 (v6.1.1.13) }; } SysBitfield3; @@ -341,7 +341,9 @@ struct RTCMEM { unsigned long energy_kWhtotal; // 008 unsigned long pulse_counter[MAX_COUNTERS]; // 00C power_t power; // 01C - // 020 next free location + uint8_t fast_reboot_count; // 020 + uint8_t spare_021[3]; // 021 + // 024 next free location } RtcSettings; struct TIME_T { diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index f93df0059..3a1dc14c6 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -85,6 +85,7 @@ typedef unsigned long power_t; // Power (Relay) type #define STATES 20 // Number of states per second using 50 mSec interval #define IMMINENT_RESET_FACTOR 10 // Factor to extent button hold time for imminent Reset to default 40 seconds using KEY_HOLD_TIME of 40 +#define BOOT_LOOP_TIME 10 // Number of seconds to stop detecting boot loops #define SYSLOG_TIMER 600 // Seconds to restore syslog_level #define SERIALLOG_TIMER 600 // Seconds to disable SerialLog #define OTA_ATTEMPTS 5 // Number of times to try fetching the new firmware diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 8cd69e4cc..1bcf365b0 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1567,6 +1567,11 @@ void PerformEverySecond() { uptime++; + if (BOOT_LOOP_TIME == uptime) { + RtcSettings.fast_reboot_count = 0; + RtcSettingsSave(); + } + if ((4 == uptime) && (SONOFF_IFAN02 == Settings.module)) { // Microcontroller needs 3 seconds before accepting commands SetDevicePower(1, SRC_RETRY); // Sync with default power on state microcontroller being Light ON and Fan OFF SetDevicePower(power, SRC_RETRY); // Set required power on state @@ -2313,7 +2318,7 @@ void GpioInit() pin[i] = 99; } for (byte i = 0; i < MAX_GPIO_PIN; i++) { - mpin = my_module.gp.io[i]; + mpin = ValidGPIO(i, my_module.gp.io[i]); // snprintf_P(log_data, sizeof(log_data), PSTR("DBG: gpio pin %d, mpin %d"), i, mpin); // AddLog(LOG_LEVEL_DEBUG); @@ -2323,7 +2328,7 @@ void GpioInit() bitSet(switch_no_pullup, mpin - GPIO_SWT1_NP); mpin -= (GPIO_SWT1_NP - GPIO_SWT1); } - if ((mpin >= GPIO_KEY1_NP) && (mpin < (GPIO_KEY1_NP + MAX_KEYS))) { + else if ((mpin >= GPIO_KEY1_NP) && (mpin < (GPIO_KEY1_NP + MAX_KEYS))) { bitSet(key_no_pullup, mpin - GPIO_KEY1_NP); mpin -= (GPIO_KEY1_NP - GPIO_KEY1); } @@ -2486,6 +2491,10 @@ void setup() { byte idx; + RtcSettingsLoad(); + RtcSettings.fast_reboot_count++; + RtcSettingsSave(); + Serial.begin(baudrate); delay(10); Serial.println(); @@ -2517,10 +2526,25 @@ void setup() save_data_counter = Settings.save_data; sleep = Settings.sleep; - if ((resetInfo.reason == REASON_WDT_RST) || (resetInfo.reason == REASON_EXCEPTION_RST) || (resetInfo.reason == REASON_SOFT_WDT_RST) || OsWatchBlockedLoop()) { - for (byte i = 0; i < MAX_RULE_SETS; i++) { - if (bitRead(Settings.rule_stop, i)) { bitWrite(Settings.rule_enabled, i, 0); } + // Disable functionality as possible cause of fast reboot within BOOT_LOOP_TIME seconds (Exception or WDT) + if (RtcSettings.fast_reboot_count > 1) { // Restart twice + Settings.flag3.user_esp8285_enable = 0; // Disable ESP8285 Generic GPIOs interfering with flash SPI + if (RtcSettings.fast_reboot_count > 2) { // Restart 3 times + for (byte i = 0; i < MAX_RULE_SETS; i++) { + if (bitRead(Settings.rule_stop, i)) { + bitWrite(Settings.rule_enabled, i, 0); // Disable rules causing boot loop + } + } } + if (RtcSettings.fast_reboot_count > 3) { // Restarted 4 times + Settings.rule_enabled = 0; // Disable all rules + } + if (RtcSettings.fast_reboot_count > 4) { // Restarted 5 times + Settings.module = SONOFF_BASIC; // Use default module + Settings.last_module = SONOFF_BASIC; // Use default module + } + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_LOG_SOME_SETTINGS_RESET " (%d)"), RtcSettings.fast_reboot_count); + AddLog(LOG_LEVEL_DEBUG); } Settings.bootcount++; diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index f351b547d..72634caa1 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x0601010D +#define VERSION 0x0601010E #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/support.ino b/sonoff/support.ino index 87cd49edb..8cc064fe5 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -717,6 +717,15 @@ void ShowSource(int source) } } +uint8_t ValidGPIO(uint8_t pin, uint8_t gpio) +{ + uint8_t result = gpio; + if ((WEMOS == Settings.module) && (!Settings.flag3.user_esp8285_enable)) { + if ((pin == 9) || (pin == 10)) { result = GPIO_NONE; } // Disable possible flash GPIO9 and GPIO10 + } + return result; +} + /*********************************************************************************************\ * Sleep aware time scheduler functions borrowed from ESPEasy \*********************************************************************************************/ diff --git a/sonoff/xdrv_02_webserver.ino b/sonoff/xdrv_02_webserver.ino index 64c138a56..c919c8f43 100644 --- a/sonoff/xdrv_02_webserver.ino +++ b/sonoff/xdrv_02_webserver.ino @@ -789,7 +789,7 @@ void HandleModuleConfiguration() page += FPSTR(HTTP_SCRIPT_MODULE3); for (byte i = 0; i < MAX_GPIO_PIN; i++) { - if (GPIO_USER == cmodule.gp.io[i]) { + if (GPIO_USER == ValidGPIO(i, cmodule.gp.io[i])) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("sk(%d,%d);"), my_module.gp.io[i], i); // g0 - g16 page += mqtt_data; } @@ -803,10 +803,10 @@ void HandleModuleConfiguration() page.replace(F("{mt"), stemp); page += F("
"); for (byte i = 0; i < MAX_GPIO_PIN; i++) { - if (GPIO_USER == cmodule.gp.io[i]) { + if (GPIO_USER == ValidGPIO(i, cmodule.gp.io[i])) { snprintf_P(stemp, 3, PINS_WEMOS +i*2); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR(""), - (WEMOS==Settings.module)?stemp:"", i, (0==i)? D_SENSOR_BUTTON "1":(1==i)? D_SERIAL_OUT :(3==i)? D_SERIAL_IN :(12==i)? D_SENSOR_RELAY "1":(13==i)? D_SENSOR_LED "1i":(14==i)? D_SENSOR :"", i, i); + (WEMOS==Settings.module)?stemp:"", i, (0==i)? D_SENSOR_BUTTON "1":(1==i)? D_SERIAL_OUT :(3==i)? D_SERIAL_IN :(9==i)? "ESP8285" :(10==i)? "ESP8285" :(12==i)? D_SENSOR_RELAY "1":(13==i)? D_SENSOR_LED "1i":(14==i)? D_SENSOR :"", i, i); page += mqtt_data; } } diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index 229b55d69..0652f3b53 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -457,7 +457,7 @@ boolean TimerCommand() } if (XdrvMailbox.payload == 2) { Settings.flag3.timers_enable = !Settings.flag3.timers_enable; - } + } } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, GetStateText(Settings.flag3.timers_enable)); From 3abdaaffb747d11872de95dd1a6d9f17b7fcc019 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 30 Aug 2018 13:19:09 +0200 Subject: [PATCH 04/25] Revert "6.1.1.14 Add boot loop detection" This reverts commit b9a875d6fbd2e1ddd023b2dbbe320eef074905ad. --- sonoff/_changelog.ino | 5 +---- sonoff/i18n.h | 1 - sonoff/settings.h | 6 ++---- sonoff/sonoff.h | 1 - sonoff/sonoff.ino | 34 +++++----------------------------- sonoff/sonoff_version.h | 2 +- sonoff/support.ino | 9 --------- sonoff/xdrv_02_webserver.ino | 6 +++--- sonoff/xdrv_09_timers.ino | 2 +- 9 files changed, 13 insertions(+), 53 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index dcc60cc55..0629de523 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,7 +1,4 @@ -/* 6.1.1.14 20180830 - * Add boot loop detection and try to fix - * - * 6.1.1.13 20180828 +/* 6.1.1.13 20180828 * Fix 6.1.1.12 regression of Mem and Var default handling (#3618) * Optimizations * Change define USE_ALL_SENSORS to USE_SENSORS as it doesn't contain all sensors due to duplicate I2C addresses diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 107710678..3d63f73f5 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -236,7 +236,6 @@ #define D_CMND_SERIALSEND "SerialSend" #define D_CMND_SERIALDELIMITER "SerialDelimiter" #define D_CMND_BAUDRATE "Baudrate" -#define D_LOG_SOME_SETTINGS_RESET "Some settings have been reset" // Commands xdrv_01_mqtt.ino #define D_CMND_MQTTHOST "MqttHost" diff --git a/sonoff/settings.h b/sonoff/settings.h index 6eabc5c7c..618ef0b54 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -94,7 +94,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t spare28 : 1; uint32_t spare29 : 1; uint32_t spare30 : 1; - uint32_t user_esp8285_enable : 1; // bit 31 (v6.1.1.13) + uint32_t spare31 : 1; }; } SysBitfield3; @@ -341,9 +341,7 @@ struct RTCMEM { unsigned long energy_kWhtotal; // 008 unsigned long pulse_counter[MAX_COUNTERS]; // 00C power_t power; // 01C - uint8_t fast_reboot_count; // 020 - uint8_t spare_021[3]; // 021 - // 024 next free location + // 020 next free location } RtcSettings; struct TIME_T { diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 3a1dc14c6..f93df0059 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -85,7 +85,6 @@ typedef unsigned long power_t; // Power (Relay) type #define STATES 20 // Number of states per second using 50 mSec interval #define IMMINENT_RESET_FACTOR 10 // Factor to extent button hold time for imminent Reset to default 40 seconds using KEY_HOLD_TIME of 40 -#define BOOT_LOOP_TIME 10 // Number of seconds to stop detecting boot loops #define SYSLOG_TIMER 600 // Seconds to restore syslog_level #define SERIALLOG_TIMER 600 // Seconds to disable SerialLog #define OTA_ATTEMPTS 5 // Number of times to try fetching the new firmware diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 1bcf365b0..8cd69e4cc 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1567,11 +1567,6 @@ void PerformEverySecond() { uptime++; - if (BOOT_LOOP_TIME == uptime) { - RtcSettings.fast_reboot_count = 0; - RtcSettingsSave(); - } - if ((4 == uptime) && (SONOFF_IFAN02 == Settings.module)) { // Microcontroller needs 3 seconds before accepting commands SetDevicePower(1, SRC_RETRY); // Sync with default power on state microcontroller being Light ON and Fan OFF SetDevicePower(power, SRC_RETRY); // Set required power on state @@ -2318,7 +2313,7 @@ void GpioInit() pin[i] = 99; } for (byte i = 0; i < MAX_GPIO_PIN; i++) { - mpin = ValidGPIO(i, my_module.gp.io[i]); + mpin = my_module.gp.io[i]; // snprintf_P(log_data, sizeof(log_data), PSTR("DBG: gpio pin %d, mpin %d"), i, mpin); // AddLog(LOG_LEVEL_DEBUG); @@ -2328,7 +2323,7 @@ void GpioInit() bitSet(switch_no_pullup, mpin - GPIO_SWT1_NP); mpin -= (GPIO_SWT1_NP - GPIO_SWT1); } - else if ((mpin >= GPIO_KEY1_NP) && (mpin < (GPIO_KEY1_NP + MAX_KEYS))) { + if ((mpin >= GPIO_KEY1_NP) && (mpin < (GPIO_KEY1_NP + MAX_KEYS))) { bitSet(key_no_pullup, mpin - GPIO_KEY1_NP); mpin -= (GPIO_KEY1_NP - GPIO_KEY1); } @@ -2491,10 +2486,6 @@ void setup() { byte idx; - RtcSettingsLoad(); - RtcSettings.fast_reboot_count++; - RtcSettingsSave(); - Serial.begin(baudrate); delay(10); Serial.println(); @@ -2526,25 +2517,10 @@ void setup() save_data_counter = Settings.save_data; sleep = Settings.sleep; - // Disable functionality as possible cause of fast reboot within BOOT_LOOP_TIME seconds (Exception or WDT) - if (RtcSettings.fast_reboot_count > 1) { // Restart twice - Settings.flag3.user_esp8285_enable = 0; // Disable ESP8285 Generic GPIOs interfering with flash SPI - if (RtcSettings.fast_reboot_count > 2) { // Restart 3 times - for (byte i = 0; i < MAX_RULE_SETS; i++) { - if (bitRead(Settings.rule_stop, i)) { - bitWrite(Settings.rule_enabled, i, 0); // Disable rules causing boot loop - } - } + if ((resetInfo.reason == REASON_WDT_RST) || (resetInfo.reason == REASON_EXCEPTION_RST) || (resetInfo.reason == REASON_SOFT_WDT_RST) || OsWatchBlockedLoop()) { + for (byte i = 0; i < MAX_RULE_SETS; i++) { + if (bitRead(Settings.rule_stop, i)) { bitWrite(Settings.rule_enabled, i, 0); } } - if (RtcSettings.fast_reboot_count > 3) { // Restarted 4 times - Settings.rule_enabled = 0; // Disable all rules - } - if (RtcSettings.fast_reboot_count > 4) { // Restarted 5 times - Settings.module = SONOFF_BASIC; // Use default module - Settings.last_module = SONOFF_BASIC; // Use default module - } - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_LOG_SOME_SETTINGS_RESET " (%d)"), RtcSettings.fast_reboot_count); - AddLog(LOG_LEVEL_DEBUG); } Settings.bootcount++; diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 72634caa1..f351b547d 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x0601010E +#define VERSION 0x0601010D #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/support.ino b/sonoff/support.ino index 8cc064fe5..87cd49edb 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -717,15 +717,6 @@ void ShowSource(int source) } } -uint8_t ValidGPIO(uint8_t pin, uint8_t gpio) -{ - uint8_t result = gpio; - if ((WEMOS == Settings.module) && (!Settings.flag3.user_esp8285_enable)) { - if ((pin == 9) || (pin == 10)) { result = GPIO_NONE; } // Disable possible flash GPIO9 and GPIO10 - } - return result; -} - /*********************************************************************************************\ * Sleep aware time scheduler functions borrowed from ESPEasy \*********************************************************************************************/ diff --git a/sonoff/xdrv_02_webserver.ino b/sonoff/xdrv_02_webserver.ino index c919c8f43..64c138a56 100644 --- a/sonoff/xdrv_02_webserver.ino +++ b/sonoff/xdrv_02_webserver.ino @@ -789,7 +789,7 @@ void HandleModuleConfiguration() page += FPSTR(HTTP_SCRIPT_MODULE3); for (byte i = 0; i < MAX_GPIO_PIN; i++) { - if (GPIO_USER == ValidGPIO(i, cmodule.gp.io[i])) { + if (GPIO_USER == cmodule.gp.io[i]) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("sk(%d,%d);"), my_module.gp.io[i], i); // g0 - g16 page += mqtt_data; } @@ -803,10 +803,10 @@ void HandleModuleConfiguration() page.replace(F("{mt"), stemp); page += F("
%s " D_GPIO "%d %s
"); for (byte i = 0; i < MAX_GPIO_PIN; i++) { - if (GPIO_USER == ValidGPIO(i, cmodule.gp.io[i])) { + if (GPIO_USER == cmodule.gp.io[i]) { snprintf_P(stemp, 3, PINS_WEMOS +i*2); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR(""), - (WEMOS==Settings.module)?stemp:"", i, (0==i)? D_SENSOR_BUTTON "1":(1==i)? D_SERIAL_OUT :(3==i)? D_SERIAL_IN :(9==i)? "ESP8285" :(10==i)? "ESP8285" :(12==i)? D_SENSOR_RELAY "1":(13==i)? D_SENSOR_LED "1i":(14==i)? D_SENSOR :"", i, i); + (WEMOS==Settings.module)?stemp:"", i, (0==i)? D_SENSOR_BUTTON "1":(1==i)? D_SERIAL_OUT :(3==i)? D_SERIAL_IN :(12==i)? D_SENSOR_RELAY "1":(13==i)? D_SENSOR_LED "1i":(14==i)? D_SENSOR :"", i, i); page += mqtt_data; } } diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index 0652f3b53..229b55d69 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -457,7 +457,7 @@ boolean TimerCommand() } if (XdrvMailbox.payload == 2) { Settings.flag3.timers_enable = !Settings.flag3.timers_enable; - } + } } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, GetStateText(Settings.flag3.timers_enable)); From f7c38f24f3b7f1ad0c2ac0951b9629b4b3d6c616 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 30 Aug 2018 14:27:33 +0200 Subject: [PATCH 05/25] 6.1.1.14 Add boot loop detection Add boot loop detection and try to fix --- sonoff/_changelog.ino | 5 ++++- sonoff/i18n.h | 1 + sonoff/settings.h | 7 +++++-- sonoff/settings.ino | 8 ++++++++ sonoff/sonoff.h | 1 + sonoff/sonoff.ino | 35 ++++++++++++++++++++++++++++++----- sonoff/sonoff_template.h | 28 ++++++++++++++++++++++++++-- sonoff/sonoff_version.h | 2 +- sonoff/support.ino | 9 +++++++++ sonoff/xdrv_02_webserver.ino | 6 +++--- sonoff/xdrv_09_timers.ino | 2 +- 11 files changed, 89 insertions(+), 15 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 0629de523..dcc60cc55 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,7 @@ -/* 6.1.1.13 20180828 +/* 6.1.1.14 20180830 + * Add boot loop detection and try to fix + * + * 6.1.1.13 20180828 * Fix 6.1.1.12 regression of Mem and Var default handling (#3618) * Optimizations * Change define USE_ALL_SENSORS to USE_SENSORS as it doesn't contain all sensors due to duplicate I2C addresses diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 3d63f73f5..107710678 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -236,6 +236,7 @@ #define D_CMND_SERIALSEND "SerialSend" #define D_CMND_SERIALDELIMITER "SerialDelimiter" #define D_CMND_BAUDRATE "Baudrate" +#define D_LOG_SOME_SETTINGS_RESET "Some settings have been reset" // Commands xdrv_01_mqtt.ino #define D_CMND_MQTTHOST "MqttHost" diff --git a/sonoff/settings.h b/sonoff/settings.h index 618ef0b54..ded2c140b 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -94,7 +94,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t spare28 : 1; uint32_t spare29 : 1; uint32_t spare30 : 1; - uint32_t spare31 : 1; + uint32_t user_esp8285_enable : 1; // bit 31 (v6.1.1.14) }; } SysBitfield3; @@ -341,7 +341,10 @@ struct RTCMEM { unsigned long energy_kWhtotal; // 008 unsigned long pulse_counter[MAX_COUNTERS]; // 00C power_t power; // 01C - // 020 next free location + uint16_t extended_valid; // 020 Extended valid flag (v6.1.1.14) + uint8_t fast_reboot_count; // 022 + uint8_t free_023[57]; // 023 + // 05C next free location (64 (=core) + 100 (=tasmota offset) + 92 (=0x5C RTCMEM struct) = 256 bytes (max = 512)) } RtcSettings; struct TIME_T { diff --git a/sonoff/settings.ino b/sonoff/settings.ino index e0a40a17c..cba043696 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -84,6 +84,7 @@ void RtcSettingsSave() { if (GetRtcSettingsCrc() != rtc_settings_crc) { RtcSettings.valid = RTC_MEM_VALID; + RtcSettings.extended_valid = RTC_MEM_VALID; ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RTCMEM)); rtc_settings_crc = GetRtcSettingsCrc(); #ifdef DEBUG_THEO @@ -103,12 +104,14 @@ void RtcSettingsLoad() if (RtcSettings.valid != RTC_MEM_VALID) { memset(&RtcSettings, 0, sizeof(RTCMEM)); RtcSettings.valid = RTC_MEM_VALID; + RtcSettings.extended_valid = RTC_MEM_VALID; RtcSettings.energy_kWhtoday = Settings.energy_kWhtoday; RtcSettings.energy_kWhtotal = Settings.energy_kWhtotal; for (byte i = 0; i < MAX_COUNTERS; i++) { RtcSettings.pulse_counter[i] = Settings.pulse_counter[i]; } RtcSettings.power = Settings.power; +// RtcSettings.fast_reboot_count = 0; // Explicit by memset RtcSettingsSave(); } rtc_settings_crc = GetRtcSettingsCrc(); @@ -119,6 +122,11 @@ boolean RtcSettingsValid() return (RTC_MEM_VALID == RtcSettings.valid); } +boolean RtcSettingsExtendedValid() +{ + return (RTC_MEM_VALID == RtcSettings.extended_valid); +} + /*********************************************************************************************\ * Config - Flash \*********************************************************************************************/ diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index f93df0059..3a1dc14c6 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -85,6 +85,7 @@ typedef unsigned long power_t; // Power (Relay) type #define STATES 20 // Number of states per second using 50 mSec interval #define IMMINENT_RESET_FACTOR 10 // Factor to extent button hold time for imminent Reset to default 40 seconds using KEY_HOLD_TIME of 40 +#define BOOT_LOOP_TIME 10 // Number of seconds to stop detecting boot loops #define SYSLOG_TIMER 600 // Seconds to restore syslog_level #define SERIALLOG_TIMER 600 // Seconds to disable SerialLog #define OTA_ATTEMPTS 5 // Number of times to try fetching the new firmware diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 8cd69e4cc..2e080aa18 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1567,6 +1567,11 @@ void PerformEverySecond() { uptime++; + if (BOOT_LOOP_TIME == uptime) { + RtcSettings.fast_reboot_count = 0; + RtcSettingsSave(); + } + if ((4 == uptime) && (SONOFF_IFAN02 == Settings.module)) { // Microcontroller needs 3 seconds before accepting commands SetDevicePower(1, SRC_RETRY); // Sync with default power on state microcontroller being Light ON and Fan OFF SetDevicePower(power, SRC_RETRY); // Set required power on state @@ -2313,7 +2318,7 @@ void GpioInit() pin[i] = 99; } for (byte i = 0; i < MAX_GPIO_PIN; i++) { - mpin = my_module.gp.io[i]; + mpin = ValidGPIO(i, my_module.gp.io[i]); // snprintf_P(log_data, sizeof(log_data), PSTR("DBG: gpio pin %d, mpin %d"), i, mpin); // AddLog(LOG_LEVEL_DEBUG); @@ -2323,7 +2328,7 @@ void GpioInit() bitSet(switch_no_pullup, mpin - GPIO_SWT1_NP); mpin -= (GPIO_SWT1_NP - GPIO_SWT1); } - if ((mpin >= GPIO_KEY1_NP) && (mpin < (GPIO_KEY1_NP + MAX_KEYS))) { + else if ((mpin >= GPIO_KEY1_NP) && (mpin < (GPIO_KEY1_NP + MAX_KEYS))) { bitSet(key_no_pullup, mpin - GPIO_KEY1_NP); mpin -= (GPIO_KEY1_NP - GPIO_KEY1); } @@ -2486,6 +2491,11 @@ void setup() { byte idx; + RtcSettingsLoad(); + if (!RtcSettingsExtendedValid()) { RtcSettings.fast_reboot_count = 0; } + RtcSettings.fast_reboot_count++; + RtcSettingsSave(); + Serial.begin(baudrate); delay(10); Serial.println(); @@ -2517,10 +2527,25 @@ void setup() save_data_counter = Settings.save_data; sleep = Settings.sleep; - if ((resetInfo.reason == REASON_WDT_RST) || (resetInfo.reason == REASON_EXCEPTION_RST) || (resetInfo.reason == REASON_SOFT_WDT_RST) || OsWatchBlockedLoop()) { - for (byte i = 0; i < MAX_RULE_SETS; i++) { - if (bitRead(Settings.rule_stop, i)) { bitWrite(Settings.rule_enabled, i, 0); } + // Disable functionality as possible cause of fast reboot within BOOT_LOOP_TIME seconds (Exception or WDT) + if (RtcSettings.fast_reboot_count > 1) { // Restart twice + Settings.flag3.user_esp8285_enable = 0; // Disable ESP8285 Generic GPIOs interfering with flash SPI + if (RtcSettings.fast_reboot_count > 2) { // Restart 3 times + for (byte i = 0; i < MAX_RULE_SETS; i++) { + if (bitRead(Settings.rule_stop, i)) { + bitWrite(Settings.rule_enabled, i, 0); // Disable rules causing boot loop + } + } } + if (RtcSettings.fast_reboot_count > 3) { // Restarted 4 times + Settings.rule_enabled = 0; // Disable all rules + } + if (RtcSettings.fast_reboot_count > 4) { // Restarted 5 times + Settings.module = SONOFF_BASIC; // Use default module + Settings.last_module = SONOFF_BASIC; // Use default module + } + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_LOG_SOME_SETTINGS_RESET " (%d)"), RtcSettings.fast_reboot_count); + AddLog(LOG_LEVEL_DEBUG); } Settings.bootcount++; diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index 180c24aec..84a0749dc 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -226,7 +226,7 @@ enum SupportedModules { #define MAX_GPIO_PIN 18 // Number of supported GPIO -const char PINS_WEMOS[] PROGMEM = "D3TXD4RXD2D1flashcontrolD6D7D5D8D0A0"; +const char PINS_WEMOS[] PROGMEM = "D3TXD4RXD2D1flashcFLFLolD6D7D5D8D0A0"; typedef struct MYIO { uint8_t io[MAX_GPIO_PIN]; @@ -514,7 +514,10 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_USER, // GPIO03 RX Serial TXD and Optional sensor GPIO_USER, // GPIO04 D2 Wemos I2C SDA GPIO_USER, // GPIO05 D1 Wemos I2C SCL / Wemos Relay Shield (0 = Off, 1 = On) / Wemos WS2812B RGB led Shield - 0, 0, 0, 0, 0, 0, // Flash connection + 0, 0, 0, // Flash connection + GPIO_USER, // Flash connection or GPIO09 on ESP8285 only! + GPIO_USER, // Flash connection or GPIO10 on ESP8285 only! + 0, // Flash connection GPIO_USER, // GPIO12 D6 GPIO_USER, // GPIO13 D7 GPIO_USER, // GPIO14 D5 @@ -987,6 +990,27 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { 0 // ADC0 Analog input (A0) }, + { "Shelly 1", // Shelly1 Open Source (ESP8266 - 2MB) - https://shelly.cloud/shelly1-open-source/ + GPIO_KEY1, // GPIO00 Button + GPIO_USER, // GPIO01 Serial RXD and Optional sensor + 0, + GPIO_USER, // GPIO03 Serial TXD and Optional sensor + GPIO_REL1, // GPIO04 Relay (0 = Off, 1 = On) + GPIO_SWT1_NP, // GPIO05 Switch + 0, 0, 0, 0, 0, 0, // Flash connection + 0, 0, 0, 0, 0, 0 + }, + { "Shelly 2", // Shelly2 (ESP8266 - 2MB) - https://shelly.cloud/shelly2/ + // As Gnd is connected to AC no user GPIO allowed + 0, 0, 0, 0, + GPIO_REL1, // GPIO04 Relay 1 (0 = Off, 1 = On) + GPIO_REL2, // GPIO05 Relay 2 (0 = Off, 1 = On) + 0, 0, 0, 0, 0, 0, // Flash connection + GPIO_SWT1_NP, // GPIO12 Switch 1 + 0, + GPIO_SWT2_NP, // GPIO14 Switch 2 + 0, 0, 0 + }, */ #endif // _SONOFF_TEMPLATE_H_ \ No newline at end of file diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index f351b547d..72634caa1 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x0601010D +#define VERSION 0x0601010E #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/support.ino b/sonoff/support.ino index 87cd49edb..8cc064fe5 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -717,6 +717,15 @@ void ShowSource(int source) } } +uint8_t ValidGPIO(uint8_t pin, uint8_t gpio) +{ + uint8_t result = gpio; + if ((WEMOS == Settings.module) && (!Settings.flag3.user_esp8285_enable)) { + if ((pin == 9) || (pin == 10)) { result = GPIO_NONE; } // Disable possible flash GPIO9 and GPIO10 + } + return result; +} + /*********************************************************************************************\ * Sleep aware time scheduler functions borrowed from ESPEasy \*********************************************************************************************/ diff --git a/sonoff/xdrv_02_webserver.ino b/sonoff/xdrv_02_webserver.ino index 64c138a56..c919c8f43 100644 --- a/sonoff/xdrv_02_webserver.ino +++ b/sonoff/xdrv_02_webserver.ino @@ -789,7 +789,7 @@ void HandleModuleConfiguration() page += FPSTR(HTTP_SCRIPT_MODULE3); for (byte i = 0; i < MAX_GPIO_PIN; i++) { - if (GPIO_USER == cmodule.gp.io[i]) { + if (GPIO_USER == ValidGPIO(i, cmodule.gp.io[i])) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("sk(%d,%d);"), my_module.gp.io[i], i); // g0 - g16 page += mqtt_data; } @@ -803,10 +803,10 @@ void HandleModuleConfiguration() page.replace(F("{mt"), stemp); page += F("
%s " D_GPIO "%d %s
"); for (byte i = 0; i < MAX_GPIO_PIN; i++) { - if (GPIO_USER == cmodule.gp.io[i]) { + if (GPIO_USER == ValidGPIO(i, cmodule.gp.io[i])) { snprintf_P(stemp, 3, PINS_WEMOS +i*2); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR(""), - (WEMOS==Settings.module)?stemp:"", i, (0==i)? D_SENSOR_BUTTON "1":(1==i)? D_SERIAL_OUT :(3==i)? D_SERIAL_IN :(12==i)? D_SENSOR_RELAY "1":(13==i)? D_SENSOR_LED "1i":(14==i)? D_SENSOR :"", i, i); + (WEMOS==Settings.module)?stemp:"", i, (0==i)? D_SENSOR_BUTTON "1":(1==i)? D_SERIAL_OUT :(3==i)? D_SERIAL_IN :(9==i)? "ESP8285" :(10==i)? "ESP8285" :(12==i)? D_SENSOR_RELAY "1":(13==i)? D_SENSOR_LED "1i":(14==i)? D_SENSOR :"", i, i); page += mqtt_data; } } diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index 229b55d69..0652f3b53 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -457,7 +457,7 @@ boolean TimerCommand() } if (XdrvMailbox.payload == 2) { Settings.flag3.timers_enable = !Settings.flag3.timers_enable; - } + } } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, GetStateText(Settings.flag3.timers_enable)); From 2212af48609388e1ec5a5804d9429b274f26960c Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 30 Aug 2018 14:47:48 +0200 Subject: [PATCH 06/25] Clear GPIO on multi boot loop Clear GPIO on multi boot loop --- RELEASENOTES.md | 1 + sonoff/_changelog.ino | 2 +- sonoff/sonoff.ino | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index a55440abe..7cacefa47 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -140,6 +140,7 @@ Version 6.2.0 20180901 * Fix Sonoff Bridge data reception when using Portisch EFM8 firmware using in data buffer length (#3605) * Add read sensor retry to DS18B20, DS18x20, DHT, SHT1X and HTU21 * Add user selection of Wifi Smartconfig as define USE_SMARTCONFIG in user_config.h + * Add boot loop detection and perform some solutions * Add wifi and mqtt status led blinkyblinky to be disabled by SetOption31 1. Does not work when LedPower is On (deliberate) (#871, #2230, #3114, #3155) * Add support for TM1638 switch (#2226) * Add GPIO options ButtonXn, SwitchXn and CounterXn to select INPUT mode instead of INPUT_PULLUP (#2525) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index dcc60cc55..ca71946ab 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,5 +1,5 @@ /* 6.1.1.14 20180830 - * Add boot loop detection and try to fix + * Add boot loop detection and perform some solutions * * 6.1.1.13 20180828 * Fix 6.1.1.12 regression of Mem and Var default handling (#3618) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 2e080aa18..254f88184 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2527,7 +2527,7 @@ void setup() save_data_counter = Settings.save_data; sleep = Settings.sleep; - // Disable functionality as possible cause of fast reboot within BOOT_LOOP_TIME seconds (Exception or WDT) + // Disable functionality as possible cause of fast restart within BOOT_LOOP_TIME seconds (Exception, WDT or restarts) if (RtcSettings.fast_reboot_count > 1) { // Restart twice Settings.flag3.user_esp8285_enable = 0; // Disable ESP8285 Generic GPIOs interfering with flash SPI if (RtcSettings.fast_reboot_count > 2) { // Restart 3 times @@ -2541,8 +2541,11 @@ void setup() Settings.rule_enabled = 0; // Disable all rules } if (RtcSettings.fast_reboot_count > 4) { // Restarted 5 times - Settings.module = SONOFF_BASIC; // Use default module - Settings.last_module = SONOFF_BASIC; // Use default module + Settings.module = SONOFF_BASIC; // Reset module to Sonoff Basic + Settings.last_module = SONOFF_BASIC; + for (byte i = 0; i < MAX_GPIO_PIN; i++) { + Settings.my_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors + } } snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_LOG_SOME_SETTINGS_RESET " (%d)"), RtcSettings.fast_reboot_count); AddLog(LOG_LEVEL_DEBUG); From bd4048143e9ed6051a535e77428f4497b2b15e9f Mon Sep 17 00:00:00 2001 From: Jason2866 Date: Thu, 30 Aug 2018 18:12:21 +0200 Subject: [PATCH 07/25] Update xsns_27_apds9960.ino New Version from Staars https://github.com/Staars/Sonoff-Tasmota/tree/development/sonoff --- sonoff/xsns_27_apds9960.ino | 372 +++++++++++++----------------------- 1 file changed, 137 insertions(+), 235 deletions(-) diff --git a/sonoff/xsns_27_apds9960.ino b/sonoff/xsns_27_apds9960.ino index 151d9b732..2907bc030 100644 --- a/sonoff/xsns_27_apds9960.ino +++ b/sonoff/xsns_27_apds9960.ino @@ -54,6 +54,9 @@ #define APDS9960_CHIPID_1 0xAB #define APDS9960_CHIPID_2 0x9C +#define APDS9930_CHIPID_1 0x12 // we will check, if someone got an incorrect sensor +#define APDS9930_CHIPID_2 0x39 // there are case reports about "accidentially bought" 9930's + /* Gesture parameters */ #define GESTURE_THRESHOLD_OUT 10 #define GESTURE_SENSITIVITY_1 50 @@ -75,7 +78,9 @@ const char HTTP_APDS_9960_SNS[] PROGMEM = "%s" "{s}" "Red" "{m}%s{e}" "{s}" "Green" "{m}%s{e}" "{s}" "Blue" "{m}%s{e}" - "{s}" "Ambient" "{m}%s " D_UNIT_LUX "{e}" + "{s}" "Ambient" "{m}%s{e}" + "{s}" "Illuminance" "{m}%s " D_UNIT_LUX "{e}" + "{s}" "CCT" "{m}%s " "K" "{e}" // calculated color temperature in Kelvin "{s}" "Proximity" "{m}%s{e}"; // {s} = #endif // USE_WEBSERVER @@ -207,7 +212,7 @@ const char HTTP_APDS_9960_SNS[] PROGMEM = "%s" #define DEFAULT_ATIME 219 // 103ms #define DEFAULT_WTIME 246 // 27ms #define DEFAULT_PROX_PPULSE 0x87 // 16us, 8 pulses -#define DEFAULT_GESTURE_PPULSE 0x89 // 16us, 10 pulses +#define DEFAULT_GESTURE_PPULSE 0x89 // 16us, 10 pulses ---89 #define DEFAULT_POFFSET_UR 0 // 0 offset #define DEFAULT_POFFSET_DL 0 // 0 offset #define DEFAULT_CONFIG1 0x60 // No 12x wait (WTIME) factor @@ -225,8 +230,8 @@ const char HTTP_APDS_9960_SNS[] PROGMEM = "%s" #define DEFAULT_GEXTH 30 // Threshold for exiting gesture mode #define DEFAULT_GCONF1 0x40 // 4 gesture events for int., 1 for exit #define DEFAULT_GGAIN GGAIN_4X -#define DEFAULT_GLDRIVE LED_DRIVE_100MA -#define DEFAULT_GWTIME GWTIME_2_8MS +#define DEFAULT_GLDRIVE LED_DRIVE_100MA // default 100ma +#define DEFAULT_GWTIME GWTIME_2_8MS // default 2_8MS #define DEFAULT_GOFFSET 0 // No offset scaling for gesture mode #define DEFAULT_GPULSE 0xC9 // 32us, 10 pulses #define DEFAULT_GCONF3 0 // All photodiodes active during gesture @@ -271,6 +276,19 @@ typedef struct gesture_data_type { int16_t gesture_state_ = 0; int16_t gesture_motion_ = DIR_NONE; + typedef struct color_data_type { + uint16_t a; // measured ambient + uint16_t r; + uint16_t g; + uint16_t b; + uint8_t p; // proximity + uint16_t cct; // calculated color temperature + uint16_t lux; // calculated illuminance - atm only from rgb + } color_data_type; + + color_data_type color_data; + + /******************************************************************************* * Helper functions ******************************************************************************/ @@ -299,6 +317,7 @@ typedef struct gesture_data_type { * @param[in] len number of bytes to read * @return Number of bytes read. -1 on read error. */ + int8_t wireReadDataBlock( uint8_t reg, uint8_t *val, uint16_t len) @@ -323,6 +342,51 @@ int8_t wireReadDataBlock( uint8_t reg, return i; } +/** +* Taken from the Adafruit-library +* @brief Converts the raw R/G/B values to color temperature in degrees +* Kelvin +*/ + +void calculateColorTemperature() +{ + float X, Y, Z; /* RGB to XYZ correlation */ + float xc, yc; /* Chromaticity co-ordinates */ + float n; /* McCamy's formula */ + float cct; + + /* 1. Map RGB values to their XYZ counterparts. */ + /* Based on 6500K fluorescent, 3000K fluorescent */ + /* and 60W incandescent values for a wide range. */ + /* Note: Y = Illuminance or lux */ + X = (-0.14282F * color_data.r) + (1.54924F * color_data.g) + (-0.95641F * color_data.b); + Y = (-0.32466F * color_data.r) + (1.57837F * color_data.g) + (-0.73191F * color_data.b); // this is Lux + Z = (-0.68202F * color_data.r) + (0.77073F * color_data.g) + ( 0.56332F * color_data.b); + + /* 2. Calculate the chromaticity co-ordinates */ + xc = (X) / (X + Y + Z); + yc = (Y) / (X + Y + Z); + + /* 3. Use McCamy's formula to determine the CCT */ + n = (xc - 0.3320F) / (0.1858F - yc); + + /* Calculate the final CCT */ + color_data.cct = (449.0F * powf(n, 3)) + (3525.0F * powf(n, 2)) + (6823.3F * n) + 5520.33F; + color_data.lux = Y; // according to Adafruit code comments this seems to be not a perfect solution + + return; +} + +/** +* Taken from the Adafruit-Library +* @brief Implements missing powf function +*/ + +float powf(const float x, const float y) +{ + return (float)(pow((double)x, (double)y)); +} + /******************************************************************************* * Getters and setters for register values ******************************************************************************/ @@ -1260,6 +1324,8 @@ bool APDS9960_init() setGestureIntEnable(DEFAULT_GIEN); + disablePower(); // go to sleep + return true; } /******************************************************************************* @@ -1318,20 +1384,13 @@ void setMode(uint8_t mode, uint8_t enable) /** * @brief Starts the light (R/G/B/Ambient) sensor on the APDS-9960 * - * @param[in] interrupts true to enable hardware interrupt on high or low light + * no interrupts */ -void enableLightSensor(bool interrupts) +void enableLightSensor() { - /* Set default gain, interrupts, enable power, and enable sensor */ setAmbientLightGain(DEFAULT_AGAIN); - if( interrupts ) { - setAmbientLightIntEnable(1) ; - - } - else { - setAmbientLightIntEnable(0); - } + setAmbientLightIntEnable(0); enablePower() ; setMode(AMBIENT_LIGHT, 1) ; } @@ -1349,18 +1408,14 @@ void disableLightSensor() /** * @brief Starts the proximity sensor on the APDS-9960 * - * @param[in] interrupts true to enable hardware external interrupt on proximity + * no interrupts */ -void enableProximitySensor(bool interrupts) +void enableProximitySensor() { /* Set default gain, LED, interrupts, enable power, and enable sensor */ setProximityGain(DEFAULT_PGAIN); setLEDDrive(DEFAULT_LDRIVE) ; - if( interrupts ) { - setProximityIntEnable(1) ; - } else { - setProximityIntEnable(0) ; - } + setProximityIntEnable(0) ; enablePower(); setMode(PROXIMITY, 1) ; } @@ -1378,26 +1433,22 @@ void disableProximitySensor() /** * @brief Starts the gesture recognition engine on the APDS-9960 * - * @param[in] interrupts true to enable hardware external interrupt on gesture + * no interrupts */ -void enableGestureSensor(bool interrupts) +void enableGestureSensor() { - /* Enable gesture mode Set ENABLE to 0 (power off) Set WTIME to 0xFF Set AUX to LED_BOOST_300 Enable PON, WEN, PEN, GEN in ENABLE */ + resetGestureParameters(); I2cWrite8(APDS9960_I2C_ADDR, APDS9960_WTIME, 0xFF) ; I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PPULSE, DEFAULT_GESTURE_PPULSE) ; - setLEDBoost(LED_BOOST_100); // tip from jonn26 - 100 for 300 - if( interrupts ) { - setGestureIntEnable(1) ; - } else { - setGestureIntEnable(0) ; - } + setLEDBoost(LED_BOOST_100); // tip from jonn26 - 100 for 300 ---- 200 from Adafruit + setGestureIntEnable(0) ; setGestureMode(1); enablePower() ; setMode(WAIT, 1) ; @@ -1482,11 +1533,6 @@ int16_t readGesture() /* Read the current FIFO level */ fifo_level = I2cRead8(APDS9960_I2C_ADDR,APDS9960_GFLVL) ; -#if DEBUG - Serial.print("FIFO Level: "); - Serial.println(fifo_level); -#endif - /* If there's stuff in the FIFO, read it into our data block */ if( fifo_level > 0) { bytes_read = wireReadDataBlock( APDS9960_GFIFO_U, @@ -1495,14 +1541,6 @@ int16_t readGesture() if( bytes_read == -1 ) { return ERROR; } -#if DEBUG - Serial.print("FIFO Dump: "); - for ( i = 0; i < bytes_read; i++ ) { - Serial.print(fifo_data[i]); - Serial.print(" "); - } - Serial.println(); -#endif /* If at least 1 set of data, sort the data into U/D/L/R */ if( bytes_read >= 4 ) { @@ -1518,26 +1556,12 @@ int16_t readGesture() gesture_data_.index++; gesture_data_.total_gestures++; } - -#if DEBUG - Serial.print("Up Data: "); - for ( i = 0; i < gesture_data_.total_gestures; i++ ) { - Serial.print(gesture_data_.u_data[i]); - Serial.print(" "); - } - Serial.println(); -#endif - /* Filter and process gesture data. Decode near/far state */ if( processGestureData() ) { if( decodeGesture() ) { //***TODO: U-Turn Gestures -#if DEBUG - //Serial.println(gesture_motion_); -#endif } } - /* Reset data */ gesture_data_.index = 0; gesture_data_.total_gestures = 0; @@ -1549,10 +1573,6 @@ int16_t readGesture() delay(FIFO_PAUSE_TIME); decodeGesture(); motion = gesture_motion_; -#if DEBUG - Serial.print("END: "); - Serial.println(gesture_motion_); -#endif resetGestureParameters(); return motion; } @@ -1581,97 +1601,18 @@ void disablePower() * Ambient light and color sensor controls ******************************************************************************/ -/** - * @brief Reads the ambient (clear) light level as a 16-bit value - * - * @param[out] val value of the light sensor. - */ -void readAmbientLight(uint16_t &val) + /** + * @brief Reads the ARGB-Data and fills color_data + * + */ + +void readAllColorAndProximityData() { - uint8_t val_byte; - val = 0; - - /* Read value from clear channel, low byte register */ - val_byte = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CDATAL); - val = val_byte; - - /* Read value from clear channel, high byte register */ - val_byte = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CDATAH); - val = val + ((uint16_t)val_byte << 8); -} - -/** - * @brief Reads the red light level as a 16-bit value - * - * @param[out] val value of the light sensor. - */ -void readRedLight(uint16_t &val) -{ - uint8_t val_byte; - val = 0; - - /* Read value from clear channel, low byte register */ - val_byte = I2cRead8(APDS9960_I2C_ADDR, APDS9960_RDATAL) ; - val = val_byte; - - /* Read value from clear channel, high byte register */ - val_byte = I2cRead8(APDS9960_I2C_ADDR, APDS9960_RDATAH) ; - val = val + ((uint16_t)val_byte << 8); -} - -/** - * @brief Reads the green light level as a 16-bit value - * - * @param[out] val value of the light sensor. - */ -void readGreenLight(uint16_t &val) -{ - uint8_t val_byte; - val = 0; - - /* Read value from clear channel, low byte register */ - val_byte = I2cRead8(APDS9960_I2C_ADDR, APDS9960_GDATAL) ; - val = val_byte; - - /* Read value from clear channel, high byte register */ - val_byte = I2cRead8(APDS9960_I2C_ADDR, APDS9960_GDATAH) ; - val = val + ((uint16_t)val_byte << 8); -} - -/** - * @brief Reads the red light level as a 16-bit value - * - * @param[out] val value of the light sensor. - */ -void readBlueLight(uint16_t &val) -{ - uint8_t val_byte; - val = 0; - - /* Read value from clear channel, low byte register */ - val_byte = I2cRead8(APDS9960_I2C_ADDR, APDS9960_BDATAL) ; - val = val_byte; - - /* Read value from clear channel, high byte register */ - val_byte = I2cRead8(APDS9960_I2C_ADDR, APDS9960_BDATAH) ; - val = val + ((uint16_t)val_byte << 8); -} - -/******************************************************************************* - * Proximity sensor controls - ******************************************************************************/ - -/** - * @brief Reads the proximity level as an 8-bit value - * - * @param[out] val value of the proximity sensor. - */ -void readProximity(uint8_t &val) -{ - val = 0; - - /* Read value from proximity data register */ - val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PDATA) ; + if (I2cReadBuffer(APDS9960_I2C_ADDR, APDS9960_CDATAL, (uint8_t *) &color_data, (uint16_t)9)) + { + // not absolutely shure, if this is a correct way to do this, but it is very short + // we fill the struct byte by byte + } } /******************************************************************************* @@ -1751,17 +1692,7 @@ bool processGestureData() } /* Find the last value in U/D/L/R above the threshold */ for( i = gesture_data_.total_gestures - 1; i >= 0; i-- ) { -#if DEBUG - Serial.print(F("Finding last: ")); - Serial.print(F("U:")); - Serial.print(gesture_data_.u_data[i]); - Serial.print(F(" D:")); - Serial.print(gesture_data_.d_data[i]); - Serial.print(F(" L:")); - Serial.print(gesture_data_.l_data[i]); - Serial.print(F(" R:")); - Serial.println(gesture_data_.r_data[i]); -#endif + if( (gesture_data_.u_data[i] > GESTURE_THRESHOLD_OUT) && (gesture_data_.d_data[i] > GESTURE_THRESHOLD_OUT) && (gesture_data_.l_data[i] > GESTURE_THRESHOLD_OUT) && @@ -1782,52 +1713,14 @@ bool processGestureData() ud_ratio_last = ((u_last - d_last) * 100) / (u_last + d_last); lr_ratio_last = ((l_last - r_last) * 100) / (l_last + r_last); -#if DEBUG - Serial.print(F("Last Values: ")); - Serial.print(F("U:")); - Serial.print(u_last); - Serial.print(F(" D:")); - Serial.print(d_last); - Serial.print(F(" L:")); - Serial.print(l_last); - Serial.print(F(" R:")); - Serial.println(r_last); - - Serial.print(F("Ratios: ")); - Serial.print(F("UD Fi: ")); - Serial.print(ud_ratio_first); - Serial.print(F(" UD La: ")); - Serial.print(ud_ratio_last); - Serial.print(F(" LR Fi: ")); - Serial.print(lr_ratio_first); - Serial.print(F(" LR La: ")); - Serial.println(lr_ratio_last); -#endif - /* Determine the difference between the first and last ratios */ ud_delta = ud_ratio_last - ud_ratio_first; lr_delta = lr_ratio_last - lr_ratio_first; -#if DEBUG - Serial.print("Deltas: "); - Serial.print("UD: "); - Serial.print(ud_delta); - Serial.print(" LR: "); - Serial.println(lr_delta); -#endif - /* Accumulate the UD and LR delta values */ gesture_ud_delta_ += ud_delta; gesture_lr_delta_ += lr_delta; -#if DEBUG - Serial.print("Accumulations: "); - Serial.print("UD: "); - Serial.print(gesture_ud_delta_); - Serial.print(" LR: "); - Serial.println(gesture_lr_delta_); -#endif - /* Determine U/D gesture */ if( gesture_ud_delta_ >= GESTURE_SENSITIVITY_1 ) { gesture_ud_count_ = 1; @@ -1845,15 +1738,6 @@ bool processGestureData() } else { gesture_lr_count_ = 0; } - -#if DEBUG - Serial.print("UD_CT: "); - Serial.print(gesture_ud_count_); - Serial.print(" LR_CT: "); - Serial.print(gesture_lr_count_); - Serial.println("----------"); -#endif - return false; } @@ -1955,7 +1839,7 @@ void APDS9960_loop() recovery_loop_counter -= 1; } if (recovery_loop_counter == 1 && APDS9960_overload){ //restart sensor just before the end of recovery from long press - enableGestureSensor(false); + enableGestureSensor(); APDS9960_overload = false; snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"Gesture\":\"On\"}")); MqttPublishPrefixTopic_P(RESULT_OR_TELE, mqtt_data); // only after the long break we report, that we are online again @@ -1994,11 +1878,19 @@ bool APDS9960_detect(void) if (APDS9960_init()) { success = true; AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "APDS9960 initialized")); - enableGestureSensor(false); + enableProximitySensor(); + enableGestureSensor(); + } + } + else { + if (APDS9960type == APDS9930_CHIPID_1 || APDS9960type == APDS9930_CHIPID_2) { + snprintf_P(log_data, sizeof(log_data), PSTR("APDS9930 found at address 0x%x, unsupported chip"), APDS9960_I2C_ADDR); + AddLog(LOG_LEVEL_DEBUG); + } + else{ + snprintf_P(log_data, sizeof(log_data), PSTR("APDS9960 not found at address 0x%x"), APDS9960_I2C_ADDR); + AddLog(LOG_LEVEL_DEBUG); } - } else { - snprintf_P(log_data, sizeof(log_data), PSTR("APDS9960 not found at address 0x%x"), APDS9960_I2C_ADDR); - AddLog(LOG_LEVEL_DEBUG); } currentGesture[0] = '\0'; return success; @@ -2013,33 +1905,34 @@ void APDS9960_show(boolean json) if (!APDS9960type) { return; } - if (!gesture_mode) { + if (!gesture_mode && !APDS9960_overload) { char red_chr[10]; char green_chr[10]; char blue_chr[10]; char ambient_chr[10]; + char illuminance_chr[10]; + char cct_chr[10]; char prox_chr[10]; - uint16_t val; - uint8_t val_prox; - readRedLight(val); - sprintf (red_chr, "%u", val); - readGreenLight(val); - sprintf (green_chr, "%u", val); - readBlueLight(val); - sprintf (blue_chr, "%u", val ); - readAmbientLight(val); - sprintf (ambient_chr, "%u", val); + readAllColorAndProximityData(); + sprintf (ambient_chr, "%u", color_data.a); + sprintf (red_chr, "%u", color_data.r); + sprintf (green_chr, "%u", color_data.g); + sprintf (blue_chr, "%u", color_data.b ); + sprintf (prox_chr, "%u", color_data.p ); + + calculateColorTemperature(); // and calculate Lux + sprintf (cct_chr, "%u", color_data.cct); + sprintf (illuminance_chr, "%u", color_data.lux); + - readProximity(val_prox); - sprintf (prox_chr, "%u", val_prox ); if (json) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"Red\":%s,\"Green\":%s,\"Blue\":%s,\"Ambient\":%s,\"Proximity\":%s}"), - mqtt_data, APDS9960stype, red_chr, green_chr, blue_chr, ambient_chr, prox_chr); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"Red\":%s,\"Green\":%s,\"Blue\":%s,\"Ambient\":%s,\"Illuminance\":%s,\"CCT\":%s,\"Proximity\":%s}"), + mqtt_data, APDS9960stype, red_chr, green_chr, blue_chr, ambient_chr, illuminance_chr, cct_chr, prox_chr); #ifdef USE_WEBSERVER } else { - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_APDS_9960_SNS, mqtt_data, red_chr, green_chr, blue_chr, ambient_chr, prox_chr ); + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_APDS_9960_SNS, mqtt_data, red_chr, green_chr, blue_chr, ambient_chr, illuminance_chr, cct_chr, prox_chr ); #endif // USE_WEBSERVER } } @@ -2069,14 +1962,23 @@ bool APDS9960CommandSensor() case 0: // Off disableGestureSensor(); gesture_mode = 0; - enableLightSensor(false); - enableProximitySensor(false); + enableLightSensor(); + APDS9960_overload = false; // prevent unwanted re-enabling break; - case 1: // On + case 1: // On with default gain of 4x if (APDS9960type) { + setGestureGain(DEFAULT_GGAIN); + setProximityGain(DEFAULT_PGAIN); disableLightSensor(); - disableProximitySensor(); - enableGestureSensor(false); + enableGestureSensor(); + gesture_mode = 1; + } + case 2: + if (APDS9960type) { + setGestureGain(GGAIN_2X); + setProximityGain(PGAIN_2X); + disableLightSensor(); + enableGestureSensor(); gesture_mode = 1; } } From fb6640e94b4a1241b051b8fae23f37fed1d142fd Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 31 Aug 2018 12:17:09 +0200 Subject: [PATCH 08/25] Update display drivers Add features to and provide more stable display drivers --- sonoff/_changelog.ino | 1 + sonoff/xdrv_13_display.ino | 82 +++++++++++++++--------------- sonoff/xdsp_01_lcd.ino | 67 +++++++++--------------- sonoff/xdsp_02_ssd1306.ino | 62 ++++++++--------------- sonoff/xdsp_03_matrix.ino | 53 ++++++++----------- sonoff/xdsp_04_ili9341.ino | 101 +++++++++++++++++++++++-------------- 6 files changed, 172 insertions(+), 194 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index ca71946ab..6fc8a9fb5 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,5 +1,6 @@ /* 6.1.1.14 20180830 * Add boot loop detection and perform some solutions + * Add features to and provide more stable display drivers * * 6.1.1.13 20180828 * Fix 6.1.1.12 regression of Mem and Var default handling (#3618) diff --git a/sonoff/xdrv_13_display.ino b/sonoff/xdrv_13_display.ino index 5642a4bcc..74b4069e1 100644 --- a/sonoff/xdrv_13_display.ino +++ b/sonoff/xdrv_13_display.ino @@ -89,7 +89,6 @@ char **disp_log_buffer; uint8_t disp_log_buffer_cols = 0; uint8_t disp_log_buffer_idx = 0; uint8_t disp_log_buffer_ptr = 0; -bool disp_log_buffer_active = false; char **disp_screen_buffer; uint8_t disp_screen_buffer_cols = 0; @@ -534,6 +533,15 @@ void DisplayReAllocScreenBuffer() DisplayAllocScreenBuffer(); } +void DisplayFillScreen(uint8_t line) +{ + byte len = disp_screen_buffer_cols - strlen(disp_screen_buffer[line]); + if (len) { + memset(disp_screen_buffer[line] + strlen(disp_screen_buffer[line]), 0x20, len); + disp_screen_buffer[line][disp_screen_buffer_cols -1] = 0; + } +} + /*-------------------------------------------------------------------------------------------*/ void DisplayClearLogBuffer() @@ -582,55 +590,47 @@ void DisplayReAllocLogBuffer() DisplayAllocLogBuffer(); } -/*-------------------------------------------------------------------------------------------*/ - -void DisplayLogBufferIdxInc() +void DisplayLogBufferAdd(char* txt) { - disp_log_buffer_idx++; - if (DISPLAY_LOG_ROWS == disp_log_buffer_idx) { - disp_log_buffer_idx = 0; + if (disp_log_buffer_cols) { + strlcpy(disp_log_buffer[disp_log_buffer_idx], txt, disp_log_buffer_cols); // This preserves the % sign where printf won't + disp_log_buffer_idx++; + if (DISPLAY_LOG_ROWS == disp_log_buffer_idx) { disp_log_buffer_idx = 0; } } } -void DisplayLogBufferPtrInc() +char* DisplayLogBuffer(char temp_code) { - disp_log_buffer_ptr++; - if (DISPLAY_LOG_ROWS == disp_log_buffer_ptr) { - disp_log_buffer_ptr = 0; - } -} + char* result = NULL; + if (disp_log_buffer_cols) { + if (disp_log_buffer_idx != disp_log_buffer_ptr) { + result = disp_log_buffer[disp_log_buffer_ptr]; + disp_log_buffer_ptr++; + if (DISPLAY_LOG_ROWS == disp_log_buffer_ptr) { disp_log_buffer_ptr = 0; } -/* -void DisplayPrintLog() -{ - disp_refresh--; - if (!disp_refresh) { - disp_refresh = Settings.display_refresh; - disp_log_buffer_active = (disp_log_buffer_idx != disp_log_buffer_ptr); - if (disp_log_buffer_active) { - XdspPrintLog(disp_log_buffer[disp_log_buffer_ptr]); - DisplayLogBufferPtrInc(); + char *pch = strchr(result, '~'); // = 0x7E (~) Replace degrees character (276 octal) + if (pch != NULL) { result[pch - result] = temp_code; } } } + return result; } -*/ void DisplayLogBufferInit() { if (Settings.display_mode) { disp_log_buffer_idx = 0; disp_log_buffer_ptr = 0; - disp_log_buffer_active = false; disp_refresh = Settings.display_refresh; snprintf_P(disp_temp, sizeof(disp_temp), PSTR("%c"), TempUnit()); -// DisplayReAllocLogBuffer(); + DisplayReAllocLogBuffer(); - snprintf_P(disp_log_buffer[disp_log_buffer_idx], disp_log_buffer_cols, PSTR(D_VERSION " %s"), my_version); - DisplayLogBufferIdxInc(); - snprintf_P(disp_log_buffer[disp_log_buffer_idx], disp_log_buffer_cols, PSTR("Display mode %d"), Settings.display_mode); - DisplayLogBufferIdxInc(); + char buffer[20]; + snprintf_P(buffer, sizeof(buffer), PSTR(D_VERSION " %s"), my_version); + DisplayLogBufferAdd(buffer); + snprintf_P(buffer, sizeof(buffer), PSTR("Display mode %d"), Settings.display_mode); + DisplayLogBufferAdd(buffer); } } @@ -668,6 +668,7 @@ const char kSensorQuantity[] PROGMEM = void DisplayJsonValue(const char *topic, const char* device, const char* mkey, const char* value) { char quantity[TOPSZ]; + char buffer[Settings.display_cols[0] +1]; char spaces[Settings.display_cols[0]]; char source[Settings.display_cols[0] - Settings.display_cols[1]]; char svalue[Settings.display_cols[1] +1]; @@ -718,12 +719,12 @@ void DisplayJsonValue(const char *topic, const char* device, const char* mkey, c else if (JSON_CO2 == quantity_code) { snprintf_P(svalue, sizeof(svalue), PSTR("%s" D_UNIT_PARTS_PER_MILLION), value); } - snprintf_P(disp_log_buffer[disp_log_buffer_idx], disp_log_buffer_cols, PSTR("%s %s"), source, svalue); + snprintf_P(buffer, sizeof(buffer), PSTR("%s %s"), source, svalue); -// snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "mkey [%s], source [%s], value [%s], quantity_code %d, log_buffer [%s]"), mkey, source, value, quantity_code, disp_log_buffer[disp_log_buffer_idx]); +// snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "mkey [%s], source [%s], value [%s], quantity_code %d, log_buffer [%s]"), mkey, source, value, quantity_code, buffer); // AddLog(LOG_LEVEL_DEBUG); - DisplayLogBufferIdxInc(); + DisplayLogBufferAdd(buffer); } void DisplayAnalyzeJson(char *topic, char *json) @@ -856,7 +857,6 @@ void DisplayInitDriver() #ifndef USE_DISPLAY_MODES1TO5 Settings.display_mode = 0; #else - DisplayAllocLogBuffer(); DisplayLogBufferInit(); #endif // USE_DISPLAY_MODES1TO5 } @@ -981,8 +981,7 @@ boolean DisplayCommand() if (!Settings.display_mode) { DisplayText(); } else { - strlcpy(disp_log_buffer[disp_log_buffer_idx], XdrvMailbox.data, disp_log_buffer_cols); - DisplayLogBufferIdxInc(); + DisplayLogBufferAdd(XdrvMailbox.data); } #endif // USE_DISPLAY_MODES1TO5 } else { @@ -1006,22 +1005,23 @@ boolean DisplayCommand() } else if ((CMND_DISP_COLS == command_code) && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= 2)) { if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= DISPLAY_MAX_COLS)) { + Settings.display_cols[XdrvMailbox.index -1] = XdrvMailbox.payload; #ifdef USE_DISPLAY_MODES1TO5 - if ((1 == XdrvMailbox.index) && (Settings.display_cols[0] != XdrvMailbox.payload)) { + if (1 == XdrvMailbox.index) { DisplayLogBufferInit(); DisplayReAllocScreenBuffer(); } #endif // USE_DISPLAY_MODES1TO5 - Settings.display_cols[XdrvMailbox.index -1] = XdrvMailbox.payload; } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_DISPLAY_COMMAND_INDEX_NVALUE, command, XdrvMailbox.index, Settings.display_cols[XdrvMailbox.index -1]); } else if (CMND_DISP_ROWS == command_code) { if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= DISPLAY_MAX_ROWS)) { -#ifdef USE_DISPLAY_MODES1TO5 - if (Settings.display_rows != XdrvMailbox.payload) { DisplayReAllocScreenBuffer(); } -#endif // USE_DISPLAY_MODES1TO5 Settings.display_rows = XdrvMailbox.payload; +#ifdef USE_DISPLAY_MODES1TO5 + DisplayLogBufferInit(); + DisplayReAllocScreenBuffer(); +#endif // USE_DISPLAY_MODES1TO5 } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_DISPLAY_COMMAND_NVALUE, command, Settings.display_rows); } diff --git a/sonoff/xdsp_01_lcd.ino b/sonoff/xdsp_01_lcd.ino index 37f4c9bcc..9d4a5d396 100644 --- a/sonoff/xdsp_01_lcd.ino +++ b/sonoff/xdsp_01_lcd.ino @@ -112,51 +112,37 @@ void LcdCenter(byte row, char* txt) lcd->print(line); } -void LcdPrintLogLine() +boolean LcdPrintLog() { - if (!disp_screen_buffer_cols) { - DisplayAllocScreenBuffer(); - } else { - uint8_t last_row = Settings.display_rows -1; + boolean result = false; - for (byte i = 0; i < last_row; i++) { - strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols); - lcd->setCursor(0, i); // Col 0, Row i - lcd->print(disp_screen_buffer[i +1]); - } - - char *pch = strchr(disp_log_buffer[disp_log_buffer_ptr],'~'); // = 0x7E (~) Replace degrees character (276 octal) - if (pch != NULL) { - disp_log_buffer[disp_log_buffer_ptr][pch - disp_log_buffer[disp_log_buffer_ptr]] = '\337'; // = 0xDF - } - strlcpy(disp_screen_buffer[last_row], disp_log_buffer[disp_log_buffer_ptr], disp_screen_buffer_cols); - - // Fill with spaces - byte len = disp_screen_buffer_cols - strlen(disp_screen_buffer[last_row]); - if (len) { - memset(disp_screen_buffer[last_row] + strlen(disp_screen_buffer[last_row]), 0x20, len); - disp_screen_buffer[last_row][disp_screen_buffer_cols -1] = 0; - } - - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]); - AddLog(LOG_LEVEL_DEBUG); - - lcd->setCursor(0, last_row); - lcd->print(disp_screen_buffer[last_row]); - } -} - -void LcdPrintLog() -{ disp_refresh--; if (!disp_refresh) { disp_refresh = Settings.display_refresh; - disp_log_buffer_active = (disp_log_buffer_idx != disp_log_buffer_ptr); - if (disp_log_buffer_active) { - LcdPrintLogLine(); - DisplayLogBufferPtrInc(); + if (!disp_screen_buffer_cols) { DisplayAllocScreenBuffer(); } + + char* txt = DisplayLogBuffer('\337'); + if (txt != NULL) { + uint8_t last_row = Settings.display_rows -1; + + for (byte i = 0; i < last_row; i++) { + strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols); + lcd->setCursor(0, i); // Col 0, Row i + lcd->print(disp_screen_buffer[i +1]); + } + strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols); + DisplayFillScreen(last_row); + + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]); + AddLog(LOG_LEVEL_DEBUG); + + lcd->setCursor(0, last_row); + lcd->print(disp_screen_buffer[last_row]); + + result = true; } } + return result; } void LcdTime() @@ -182,10 +168,7 @@ void LcdRefresh() // Every second break; case 3: // Local case 5: { // Mqtt - LcdPrintLog(); - if (!disp_log_buffer_active) { - LcdTime(); - } + if (!LcdPrintLog()) { LcdTime(); } break; } } diff --git a/sonoff/xdsp_02_ssd1306.ino b/sonoff/xdsp_02_ssd1306.ino index 704daf92b..6b4d72f96 100644 --- a/sonoff/xdsp_02_ssd1306.ino +++ b/sonoff/xdsp_02_ssd1306.ino @@ -133,52 +133,32 @@ void Ssd1306OnOff() #ifdef USE_DISPLAY_MODES1TO5 -void Ssd1306PrintLogLine() -{ - if (!disp_screen_buffer_cols) { - DisplayAllocScreenBuffer(); - } else { - uint8_t last_row = Settings.display_rows -1; - - oled->clearDisplay(); - oled->setTextSize(Settings.display_size); - oled->setCursor(0,0); - for (byte i = 0; i < last_row; i++) { - strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols); - oled->println(disp_screen_buffer[i]); - } - - char *pch = strchr(disp_log_buffer[disp_log_buffer_ptr],'~'); // = 0x7E (~) Replace degrees character (276 octal) - if (pch != NULL) { - disp_log_buffer[disp_log_buffer_ptr][pch - disp_log_buffer[disp_log_buffer_ptr]] = '\370'; // = 0xF8 - } - strlcpy(disp_screen_buffer[last_row], disp_log_buffer[disp_log_buffer_ptr], disp_screen_buffer_cols); - - // Fill with spaces - byte len = disp_screen_buffer_cols - strlen(disp_screen_buffer[last_row]); - if (len) { - memset(disp_screen_buffer[last_row] + strlen(disp_screen_buffer[last_row]), 0x20, len); - disp_screen_buffer[last_row][disp_screen_buffer_cols -1] = 0; - } - - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]); - AddLog(LOG_LEVEL_DEBUG); - - - oled->println(disp_screen_buffer[last_row]); - oled->display(); - } -} - void Ssd1306PrintLog() { disp_refresh--; if (!disp_refresh) { disp_refresh = Settings.display_refresh; - disp_log_buffer_active = (disp_log_buffer_idx != disp_log_buffer_ptr); - if (disp_log_buffer_active) { - Ssd1306PrintLogLine(); - DisplayLogBufferPtrInc(); + if (!disp_screen_buffer_cols) { DisplayAllocScreenBuffer(); } + + char* txt = DisplayLogBuffer('\370'); + if (txt != NULL) { + uint8_t last_row = Settings.display_rows -1; + + oled->clearDisplay(); + oled->setTextSize(Settings.display_size); + oled->setCursor(0,0); + for (byte i = 0; i < last_row; i++) { + strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols); + oled->println(disp_screen_buffer[i]); + } + strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols); + DisplayFillScreen(last_row); + + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]); + AddLog(LOG_LEVEL_DEBUG); + + oled->println(disp_screen_buffer[last_row]); + oled->display(); } } } diff --git a/sonoff/xdsp_03_matrix.ino b/sonoff/xdsp_03_matrix.ino index 868a2c9bd..aef33dbc3 100644 --- a/sonoff/xdsp_03_matrix.ino +++ b/sonoff/xdsp_03_matrix.ino @@ -39,6 +39,7 @@ int16_t mtx_y = 0; char mtx_buffer[MTX_MAX_SCREEN_BUFFER]; uint8_t mtx_mode = 0; uint8_t mtx_loop = 0; +uint8_t mtx_done = 0; /*********************************************************************************************/ @@ -109,9 +110,7 @@ void MatrixScrollLeft(char* txt, int loop) // Move text position left by 1 pixel. mtx_x--; int16_t len = strlen(txt); - if (mtx_x < -(len *6)) { - mtx_state = loop; - } + if (mtx_x < -(len *6)) { mtx_state = loop; } } break; } @@ -159,9 +158,7 @@ void MatrixScrollUp(char* txt, int loop) mtx_y--; // Move text position up by 1 pixel. mtx_counter = STATES * 1; // Hold text for 1 seconds } - if (mtx_y < -(wordcounter *8)) { - mtx_state = loop; - } + if (mtx_y < -(wordcounter *8)) { mtx_state = loop; } } break; } @@ -220,16 +217,14 @@ void MatrixInitDriver() void MatrixOnOff() { - if (!disp_power) { - MatrixClear(); - } + if (!disp_power) { MatrixClear(); } } void MatrixDrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uint8_t flag) { snprintf(mtx_buffer, sizeof(mtx_buffer), str); - mtx_mode = x; - mtx_loop = y; + mtx_mode = x &1; // Use x for selecting scroll up (0) or scroll left (1) + mtx_loop = y &1; // Use y for selecting no loop (0) or loop (1) if (!mtx_state) { mtx_state = 1; } } @@ -237,40 +232,36 @@ void MatrixDrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uint8 #ifdef USE_DISPLAY_MODES1TO5 -void MatrixBufferScroll(uint8_t direction) +void MatrixPrintLog(uint8_t direction) { - if (disp_log_buffer_idx != disp_log_buffer_ptr) { - if (!mtx_state) { - mtx_state = 1; - } + char* txt = (!mtx_done) ? DisplayLogBuffer('\370') : mtx_buffer; + if (txt != NULL) { + if (!mtx_state) { mtx_state = 1; } - char *pch = strchr(disp_log_buffer[disp_log_buffer_ptr],'~'); // = 0x7E (~) Replace degrees character (276 octal) - if (pch != NULL) { - disp_log_buffer[disp_log_buffer_ptr][pch - disp_log_buffer[disp_log_buffer_ptr]] = '\370'; // = 0xF8 - } - - if (direction) { - MatrixScrollUp(disp_log_buffer[disp_log_buffer_ptr], 0); - } else { + if (!mtx_done) { // Remove extra spaces uint8_t space = 0; uint8_t max_cols = (disp_log_buffer_cols < MTX_MAX_SCREEN_BUFFER) ? disp_log_buffer_cols : MTX_MAX_SCREEN_BUFFER; mtx_buffer[0] = '\0'; for (byte i = 0; i < max_cols; i++) { - if (disp_log_buffer[disp_log_buffer_ptr][i] == ' ') { + if (txt[i] == ' ') { space++; } else { space = 0; } if (space < 2) { - strncat(mtx_buffer, (const char*)disp_log_buffer[disp_log_buffer_ptr] +i, 1); + strncat(mtx_buffer, (const char*)txt +i, 1); } } + mtx_done = 1; + } + + if (direction) { + MatrixScrollUp(mtx_buffer, 0); + } else { MatrixScrollLeft(mtx_buffer, 0); } - if (!mtx_state) { - DisplayLogBufferPtrInc(); - } + if (!mtx_state) { mtx_done = 0; } } else { char disp_time[9]; // 13:45:43 @@ -310,11 +301,11 @@ void MatrixRefresh() // Every second break; } case 4: - MatrixBufferScroll(0); + MatrixPrintLog(0); break; case 1: // Time and user text case 5: // Time, user text and MQTT - MatrixBufferScroll(1); + MatrixPrintLog(1); break; #endif // USE_DISPLAY_MODES1TO5 } diff --git a/sonoff/xdsp_04_ili9341.ino b/sonoff/xdsp_04_ili9341.ino index 34f3682da..5f7f506fe 100644 --- a/sonoff/xdsp_04_ili9341.ino +++ b/sonoff/xdsp_04_ili9341.ino @@ -54,7 +54,7 @@ void Ili9341InitMode() tft->setCursor(0, 0); tft->setTextColor(ILI9341_YELLOW, ILI9341_BLACK); tft->setTextSize(2); - tft->println("HEADER"); +// tft->println("HEADER"); tft_scroll = TFT_TOP; } @@ -65,6 +65,11 @@ void Ili9341Init(uint8_t mode) switch(mode) { case DISPLAY_INIT_MODE: Ili9341InitMode(); +#ifdef USE_DISPLAY_MODES1TO5 + if (Settings.display_rotate) { + DisplayClearScreenBuffer(); + } +#endif // USE_DISPLAY_MODES1TO5 break; case DISPLAY_INIT_PARTIAL: case DISPLAY_INIT_FULL: @@ -82,6 +87,12 @@ void Ili9341InitDriver() tft = new Adafruit_ILI9341(pin[GPIO_SPI_CS], pin[GPIO_SPI_DC]); tft->begin(); +#ifdef USE_DISPLAY_MODES1TO5 + if (Settings.display_rotate) { + DisplayAllocScreenBuffer(); + } +#endif // USE_DISPLAY_MODES1TO5 + Ili9341InitMode(); } } @@ -126,41 +137,49 @@ void Ili9341OnOff() #ifdef USE_DISPLAY_MODES1TO5 -void Ili9341PrintLogLine() -{ - tft->setTextColor(ILI9341_CYAN, ILI9341_BLACK); // Add background color to solve flicker - tft->setCursor(0, tft_scroll); - byte size = Settings.display_size; - tft->setTextSize(size); - uint16_t theight = size * TFT_FONT_HEIGTH; - - tft->fillRect(0, tft_scroll, tft->width(), theight, ILI9341_BLACK); // Erase line - - char *pch = strchr(disp_log_buffer[disp_log_buffer_ptr],'~'); // = 0x7E (~) Replace degrees character (276 octal) - if (pch != NULL) { - disp_log_buffer[disp_log_buffer_ptr][pch - disp_log_buffer[disp_log_buffer_ptr]] = '\370'; // = 0xF8 - } - - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "[%s]"), disp_log_buffer[disp_log_buffer_ptr]); - AddLog(LOG_LEVEL_DEBUG); - - tft->print(disp_log_buffer[disp_log_buffer_ptr]); - tft_scroll += theight; - if (tft_scroll >= (tft->height() - TFT_BOTTOM)) { - tft_scroll = TFT_TOP; - } - tft->scrollTo(tft_scroll); -} - void Ili9341PrintLog() { disp_refresh--; if (!disp_refresh) { disp_refresh = Settings.display_refresh; - disp_log_buffer_active = (disp_log_buffer_idx != disp_log_buffer_ptr); - if (disp_log_buffer_active) { - Ili9341PrintLogLine(); - DisplayLogBufferPtrInc(); + if (Settings.display_rotate) { + if (!disp_screen_buffer_cols) { DisplayAllocScreenBuffer(); } + } + + char* txt = DisplayLogBuffer('\370'); + if (txt != NULL) { + byte size = Settings.display_size; + uint16_t theight = size * TFT_FONT_HEIGTH; + + tft->setTextSize(size); + tft->setTextColor(ILI9341_CYAN, ILI9341_BLACK); // Add background color to solve flicker + if (!Settings.display_rotate) { // Use hardware scroll + tft->setCursor(0, tft_scroll); + tft->fillRect(0, tft_scroll, tft->width(), theight, ILI9341_BLACK); // Erase line + tft->print(txt); + tft_scroll += theight; + if (tft_scroll >= (tft->height() - TFT_BOTTOM)) { + tft_scroll = TFT_TOP; + } + tft->scrollTo(tft_scroll); + } else { + uint8_t last_row = Settings.display_rows -1; + + tft_scroll = theight; // Start below header + tft->setCursor(0, tft_scroll); + for (byte i = 0; i < last_row; i++) { + strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols); +// tft->fillRect(0, tft_scroll, tft->width(), theight, ILI9341_BLACK); // Erase line + tft->print(disp_screen_buffer[i]); + tft_scroll += theight; + tft->setCursor(0, tft_scroll); + } + strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols); + DisplayFillScreen(last_row); + tft->print(disp_screen_buffer[last_row]); + } + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "[%s]"), txt); + AddLog(LOG_LEVEL_DEBUG); } } } @@ -168,17 +187,21 @@ void Ili9341PrintLog() void Ili9341Refresh() // Every second { if (Settings.display_mode) { // Mode 0 is User text - char tftdt[21]; - char disp_time[9]; // 13:45:43 - char disp_date4[11]; // 24-04-2017 - - snprintf_P(disp_time, sizeof(disp_time), PSTR("%02d" D_HOUR_MINUTE_SEPARATOR "%02d" D_MINUTE_SECOND_SEPARATOR "%02d"), RtcTime.hour, RtcTime.minute, RtcTime.second); - snprintf_P(disp_date4, sizeof(disp_date4), PSTR("%02d" D_MONTH_DAY_SEPARATOR "%02d" D_YEAR_MONTH_SEPARATOR "%04d"), RtcTime.day_of_month, RtcTime.month, RtcTime.year); + char tftdt[Settings.display_cols[0] +1]; + char date4[11]; // 24-04-2017 + char space[Settings.display_cols[0] - 17]; + char time[9]; // 13:45:43 tft->setTextSize(2); - tft->setTextColor(ILI9341_YELLOW, ILI9341_BLACK); // Add background color to solve flicker + tft->setTextColor(ILI9341_YELLOW, ILI9341_RED); // Add background color to solve flicker tft->setCursor(0, 0); - snprintf_P(tftdt, sizeof(tftdt), PSTR("%s %s"), disp_date4, disp_time); + + snprintf_P(date4, sizeof(date4), PSTR("%02d" D_MONTH_DAY_SEPARATOR "%02d" D_YEAR_MONTH_SEPARATOR "%04d"), RtcTime.day_of_month, RtcTime.month, RtcTime.year); + memset(space, 0x20, sizeof(space)); + space[sizeof(space) -1] = '\0'; + snprintf_P(time, sizeof(time), PSTR("%02d" D_HOUR_MINUTE_SEPARATOR "%02d" D_MINUTE_SECOND_SEPARATOR "%02d"), RtcTime.hour, RtcTime.minute, RtcTime.second); + snprintf_P(tftdt, sizeof(tftdt), PSTR("%s%s%s"), date4, space, time); + tft->print(tftdt); switch (Settings.display_mode) { From 5e927000d885daeb2f832a20d30747e5ce879777 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 31 Aug 2018 14:47:49 +0200 Subject: [PATCH 09/25] Prep for release Prep for release --- sonoff/user_config.h | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/sonoff/user_config.h b/sonoff/user_config.h index f35c7f2be..0471ff768 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -301,11 +301,11 @@ // #define USE_CCS811 // Enable CCS811 sensor (I2C address 0x5A) (+2k2 code) // #define USE_MPU6050 // Enable MPU6050 sensor (I2C address 0x68 AD0 low or 0x69 AD0 high) (+2k6 code) -// #define USE_DISPLAY // Add I2C Display Support for LCD, Oled and up to eigth Matrices (+19k code) +// #define USE_DISPLAY // Add I2C Display Support (+2k code) #define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0 - #define USE_DISPLAY_LCD // [DisplayModel 1] Enable Lcd display (I2C addresses 0x27 and 0x3F) - #define USE_DISPLAY_SSD1306 // [DisplayModel 2] Enable SSD1306 Oled 128x64 display (I2C addresses 0x3C and 0x3D) - #define USE_DISPLAY_MATRIX // [DisplayModel 3] Enable 8x8 Matrix display (I2C adresseses see below) + #define USE_DISPLAY_LCD // [DisplayModel 1] Enable Lcd display (I2C addresses 0x27 and 0x3F) (+6k code) + #define USE_DISPLAY_SSD1306 // [DisplayModel 2] Enable SSD1306 Oled 128x64 display (I2C addresses 0x3C and 0x3D) (+16k code) + #define USE_DISPLAY_MATRIX // [DisplayModel 3] Enable 8x8 Matrix display (I2C adresseses see below) (+11k code) #define MTX_ADDRESS1 0x71 // [DisplayAddress1] I2C address of first 8x8 matrix module #define MTX_ADDRESS2 0x74 // [DisplayAddress2] I2C address of second 8x8 matrix module #define MTX_ADDRESS3 0x75 // [DisplayAddress3] I2C address of third 8x8 matrix module @@ -318,15 +318,14 @@ #endif // USE_I2C // -- SPI sensors --------------------------------- -//#define USE_SPI // SPI using library TasmotaTFT +#define USE_SPI // SPI using library TasmotaTFT #ifdef USE_SPI #ifndef USE_DISPLAY #define USE_DISPLAY // Add SPI Display support for 320x240 and 480x320 TFT #endif - #define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display -// #define USE_DISPLAY_EPAPER // [DisplayModel 5] Enable e-paper display - + #define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display (+19k code) +// #define USE_DISPLAY_EPAPER // [DisplayModel 5] Enable e-paper display (+19k code) #endif // USE_SPI // -- Serial sensors ------------------------------ @@ -367,30 +366,15 @@ //#define USE_DEBUG_DRIVER // Use xdrv_99_debug.ino providing commands CpuChk, CfgXor, CfgDump, CfgPeek and CfgPoke /*********************************************************************************************\ - * Select features and sensors enabled in previous version saving space + * Optional firmware configurations + * Select none or just one for optional features and sensors as configured in sonoff_post.h + * See RELEASENOTES.md for selected features \*********************************************************************************************/ -//#define USE_CLASSIC // Create sonoff-classic (See sonoff_post.h for selected features) - -/*********************************************************************************************\ - * Select useful sensors - overrides above undefines!! -\*********************************************************************************************/ - -//#define USE_SENSORS // Create sonoff-sensors with useful sensors enabled (See sonoff_post.h for selected sensors) - -/*********************************************************************************************\ - * Select KNX without Emulation to save space -\*********************************************************************************************/ - -//#define USE_KNX_NO_EMULATION // Create sonoff-knx with KNX but without Emulation (See sonoff_post.h) - -/*********************************************************************************************\ - * Compile a minimal version if upgrade memory gets tight ONLY TO BE USED FOR UPGRADE STEP 1! - * To be used as step 1 during upgrade. - * Step 2 is re-compile with option BE_MINIMAL commented out. -\*********************************************************************************************/ - -//#define BE_MINIMAL // Minimal version if upgrade memory gets tight (-45k code, -2k mem) +//#define USE_CLASSIC // Create sonoff-classic with initial configuration tools WPS, SmartConfig and WifiManager +//#define USE_SENSORS // Create sonoff-sensors with useful sensors enabled +//#define USE_KNX_NO_EMULATION // Create sonoff-knx with KNX but without Emulation +//#define BE_MINIMAL // Create sonoff-minimal as intermediate firmware for OTA-MAGIC /*********************************************************************************************\ * No user configurable items below From 2e8864effd32578cb719c066692f44cca51afcb9 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 31 Aug 2018 16:53:40 +0200 Subject: [PATCH 10/25] 6.2.0 - Released --- README.md | 2 +- sonoff/_changelog.ino | 163 ++++++++++++++-------------------------- sonoff/sonoff_version.h | 2 +- sonoff/user_config.h | 2 +- 4 files changed, 61 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index f8f9c92ac..556367ede 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! [![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://paypal.me/tasmota) ### Development -[![Dev Version](https://img.shields.io/badge/development%20version-6.1.1.13-blue.svg)](https://github.com/arendst/Sonoff-Tasmota) +[![Dev Version](https://img.shields.io/badge/development%20version-6.2.0.x-blue.svg)](https://github.com/arendst/Sonoff-Tasmota) [![Download Dev](https://img.shields.io/badge/download-development-yellow.svg)](http://thehackbox.org/tasmota/) [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 6fc8a9fb5..b95a6ce0e 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,114 +1,67 @@ -/* 6.1.1.14 20180830 - * Add boot loop detection and perform some solutions - * Add features to and provide more stable display drivers - * - * 6.1.1.13 20180828 - * Fix 6.1.1.12 regression of Mem and Var default handling (#3618) - * Optimizations - * Change define USE_ALL_SENSORS to USE_SENSORS as it doesn't contain all sensors due to duplicate I2C addresses - * - * 6.1.1.12 20180827 - * Add commands ButtonDebounce 40..1000 and SwitchDebounce 40..1000 to have user control over debounce timing. Default is 50mS (#3594) - * Add rule variables %sunrise%, %sunset%, %uptime% and %time% (#3608) - * Fix handling use of default names when using names starting with shortcut character (#3392, #3600) - * Fix Sonoff Bridge data reception when using Portisch EFM8 firmware and in data buffer length (#3605) - * Add optional MQTT_TELE_RETAIN to Energy Margins message (#3612, 3614) - * Add Individual HSBColorX commands (#3430, #3615) - * Add RuleX debug options 8,9,10 (StopOnError) to control RuleX execution status after an exception restart (#3607) - * - * 6.1.1.11 20180826 - * Change scheduler phase 1/3 - Fixed when sleep is enabled: Uptime, Delay, PulseTime and TelePeriod (#3581) - * Change scheduler phase 2/3 - Fixed when sleep is enabled: Blinktime (#3581) - * Change scheduler phase 3/3 - Some sensor update timings: AdcEvery 200 -> 250, Senseair 300 -> 250, SDM120 300 -> 250, SDM630 300 -> 250 - * - * 6.1.1.10 20180827 +/* 6.2.0 20180901 + * Allow user override of define MAX_RULE_VARS and MAX_RULE_TIMERS (#3561) * Disable wifi sleep for both Esp8266/Arduino core 2.4.1 and 2.4.2 to solve device freeze caused by Espressif SDK bug (#3554) - * Rewrite GPIO options ButtonXn, SwitchXn and CounterXn to select INPUT mode instead of INPUT_PULLUP - * Add command Publish2 for publishing retained MQTT messages (#3593) - * - * 6.1.1.9 20180825 - * Allow user override of define MAX_RULE_TIMERS (#3561) - * Allow user override of define MAX_RULE_VARS - * Add GPIO options ButtonXn, SwitchXn and CounterXn to select INPUT mode instead of INPUT_PULLUP (#2525) - * Fix OtaMagic when file path contains a dash (-) (#3563) - * Fix EnergyReset3 (#2723) - * Change command sleep from restart after change to not restart after change (#3554) - * Add all ruletimer values to command RuleTimer result message (#3571) - * Add RGB support for Domoticz (#3547) - * - * 6.1.1.8 20180825 - * Fix MQTT reconnection detection when using TasmotaMqtt library (#3558) - * Add build time setting of ButtonTopic and SwitchTopic (#3414) - * Add display features and dynamic buffering - * - * 6.1.1.7 20180818 - * Add initial display support for Lcd, Oled, Matrix, Tft and e-paper - Need more docs - * Fix SDM120 reporting wrong negative values to Domoticz (#3521) - * Fix iFan02 power on state (#3412, #3530) - * Add display define USE_DISPLAY_MODES1TO5 to select display modes 1 to 5 - * Add command DisplayRotate 0..3 to select persistent display rotation - * - * 6.1.1.6 20180813 - * Add modulo option to rules like rule1 on Time#Minute|5 do backlog power on;delay 200;power off endon (#3466) - * - * 6.1.1.5 20180812 - * Fix some Pow R2 and S31 checksum errors using optimized re-sync - * - * 6.1.1.4 20180812 - * Change version representation from 1.1.1a to 1.1.1.1 for better change reference - * - * 6.1.1c 20180720 - * Add iFan02 Fanspeed + and Fanspeed - command options (#3415) - * Fix some Pow R2 and S31 checksum errors (#3425) - * Change CounterType 1 from milliseconds to microseconds (#3437) - * Add output support on MCP23008/MCP23017 (#3436) - * Fix LM75AD I2C sensor detection (#3408) - * Add message when JavaScript is not enabled in webbrowser (#3388) - * Fix sonoff-minimal from using default settings - * Add option + to command Rule to concatenate new rule with existing rules (#3365) - * Add initial support for sensor MPU6050 (#3352) - * Add command SerialSend4 to send binary serial data (#3345) - * Add rule triggers Wifi#Connected and Wifi#Disconnected (#3359) - * Fix unsecure main webpage update - * Add Turkish language file (#3332) - * Fix command TimeDst/TimeStd invalid JSON (#3322) - * Fix possible WDT due to long MQTT publish handling (#3313) - * Fix CCS811 temperature and humidity compensation - * Add support for CCS811 sensor (#3309) - * Add command Timers 0/1 to globally disable or enable armed timers (#3270) - * - * 6.1.1b 20180715 - * Add support for MPR121 controller in input mode for touch buttons (#3142) - * Add support for MCP230xx for general purpose input expansion and command Sensor29 (#3188) - * Fix command Scale buffer overflow (#3236) - * Fix rules once regression from v6.1.0 (#3198, #3226) - * Add default Wifi Configuration tool as define WIFI_CONFIG_NO_SSID in user_config.h if no SSID is configured (#3224) - * Add user selection of Wifi Smartconfig as define USE_SMARTCONFIG in user_config.h - * Add user selection of WPS as define USE_WPS in user_config.h in preparation for core v2.4.2 (#3221) - * Change default Wifi config option from WPS to Wifi Manager if WPS is disabled - * or Wifi Smartconfig if webserver is disabled - * or Wifi Serial input if Smartconfig is disabled - * Remove WPS and SmartConfig from sonoff-minimal saving 56k code space - * - * 6.1.1a 20180714 - * Fix TM1638 compile error (#3212) - * Add TM1638 switch support (#2226) - * Fix invalid response using more than 4 switches and domoticz - * Update sensor drivers to provide instant results - * Add read sensor retry to DS18B20, DS18x20, DHT, SHT1X and HTU21 - * Change SHT1x driver to provide better instant results - * Fix DHT driver mixing values for different sensors (#1797) + * Change DS18B20 driver to provide better instant results + * Change some sensor drivers to provide instant results + * Change define USE_ALL_SENSORS to USE_SENSORS as it doesn't contain all sensors due to duplicate I2C addresses + * Change some sensor update timings: AdcEvery 200 -> 250, Senseair 300 -> 250, SDM120 300 -> 250, SDM630 300 -> 250 + * Change default Wifi config option from WPS to Wifi Manager if WPS is disabled or Wifi Smartconfig if webserver is disabled or Wifi Serial input if Smartconfig is disabled + * Change SHT1x driver to provide better instant results and fix I2C interference * Change DHT driver to provide better instant results and add decimals to DHT11 (#3164) * Change DS18x20 driver to provide better instant results (#3169) - * Change DS18B20 driver to provide better instant results + * Change CounterType 1 from milliseconds to microseconds (#3437) + * Change scheduler for better sleep support using Uptime, Delay, PulseTime and TelePeriod, Blinktime (#3581) + * Remove unused functionality from Sonoff-minimal to save space + * Remove WPS and SmartConfig from sonoff-minimal saving 56k code space * Remove TSL2561 debug message and update library (#2415) - * Change SHT1x sensor initialization from pre-teleperiod to once during restart to fix I2C interference + * Remove forced restart when sleep command is executed (#3554) + * Fix invalid response using more than 4 switches and domoticz + * Fix sonoff-minimal not using default settings + * Fix unsecure main webpage update + * Fix DHT driver mixing values for different sensors (#1797) + * Fix EnergyReset3 regression not clearing total energy (#2723) + * Fix rules once regression from v6.1.0 (#3198, #3226) + * Fix command Scale buffer overflow (#3236) + * Fix possible WDT due to long MQTT publish handling (#3313) + * Fix command TimeDst/TimeStd invalid JSON (#3322) + * Fix handling of default names when using names starting with shortcut character ",0,1 or 2 (#3392, #3600, #3618) + * Fix LM75AD I2C sensor detection (#3408) + * Fix iFan02 power on state (#3412, #3530) + * Fix some Pow R2 and S31 checksum errors using optimized re-sync (#3425) + * Fix SDM120 reporting wrong negative values to Domoticz (#3521) + * Fix MQTT reconnection detection when using TasmotaMqtt library (#3558) + * Fix OtaMagic when file path contains a dash (-) (#3563) + * Fix Sonoff Bridge data reception when using Portisch EFM8 firmware using in data buffer length (#3605) + * Add read sensor retry to DS18B20, DS18x20, DHT, SHT1X and HTU21 + * Add user selection of Wifi Smartconfig as define USE_SMARTCONFIG in user_config.h + * Add boot loop detection and perform some solutions * Add wifi and mqtt status led blinkyblinky to be disabled by SetOption31 1. Does not work when LedPower is On (deliberate) (#871, #2230, #3114, #3155) - * Add experimental (untested) TM1638 switch support (#2226) + * Add support for TM1638 switch (#2226) + * Add GPIO options ButtonXn, SwitchXn and CounterXn to select INPUT mode instead of INPUT_PULLUP (#2525) * Add support for APDS9960 proximity sensor (#3051) - * Add heap and stack debug information - * Add debug facilities using optional xdrv_99_debug.ino to enable in user_config.h - * Remove not needed functionality from Sonoff-minimal to save space + * Add support for MPR121 controller in input mode for touch buttons (#3142) + * Add support for MCP230xx for general purpose input expansion and command Sensor29 (#3188) + * Add default Wifi Configuration tool as define WIFI_CONFIG_NO_SSID in user_config.h if no SSID is configured (#3224) + * Add command Timers 0/1 to globally disable or enable armed timers (#3270) + * Add support for CCS811 sensor (#3309) + * Add Turkish language file (#3332) + * Add command SerialSend4 to send binary serial data (#3345) + * Add initial support for sensor MPU6050 (#3352) + * Add rule triggers Wifi#Connected and Wifi#Disconnected (#3359) + * Add option + to command Rule to concatenate new rule with existing rules (#3365) + * Add message when JavaScript is not enabled in webbrowser (#3388) + * Add build time setting of ButtonTopic and SwitchTopic (#3414) + * Add iFan02 Fanspeed + and Fanspeed - command options (#3415) + * Add Individual HSBColorX commands (#3430, #3615) + * Add output support on MCP23008/MCP23017 (#3436) + * Add modulo option to rules like rule1 on Time#Minute|5 do backlog power on;delay 200;power off endon (#3466) + * Add RGB support for Domoticz (#3547) + * Add all ruletimer values to command RuleTimer result message (#3571) + * Add command Publish2 for publishing retained MQTT messages (#3593) + * Add commands ButtonDebounce 40..1000 and SwitchDebounce 40..1000 to have user control over debounce timing. Default is 50mS (#3594) + * Add RuleX debug options 8,9,10 (StopOnError) to control RuleX execution status after an exception restart (#3607) + * Add rule variables %sunrise%, %sunset%, %uptime% and %time% (#3608) + * Add optional MQTT_TELE_RETAIN to Energy Margins message (#3612, 3614) * * 6.1.1 20180714 * Revert wifi changes (#3177) diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 72634caa1..1bf322288 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x0601010E +#define VERSION 0x06020000 #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/user_config.h b/sonoff/user_config.h index 0471ff768..a8457ff97 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -318,7 +318,7 @@ #endif // USE_I2C // -- SPI sensors --------------------------------- -#define USE_SPI // SPI using library TasmotaTFT +//#define USE_SPI // SPI using library TasmotaTFT #ifdef USE_SPI #ifndef USE_DISPLAY From 17496d002e365138e96f0bbd01c7a5d95b4971fc Mon Sep 17 00:00:00 2001 From: andrethomas Date: Sat, 1 Sep 2018 17:46:45 +0200 Subject: [PATCH 11/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 556367ede..3ab25ac17 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! See [RELEASENOTES.md](https://github.com/arendst/Sonoff-Tasmota/blob/development/RELEASENOTES.md) for release information and [sonoff/_changelog.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_changelog.ino) for detailed change information. -The compiled development versions from current codebase are built around 6AM GMT+2 everyday and posted at http://thehackbox.org/tasmota/ (this web address can be used for OTA too). Remember that these are based on the current development codebase and it is not recommended to flash devices in hard to reach places with this firmware. +The development codebase is checked hourly for changes and if new commits have been merged and compile successfuly they will be posted at http://thehackbox.org/tasmota/ (this web address can be used for OTA too). It is important to note that these are based on the current development codebase and it is not recommended to flash it to devices used in production or which are hard to reach in the event that you need to manually flash the device if OTA failed. The last compiled commit number is also posted on the same page along with the current build status (if a firmware rebuild is in progress). ### Disclaimer :warning: **DANGER OF ELECTROCUTION** :warning: From e5186e602e247117fab0c5109f8ee11409605157 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 1 Sep 2018 19:57:10 +0200 Subject: [PATCH 12/25] Fix ccs811 begin result check --- sonoff/xsns_31_ccs811.ino | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sonoff/xsns_31_ccs811.ino b/sonoff/xsns_31_ccs811.ino index 482572cdb..8aba4d04f 100644 --- a/sonoff/xsns_31_ccs811.ino +++ b/sonoff/xsns_31_ccs811.ino @@ -47,13 +47,12 @@ void CCS811Update() // Perform every n second tcnt = 0; CCS811_ready = 0; if (!CCS811_type) { - sint8_t res = ccs.begin(CCS811_ADDRESS); - if (!res) { + if (ccs.begin(CCS811_ADDRESS)) { // ccs.begin returns true in case of success CCS811_type = 1; snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "CCS811", 0x5A); AddLog(LOG_LEVEL_DEBUG); } else { - //snprintf_P(log_data, sizeof(log_data), "CCS811 init failed: %d",res); + //snprintf_P(log_data, sizeof(log_data), "CCS811 init failed"); //AddLog(LOG_LEVEL_DEBUG); } } else { From 6a57882829fe12a0f0c26f4d70389a63197f4002 Mon Sep 17 00:00:00 2001 From: Alexey Kubrinsky Date: Sun, 2 Sep 2018 00:47:35 +0200 Subject: [PATCH 13/25] Revert "Fix ccs811 begin result check" --- sonoff/xsns_31_ccs811.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sonoff/xsns_31_ccs811.ino b/sonoff/xsns_31_ccs811.ino index 8aba4d04f..482572cdb 100644 --- a/sonoff/xsns_31_ccs811.ino +++ b/sonoff/xsns_31_ccs811.ino @@ -47,12 +47,13 @@ void CCS811Update() // Perform every n second tcnt = 0; CCS811_ready = 0; if (!CCS811_type) { - if (ccs.begin(CCS811_ADDRESS)) { // ccs.begin returns true in case of success + sint8_t res = ccs.begin(CCS811_ADDRESS); + if (!res) { CCS811_type = 1; snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "CCS811", 0x5A); AddLog(LOG_LEVEL_DEBUG); } else { - //snprintf_P(log_data, sizeof(log_data), "CCS811 init failed"); + //snprintf_P(log_data, sizeof(log_data), "CCS811 init failed: %d",res); //AddLog(LOG_LEVEL_DEBUG); } } else { From 48b5f9117ab00d86cb4fac5cc4b4ee0d9621bf96 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Sep 2018 11:11:49 +0200 Subject: [PATCH 14/25] 6.2.0.1 - Fix StateText ambiguity Fix possible ambiguity on command parameters if StateText contains numbers only (#3656) --- sonoff/_changelog.ino | 5 ++++- sonoff/sonoff_version.h | 2 +- sonoff/support.ino | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index b95a6ce0e..8b5af65ce 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,7 @@ -/* 6.2.0 20180901 +/* 6.2.0.1 20180902 + * Fix possible ambiguity on command parameters if StateText contains numbers only (#3656) + * + * 6.2.0 20180901 * Allow user override of define MAX_RULE_VARS and MAX_RULE_TIMERS (#3561) * Disable wifi sleep for both Esp8266/Arduino core 2.4.1 and 2.4.2 to solve device freeze caused by Espressif SDK bug (#3554) * Change DS18B20 driver to provide better instant results diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 1bf322288..c3ea9381e 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x06020000 +#define VERSION 0x06020001 #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/support.ino b/sonoff/support.ino index 8cc064fe5..eed4146c2 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -561,13 +561,13 @@ int GetStateNumber(char *state_text) char command[CMDSZ]; int state_number = -1; - if ((GetCommandCode(command, sizeof(command), state_text, kOptionOff) >= 0) || !strcasecmp(state_text, Settings.state_text[0])) { + if (GetCommandCode(command, sizeof(command), state_text, kOptionOff) >= 0) { state_number = 0; } - else if ((GetCommandCode(command, sizeof(command), state_text, kOptionOn) >= 0) || !strcasecmp(state_text, Settings.state_text[1])) { + else if (GetCommandCode(command, sizeof(command), state_text, kOptionOn) >= 0) { state_number = 1; } - else if ((GetCommandCode(command, sizeof(command), state_text, kOptionToggle) >= 0) || !strcasecmp(state_text, Settings.state_text[2])) { + else if (GetCommandCode(command, sizeof(command), state_text, kOptionToggle) >= 0) { state_number = 2; } else if (GetCommandCode(command, sizeof(command), state_text, kOptionBlink) >= 0) { From c6a14c5fe72ead31c3bc869e6cf93ea2e8331121 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Sep 2018 11:52:24 +0200 Subject: [PATCH 15/25] Fix possible exception Fix possible exception due to buffer overflow (#3659) --- sonoff/_changelog.ino | 1 + sonoff/sonoff.ino | 2 +- sonoff/support.ino | 4 ++-- sonoff/xdrv_02_webserver.ino | 4 ++-- sonoff/xdsp_01_lcd.ino | 2 +- sonoff/xsns_01_counter.ino | 2 +- sonoff/xsns_05_ds18x20_legacy.ino | 2 +- sonoff/xsns_12_ads1115.ino | 2 +- sonoff/xsns_12_ads1115_i2cdev.ino | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 8b5af65ce..c3d1e4c6a 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,5 +1,6 @@ /* 6.2.0.1 20180902 * Fix possible ambiguity on command parameters if StateText contains numbers only (#3656) + * Fix possible exception due to buffer overflow (#3659) * * 6.2.0 20180901 * Allow user override of define MAX_RULE_VARS and MAX_RULE_TIMERS (#3561) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 254f88184..93ffbda01 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -442,7 +442,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) ShowFreeMem(PSTR("MqttDataHandler")); - strncpy(topicBuf, topic, sizeof(topicBuf)); + strlcpy(topicBuf, topic, sizeof(topicBuf)); for (i = 0; i < data_len; i++) { if (!isspace(data[i])) break; } diff --git a/sonoff/support.ino b/sonoff/support.ino index eed4146c2..8aaeabf88 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -143,7 +143,7 @@ char* subStr(char* dest, char* str, const char *delim, int index) int i; // Since strtok consumes the first arg, make a copy - strncpy(dest, str, strlen(str)); + strlcpy(dest, str, strlen(str)); for (i = 1, act = dest; i <= index; i++, act = NULL) { sub = strtok_r(act, delim, &ptr); if (sub == NULL) break; @@ -157,7 +157,7 @@ double CharToDouble(char *str) // simple ascii to double, because atof or strtod are too large char strbuf[24]; - strcpy(strbuf, str); + strlcpy(strbuf, str, sizeof(strbuf)); char *pt; double left = atoi(strbuf); double right = 0; diff --git a/sonoff/xdrv_02_webserver.ino b/sonoff/xdrv_02_webserver.ino index c919c8f43..91c01eeae 100644 --- a/sonoff/xdrv_02_webserver.ino +++ b/sonoff/xdrv_02_webserver.ino @@ -372,8 +372,8 @@ long ajax_token = 1; static void WebGetArg(const char* arg, char* out, size_t max) { String s = WebServer->arg(arg); - strncpy(out, s.c_str(), max); - out[max-1] = '\0'; // Ensure terminating NUL + strlcpy(out, s.c_str(), max); +// out[max-1] = '\0'; // Ensure terminating NUL } void ShowWebSource(int source) diff --git a/sonoff/xdsp_01_lcd.ino b/sonoff/xdsp_01_lcd.ino index 9d4a5d396..bfc0b3536 100644 --- a/sonoff/xdsp_01_lcd.ino +++ b/sonoff/xdsp_01_lcd.ino @@ -107,7 +107,7 @@ void LcdCenter(byte row, char* txt) line[Settings.display_cols[0]] = 0; len = strlen(txt); offset = (len < Settings.display_cols[0]) ? offset = (Settings.display_cols[0] - len) / 2 : 0; - strncpy(line +offset, txt, len); + strlcpy(line +offset, txt, len); lcd->setCursor(0, row); lcd->print(line); } diff --git a/sonoff/xsns_01_counter.ino b/sonoff/xsns_01_counter.ino index 069d5b3e7..b5822cac7 100644 --- a/sonoff/xsns_01_counter.ino +++ b/sonoff/xsns_01_counter.ino @@ -111,7 +111,7 @@ void CounterShow(boolean json) } header++; snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"C%d\":%s"), mqtt_data, stemp, i +1, counter); - strcpy(stemp, ","); + strlcpy(stemp, ",", sizeof(stemp)); #ifdef USE_DOMOTICZ if ((0 == tele_period) && (1 == dsxflg)) { DomoticzSensor(DZ_COUNT, RtcSettings.pulse_counter[i]); diff --git a/sonoff/xsns_05_ds18x20_legacy.ino b/sonoff/xsns_05_ds18x20_legacy.ino index 156312104..03754bbe1 100644 --- a/sonoff/xsns_05_ds18x20_legacy.ino +++ b/sonoff/xsns_05_ds18x20_legacy.ino @@ -186,7 +186,7 @@ void Ds18x20Show(boolean json) dsxflg++; snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"DS%d\":{\"" D_JSON_TYPE "\":\"%s\",\"" D_JSON_ADDRESS "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%s}"), mqtt_data, stemp, i +1, ds18x20_types, Ds18x20Addresses(i).c_str(), temperature); - strcpy(stemp, ","); + strlcpy(stemp, ",", sizeof(stemp)); #ifdef USE_DOMOTICZ if ((0 == tele_period) && (1 == dsxflg)) { DomoticzSensor(DZ_TEMP, temperature); diff --git a/sonoff/xsns_12_ads1115.ino b/sonoff/xsns_12_ads1115.ino index f1279a732..bcfb6dfad 100644 --- a/sonoff/xsns_12_ads1115.ino +++ b/sonoff/xsns_12_ads1115.ino @@ -191,7 +191,7 @@ void Ads1115Show(boolean json) } dsxflg++; snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"A%d\":%d"), mqtt_data, stemp, i, adc_value); - strcpy(stemp, ","); + strlcpy(stemp, ",", sizeof(stemp)); #ifdef USE_WEBSERVER } else { snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ANALOG, mqtt_data, "ADS1115", i, adc_value); diff --git a/sonoff/xsns_12_ads1115_i2cdev.ino b/sonoff/xsns_12_ads1115_i2cdev.ino index d3748ec7a..588a37ac5 100644 --- a/sonoff/xsns_12_ads1115_i2cdev.ino +++ b/sonoff/xsns_12_ads1115_i2cdev.ino @@ -111,7 +111,7 @@ void Ads1115Show(boolean json) } dsxflg++; snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"A%d\":%d"), mqtt_data, stemp, i, adc_value); - strcpy(stemp, ","); + strlcpy(stemp, ",", sizeof(stemp)); #ifdef USE_WEBSERVER } else { snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ANALOG, mqtt_data, "ADS1115", i, adc_value); From 5623924813f888c25d672f23714a6675b6012c35 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Sep 2018 12:10:22 +0200 Subject: [PATCH 16/25] Add Wifi channel number Add Wifi channel number to state message (#3664) --- sonoff/_changelog.ino | 1 + sonoff/i18n.h | 1 + sonoff/sonoff.ino | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index c3d1e4c6a..d8a14e367 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,6 +1,7 @@ /* 6.2.0.1 20180902 * Fix possible ambiguity on command parameters if StateText contains numbers only (#3656) * Fix possible exception due to buffer overflow (#3659) + * Add Wifi channel number to state message (#3664) * * 6.2.0 20180901 * Allow user override of define MAX_RULE_VARS and MAX_RULE_TIMERS (#3561) diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 107710678..cfc30e6bc 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -40,6 +40,7 @@ #define D_JSON_BOOTVERSION "Boot" #define D_JSON_BOOTCOUNT "BootCount" #define D_JSON_BUILDDATETIME "BuildDateTime" +#define D_JSON_CHANNEL "Channel" #define D_JSON_CO2 "CarbonDioxide" #define D_JSON_COMMAND "Command" #define D_JSON_CONNECT_FAILED "Connect failed" diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 93ffbda01..9a167eddf 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1532,8 +1532,8 @@ void MqttShowState() MqttShowPWMState(); } - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_RSSI "\":%d,\"" D_JSON_APMAC_ADDRESS "\":\"%s\"}}"), - mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WifiGetRssiAsQuality(WiFi.RSSI()), WiFi.BSSIDstr().c_str()); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d,\"" D_JSON_APMAC_ADDRESS "\":\"%s\"}}"), + mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WiFi.BSSIDstr().c_str()); } boolean MqttShowSensor() From a60876378f0adc066352eb978ef07d2d54fc83f7 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Sep 2018 13:01:08 +0200 Subject: [PATCH 17/25] Show AP channel on webpage Show channel number on webpage and wifiscan debug info. Add BSSid to wifiscan debug info --- sonoff/language/bg-BG.h | 2 ++ sonoff/language/cs-CZ.h | 2 ++ sonoff/language/de-DE.h | 2 ++ sonoff/language/el-GR.h | 2 ++ sonoff/language/en-GB.h | 2 ++ sonoff/language/es-AR.h | 2 ++ sonoff/language/fr-FR.h | 2 ++ sonoff/language/hu-HU.h | 2 ++ sonoff/language/it-IT.h | 2 ++ sonoff/language/nl-NL.h | 2 ++ sonoff/language/pl-PL.h | 2 ++ sonoff/language/pt-BR.h | 2 ++ sonoff/language/pt-PT.h | 2 ++ sonoff/language/ru-RU.h | 2 ++ sonoff/language/tr-TR.h | 4 +++- sonoff/language/uk-UK.h | 2 ++ sonoff/language/zh-CN.h | 2 ++ sonoff/language/zh-TW.h | 2 ++ sonoff/xdrv_02_webserver.ino | 5 +++-- 19 files changed, 40 insertions(+), 3 deletions(-) diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index 6421441b7..e85ab66c3 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "Мигане изкл." #define D_BOOT_COUNT "Брой на стартиранията" #define D_BRIGHTLIGHT "Яркост" +#define D_BSSID "BSSId" #define D_BUTTON "Бутон" #define D_BY "от" // Written by me #define D_BYTES "Байта" #define D_CELSIUS "Целзий" +#define D_CHANNEL "Channel" #define D_CO2 "Въглероден диоксид" #define D_CODE "код" // Button code #define D_COLDLIGHT "Хладна" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index d1905c103..2f51ccc93 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "BlikáníVyp" #define D_BOOT_COUNT "Počítadlo spuštění" #define D_BRIGHTLIGHT "Světlý" +#define D_BSSID "BSSId" #define D_BUTTON "Tlačítko" #define D_BY "by" // Written by me #define D_BYTES "Bytů" #define D_CELSIUS "°C" +#define D_CHANNEL "Channel" #define D_CO2 "CO2" #define D_CODE "kód" // Button code #define D_COLDLIGHT "Studené světlo" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index 302c7e55e..888345d8a 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "BlinkenAus" #define D_BOOT_COUNT "Anzahl Startvorgänge" #define D_BRIGHTLIGHT "hell" +#define D_BSSID "BSSId" #define D_BUTTON "Knopf" #define D_BY "von" // Written by me #define D_BYTES "Bytes" #define D_CELSIUS "Celsius" +#define D_CHANNEL "Kanal" #define D_CO2 "CO²" #define D_CODE "code" // Button code #define D_COLDLIGHT "kalt" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 789d88a6f..3187eadf9 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "Δεν αναβοσβήνει" #define D_BOOT_COUNT "Αριθμός εκκινήσεων" #define D_BRIGHTLIGHT "Λαμπερό" +#define D_BSSID "BSSId" #define D_BUTTON "Κουμπί" #define D_BY "από" // Written by me #define D_BYTES "Bytes" #define D_CELSIUS "Κελσίου" +#define D_CHANNEL "Channel" #define D_CO2 "Διοξείδιο του άνθρακα" #define D_CODE "κώδικας" // Button code #define D_COLDLIGHT "Ψυχρός" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index e8af7fab1..558877db2 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Boot Count" #define D_BRIGHTLIGHT "Bright" +#define D_BSSID "BSSId" #define D_BUTTON "Button" #define D_BY "by" // Written by me #define D_BYTES "Bytes" #define D_CELSIUS "Celsius" +#define D_CHANNEL "Channel" #define D_CO2 "Carbon dioxide" #define D_CODE "code" // Button code #define D_COLDLIGHT "Cold" diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h index 68e9141ea..c1993ffee 100644 --- a/sonoff/language/es-AR.h +++ b/sonoff/language/es-AR.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Conteo Reinicios" #define D_BRIGHTLIGHT "Brillante" +#define D_BSSID "BSSId" #define D_BUTTON "Botón" #define D_BY "por" // Written by me #define D_BYTES "Bytes" #define D_CELSIUS "Celsius" +#define D_CHANNEL "Channel" #define D_CO2 "CO2" #define D_CODE "código" // Button code #define D_COLDLIGHT "Fría" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index 1e5c2b9f8..2a46f7b53 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Nombre de boot" #define D_BRIGHTLIGHT "Luminosité" +#define D_BSSID "BSSId" #define D_BUTTON "Bouton" #define D_BY "par" // Written by me #define D_BYTES "Bytes" #define D_CELSIUS "Celsius" +#define D_CHANNEL "Channel" #define D_CO2 "Dioxyde de carbone" #define D_CODE "code" // Button code #define D_COLDLIGHT "Froid" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index 76076427e..c57278176 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "Villogás Ki" #define D_BOOT_COUNT "Bootolások száma" #define D_BRIGHTLIGHT "Max. fényerő" +#define D_BSSID "BSSId" #define D_BUTTON "Gomb" #define D_BY "tőle:" // Written by me #define D_BYTES "Byte-ok" #define D_CELSIUS "Celsius" +#define D_CHANNEL "Channel" #define D_CO2 "Szén-dioxid" #define D_CODE "kód" // Button code #define D_COLDLIGHT "Hideg" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index 2beda2e79..d07a33021 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Numero di boot" #define D_BRIGHTLIGHT "Luminoso" +#define D_BSSID "BSSId" #define D_BUTTON "Pulsante" #define D_BY "da" // Written by me #define D_BYTES "Bytes" #define D_CELSIUS "Celsius" +#define D_CHANNEL "Channel" #define D_CO2 "CO2" #define D_CODE "codice" // Button code #define D_COLDLIGHT "Fredda" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index 8ef596448..05ec4666b 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "KnipperUit" #define D_BOOT_COUNT "Herstarts" #define D_BRIGHTLIGHT "Fel" +#define D_BSSID "BSSId" #define D_BUTTON "DrukKnop" #define D_BY "door" // Written by me #define D_BYTES "Bytes" #define D_CELSIUS "Celsius" +#define D_CHANNEL "Kanaal" #define D_CO2 "Koolstofdioxide" #define D_CODE "code" // Button code #define D_COLDLIGHT "Koud" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index 06d086c57..faaf8df6d 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "MiganieWył" #define D_BOOT_COUNT "Licznik uruchomienia" #define D_BRIGHTLIGHT "Jasny" +#define D_BSSID "BSSId" #define D_BUTTON "Przycisk" #define D_BY "by" // Written by me #define D_BYTES "Bajtow" #define D_CELSIUS "Celsiusza" +#define D_CHANNEL "Channel" #define D_CO2 "Dwutlenku węgla" #define D_CODE "kod" // Button code #define D_COLDLIGHT "Zimny" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index 6c5f3fceb..318f69e45 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "Pulsar desligado" #define D_BOOT_COUNT "Contagem de inicialização" #define D_BRIGHTLIGHT "Brilho" +#define D_BSSID "BSSId" #define D_BUTTON "Botão" #define D_BY "por" // Write by me #define D_BYTES "Bytes" #define D_CELSIUS "Celsius" +#define D_CHANNEL "Channel" #define D_CO2 "Dióxido de carbono" #define D_CODE "Código" // Button code #define D_COLDLIGHT "Luz fria" diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index 0c93620e8..d39ec6e50 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "Piscar desligado" #define D_BOOT_COUNT "Contagem de Inicialização" #define D_BRIGHTLIGHT "Brilho" +#define D_BSSID "BSSId" #define D_BUTTON "Botão" #define D_BY "por" // Write by me #define D_BYTES "Bytes" #define D_CELSIUS "Celsius" +#define D_CHANNEL "Channel" #define D_CO2 "Dioxido de Carbono" #define D_CODE "Código" // Button code #define D_COLDLIGHT "Luz Fria" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index 2fa9d388f..5fea0468e 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "Не Мигать" #define D_BOOT_COUNT "Количество загрузок" #define D_BRIGHTLIGHT "Яркость" +#define D_BSSID "BSSId" #define D_BUTTON "Кнопка" #define D_BY "by" // Written by me #define D_BYTES "Байт" #define D_CELSIUS "Цельсия" +#define D_CHANNEL "Channel" #define D_CO2 "Углекислый газ" #define D_CODE "код" // Button code #define D_COLDLIGHT "Холодный" diff --git a/sonoff/language/tr-TR.h b/sonoff/language/tr-TR.h index 3d88ae1a8..b133d2c80 100755 --- a/sonoff/language/tr-TR.h +++ b/sonoff/language/tr-TR.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Yeniden başlama sayısı" #define D_BRIGHTLIGHT "Işık" +#define D_BSSID "BSSId" #define D_BUTTON "Buton" #define D_BY "by" // Written by me #define D_BYTES "Bayt" #define D_CELSIUS "Derece" +#define D_CHANNEL "Channel" #define D_CO2 "Karbon dioksit" #define D_CODE "kod" // Button code #define D_COLDLIGHT "Soğuk" @@ -536,4 +538,4 @@ #define D_LOG_UPNP "UPP: " // UPnP #define D_LOG_WIFI "WIF: " // Wifi -#endif // _LANGUAGE_TR_TR_H_ \ No newline at end of file +#endif // _LANGUAGE_TR_TR_H_ diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h index a2fe05843..9cf66773b 100644 --- a/sonoff/language/uk-UK.h +++ b/sonoff/language/uk-UK.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "Не блимати" #define D_BOOT_COUNT "Кіл-сть завант." #define D_BRIGHTLIGHT "Яскравість" +#define D_BSSID "BSSId" #define D_BUTTON "Кнопка" #define D_BY "by" // Written by me #define D_BYTES "Байт" #define D_CELSIUS "Цельсія" +#define D_CHANNEL "Channel" #define D_CO2 "Вуглек. газ" #define D_CODE "код" // Button code #define D_COLDLIGHT "Холодний" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index 70186035d..88f680f8e 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "闪烁关" #define D_BOOT_COUNT "启动次数" #define D_BRIGHTLIGHT "亮" +#define D_BSSID "BSSId" #define D_BUTTON "按钮" #define D_BY "汉化: killadm 作者:" // Written by me #define D_BYTES "大小:" #define D_CELSIUS "摄氏" +#define D_CHANNEL "Channel" #define D_CO2 "二氧化碳" #define D_CODE "代码" // Button code #define D_COLDLIGHT "冷" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index 16e6961d0..abb92d359 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -60,10 +60,12 @@ #define D_BLINKOFF "閃爍關" #define D_BOOT_COUNT "啟動次數" #define D_BRIGHTLIGHT "亮度" +#define D_BSSID "BSSId" #define D_BUTTON "按鈕" #define D_BY "by" // Written by me #define D_BYTES "大小:" #define D_CELSIUS "攝氏" +#define D_CHANNEL "Channel" #define D_CO2 "二氧化碳" #define D_CODE "代碼" // Button code #define D_COLDLIGHT "冷" diff --git a/sonoff/xdrv_02_webserver.ino b/sonoff/xdrv_02_webserver.ino index 91c01eeae..951c25f9d 100644 --- a/sonoff/xdrv_02_webserver.ino +++ b/sonoff/xdrv_02_webserver.ino @@ -254,7 +254,7 @@ const char HTTP_FORM_MODULE[] PROGMEM = "" "
" D_MODULE_TYPE " ({mt)

"; const char HTTP_LNK_ITEM[] PROGMEM = - "
{v} {i} {r}%
"; + "
{v} ({w}) {i} {r}%
"; const char HTTP_LNK_SCAN[] PROGMEM = "
" D_SCAN_FOR_WIFI_NETWORKS "

"; const char HTTP_FORM_WIFI[] PROGMEM = @@ -882,7 +882,7 @@ void HandleWifi(boolean scan) //display networks in page for (int i = 0; i < n; i++) { if (-1 == indices[i]) { continue; } // skip dups - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_SSID " %s, " D_RSSI " %d"), WiFi.SSID(indices[i]).c_str(), WiFi.RSSI(indices[i])); + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_SSID " %s, " D_BSSID " %s, " D_CHANNEL " %d, " D_RSSI " %d"), WiFi.SSID(indices[i]).c_str(), WiFi.BSSIDstr(indices[i]).c_str(), WiFi.channel(indices[i]), WiFi.RSSI(indices[i])); AddLog(LOG_LEVEL_DEBUG); int quality = WifiGetRssiAsQuality(WiFi.RSSI(indices[i])); @@ -891,6 +891,7 @@ void HandleWifi(boolean scan) String rssiQ; rssiQ += quality; item.replace(F("{v}"), WiFi.SSID(indices[i])); + item.replace(F("{w}"), String(WiFi.channel(indices[i]))); item.replace(F("{r}"), rssiQ); uint8_t auth = WiFi.encryptionType(indices[i]); item.replace(F("{i}"), (ENC_TYPE_WEP == auth) ? F(D_WEP) : (ENC_TYPE_TKIP == auth) ? F(D_WPA_PSK) : (ENC_TYPE_CCMP == auth) ? F(D_WPA2_PSK) : (ENC_TYPE_AUTO == auth) ? F(D_AUTO) : F("")); From 0ac8c73938cff33f0166d86867e33b190f23ded8 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Sep 2018 14:26:00 +0200 Subject: [PATCH 18/25] Fix Wemo emulation Fix Wemo emulation to select the first relay when more than one relay is present (#3657) --- sonoff/_changelog.ino | 1 + sonoff/xplg_wemohue.ino | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index d8a14e367..d2781b4d4 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -2,6 +2,7 @@ * Fix possible ambiguity on command parameters if StateText contains numbers only (#3656) * Fix possible exception due to buffer overflow (#3659) * Add Wifi channel number to state message (#3664) + * Fix Wemo emulation to select the first relay when more than one relay is present (#3657) * * 6.2.0 20180901 * Allow user override of define MAX_RULE_VARS and MAX_RULE_TIMERS (#3561) diff --git a/sonoff/xplg_wemohue.ino b/sonoff/xplg_wemohue.ino index 9a7cdeec7..9a5fb9467 100644 --- a/sonoff/xplg_wemohue.ino +++ b/sonoff/xplg_wemohue.ino @@ -386,12 +386,18 @@ void HandleUpnpEvent() String state_xml = FPSTR(WEMO_RESPONSE_STATE_SOAP); //differentiate get and set state if (request.indexOf(F("SetBinaryState")) > 0) { + uint8_t power = POWER_TOGGLE; if (request.indexOf(F("State>1 0) { - ExecuteCommandPower(devices_present, POWER_ON, SRC_WEMO); + power = POWER_ON } else if (request.indexOf(F("State>0 0) { - ExecuteCommandPower(devices_present, POWER_OFF, SRC_WEMO); + power = POWER_OFF; } + if (power != POWER_TOGGLE) { + uint8_t device = (light_type) ? devices_present : 1; // Select either a configured light or relay1 + ExecuteCommandPower(device, power, SRC_WEMO); + } + } else if(request.indexOf(F("GetBinaryState")) > 0){ state_xml.replace(F("Set"), F("Get")); From 4b4b0dff855a5e9c1bf7a8d272b2a73fa8fbb223 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Sep 2018 14:46:06 +0200 Subject: [PATCH 19/25] Fix compile error Fix compile error --- sonoff/xplg_wemohue.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xplg_wemohue.ino b/sonoff/xplg_wemohue.ino index 9a5fb9467..bc579782a 100644 --- a/sonoff/xplg_wemohue.ino +++ b/sonoff/xplg_wemohue.ino @@ -388,7 +388,7 @@ void HandleUpnpEvent() if (request.indexOf(F("SetBinaryState")) > 0) { uint8_t power = POWER_TOGGLE; if (request.indexOf(F("State>1 0) { - power = POWER_ON + power = POWER_ON; } else if (request.indexOf(F("State>0 0) { power = POWER_OFF; From 5ff735e4e783a46d68f333ce2a6b1a6618cdc294 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Sep 2018 15:21:58 +0200 Subject: [PATCH 20/25] Remove obsolete linker file Remove obsolete linker file as platformio now supports 1m0 out of the box --- esp8266.flash.1m0.ld | 18 ------------------ platformio.ini | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 esp8266.flash.1m0.ld diff --git a/esp8266.flash.1m0.ld b/esp8266.flash.1m0.ld deleted file mode 100644 index 1f9b56a87..000000000 --- a/esp8266.flash.1m0.ld +++ /dev/null @@ -1,18 +0,0 @@ -/* Flash Split for 1M chips */ -/* sketch 999KB */ -/* eeprom 20KB */ - -MEMORY -{ - dport0_0_seg : org = 0x3FF00000, len = 0x10 - dram0_0_seg : org = 0x3FFE8000, len = 0x14000 - iram1_0_seg : org = 0x40100000, len = 0x8000 - irom0_0_seg : org = 0x40201010, len = 0xf9ff0 -} - -PROVIDE ( _SPIFFS_start = 0x402FB000 ); -PROVIDE ( _SPIFFS_end = 0x402FB000 ); -PROVIDE ( _SPIFFS_page = 0 ); -PROVIDE ( _SPIFFS_block = 0 ); - -INCLUDE "esp8266.flash.common.ld" diff --git a/platformio.ini b/platformio.ini index 4cda52b6f..03e61b1dc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -60,7 +60,7 @@ board_build.f_cpu = 80000000L build_unflags = -Wall build_flags = - -Wl,-Tesp8266.flash.1m0.ld + -Wl,-Teagle.flash.1m0.ld ; -DUSE_CONFIG_OVERRIDE ; lwIP 1.4 (Default) ; -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH From 9ff3233b9755fd1a1f160af5ace605ff1dab8e4a Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Sep 2018 15:23:11 +0200 Subject: [PATCH 21/25] Revert "Remove obsolete linker file" This reverts commit 5ff735e4e783a46d68f333ce2a6b1a6618cdc294. --- esp8266.flash.1m0.ld | 18 ++++++++++++++++++ platformio.ini | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 esp8266.flash.1m0.ld diff --git a/esp8266.flash.1m0.ld b/esp8266.flash.1m0.ld new file mode 100644 index 000000000..1f9b56a87 --- /dev/null +++ b/esp8266.flash.1m0.ld @@ -0,0 +1,18 @@ +/* Flash Split for 1M chips */ +/* sketch 999KB */ +/* eeprom 20KB */ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x14000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40201010, len = 0xf9ff0 +} + +PROVIDE ( _SPIFFS_start = 0x402FB000 ); +PROVIDE ( _SPIFFS_end = 0x402FB000 ); +PROVIDE ( _SPIFFS_page = 0 ); +PROVIDE ( _SPIFFS_block = 0 ); + +INCLUDE "esp8266.flash.common.ld" diff --git a/platformio.ini b/platformio.ini index 03e61b1dc..4cda52b6f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -60,7 +60,7 @@ board_build.f_cpu = 80000000L build_unflags = -Wall build_flags = - -Wl,-Teagle.flash.1m0.ld + -Wl,-Tesp8266.flash.1m0.ld ; -DUSE_CONFIG_OVERRIDE ; lwIP 1.4 (Default) ; -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH From 2210bda2e6ff3c0033959cb27014119fed6fea9f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Sep 2018 15:54:26 +0200 Subject: [PATCH 22/25] Replace APMac with BSSId Replace APMac with BSSId in state and status 11 --- sonoff/i18n.h | 1 + sonoff/sonoff.ino | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sonoff/i18n.h b/sonoff/i18n.h index cfc30e6bc..5559ac6d1 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -39,6 +39,7 @@ #define D_JSON_BLOCKED_LOOP "Blocked Loop" #define D_JSON_BOOTVERSION "Boot" #define D_JSON_BOOTCOUNT "BootCount" +#define D_JSON_BSSID "BSSId" #define D_JSON_BUILDDATETIME "BuildDateTime" #define D_JSON_CHANNEL "Channel" #define D_JSON_CO2 "CarbonDioxide" diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 9a167eddf..8d82efc18 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1532,8 +1532,8 @@ void MqttShowState() MqttShowPWMState(); } - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d,\"" D_JSON_APMAC_ADDRESS "\":\"%s\"}}"), - mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI()), WiFi.BSSIDstr().c_str()); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_WIFI "\":{\"" D_JSON_AP "\":%d,\"" D_JSON_SSID "\":\"%s\",\"" D_JSON_BSSID "\":\"%s\",\"" D_JSON_CHANNEL "\":%d,\"" D_JSON_RSSI "\":%d}}"), + mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WiFi.BSSIDstr().c_str(), WiFi.channel(), WifiGetRssiAsQuality(WiFi.RSSI())); } boolean MqttShowSensor() From 44ecdaf952b7e0cf42cf30ffebb996b75e52e1ad Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 2 Sep 2018 16:17:49 +0200 Subject: [PATCH 23/25] Add support for Shelly Add support for Shelly 1 and basic support for Shelly 2 - No energy monitoring yet (#2789) --- sonoff/_changelog.ino | 1 + sonoff/sonoff_template.h | 52 ++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index d2781b4d4..a59ba99cb 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -3,6 +3,7 @@ * Fix possible exception due to buffer overflow (#3659) * Add Wifi channel number to state message (#3664) * Fix Wemo emulation to select the first relay when more than one relay is present (#3657) + * Add support for Shelly 1 and basic support for Shelly 2 - No energy monitoring yet (#2789) * * 6.2.0 20180901 * Allow user override of define MAX_RULE_VARS and MAX_RULE_TIMERS (#3561) diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index 84a0749dc..8d3fac176 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -136,6 +136,9 @@ enum ProgramSelectablePins { GPIO_DI, // my92x1 PWM input GPIO_DCKI, // my92x1 CLK input GPIO_ARIRFRCV, // AliLux RF Receive input + GPIO_MCP39_TX, // MCP39F501 Serial output + GPIO_MCP39_RX, // MCP39F501 Serial input + GPIO_MCP39_RST, // MCP39F501 Serial reset GPIO_USER, // User configurable GPIO_MAX }; @@ -220,6 +223,8 @@ enum SupportedModules { SONOFF_POW_R2, SONOFF_IFAN02, BLITZWOLF_BWSHP2, + SHELLY1, + SHELLY2, MAXMODULE }; /********************************************************************************************/ @@ -271,6 +276,8 @@ const uint8_t kNiceList[MAXMODULE] PROGMEM = { LUANIHVIO, YUNSHAN, WION, + SHELLY1, + SHELLY2, BLITZWOLF_BWSHP2, H801, MAGICHOME, @@ -906,6 +913,27 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_HLW_CF1, // GPIO14 BL0937 or HJL-01 CF1 voltage / current GPIO_REL1, // GPIO15 Relay (0 = Off, 1 = On) 0, 0 + }, + { "Shelly 1", // Shelly1 Open Source (ESP8266 - 2MB) - https://shelly.cloud/shelly1-open-source/ + 0, 0, 0, 0, + GPIO_REL1, // GPIO04 Relay (0 = Off, 1 = On) + GPIO_SWT1_NP, // GPIO05 SW pin + 0, 0, 0, 0, 0, 0, // Flash connection + 0, 0, 0, 0, 0, 0 + }, + { "Shelly 2", // Shelly2 (ESP8266 - 2MB) - https://shelly.cloud/shelly2/ + 0, + GPIO_MCP39_RX, // GPIO01 MCP39F501 Serial input + 0, + GPIO_MCP39_TX, // GPIO03 MCP39F501 Serial output + GPIO_REL1, // GPIO04 + GPIO_REL2, // GPIO05 + 0, 0, 0, 0, 0, 0, // Flash connection + GPIO_SWT1_NP, // GPIO12 + 0, + GPIO_SWT2_NP, // GPIO14 + GPIO_MCP39_RST, // GPIO15 MCP39F501 Reset + 0, 0 } }; @@ -988,29 +1016,7 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_USER, // GPIO15 (D15) GPIO_USER, // GPIO16 (D16) 0 // ADC0 Analog input (A0) - }, - - { "Shelly 1", // Shelly1 Open Source (ESP8266 - 2MB) - https://shelly.cloud/shelly1-open-source/ - GPIO_KEY1, // GPIO00 Button - GPIO_USER, // GPIO01 Serial RXD and Optional sensor - 0, - GPIO_USER, // GPIO03 Serial TXD and Optional sensor - GPIO_REL1, // GPIO04 Relay (0 = Off, 1 = On) - GPIO_SWT1_NP, // GPIO05 Switch - 0, 0, 0, 0, 0, 0, // Flash connection - 0, 0, 0, 0, 0, 0 - }, - { "Shelly 2", // Shelly2 (ESP8266 - 2MB) - https://shelly.cloud/shelly2/ - // As Gnd is connected to AC no user GPIO allowed - 0, 0, 0, 0, - GPIO_REL1, // GPIO04 Relay 1 (0 = Off, 1 = On) - GPIO_REL2, // GPIO05 Relay 2 (0 = Off, 1 = On) - 0, 0, 0, 0, 0, 0, // Flash connection - GPIO_SWT1_NP, // GPIO12 Switch 1 - 0, - GPIO_SWT2_NP, // GPIO14 Switch 2 - 0, 0, 0 - }, + } */ #endif // _SONOFF_TEMPLATE_H_ \ No newline at end of file From d557fdbe7b6cee4a5956512fdb632073c7b170ad Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 3 Sep 2018 00:28:03 -0300 Subject: [PATCH 24/25] Updated Spanish Translation --- sonoff/language/es-AR.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h index c1993ffee..986b9507f 100644 --- a/sonoff/language/es-AR.h +++ b/sonoff/language/es-AR.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 v6.1.1c + * Updated until v6.2.0.1 \*********************************************************************/ #define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English) @@ -65,7 +65,7 @@ #define D_BY "por" // Written by me #define D_BYTES "Bytes" #define D_CELSIUS "Celsius" -#define D_CHANNEL "Channel" +#define D_CHANNEL "Canal" #define D_CO2 "CO2" #define D_CODE "código" // Button code #define D_COLDLIGHT "Fría" @@ -462,7 +462,7 @@ #define D_SENSOR_RELAY "Relé" // Suffix "1i" #define D_SENSOR_LED "Led" // Suffix "1i" #define D_SENSOR_PWM "PWM" // Suffix "1" -#define D_SENSOR_COUNTER "Counter" // Suffix "1" +#define D_SENSOR_COUNTER "Contador" // Suffix "1" #define D_SENSOR_IRRECV "IR RX" #define D_SENSOR_MHZ_RX "MHZ Rx" #define D_SENSOR_MHZ_TX "MHZ Tx" From 41999a0afcb866c8bc006bc2a7a96fcc74f356ed Mon Sep 17 00:00:00 2001 From: znanev <20048364+znanev@users.noreply.github.com> Date: Mon, 3 Sep 2018 13:49:49 +0100 Subject: [PATCH 25/25] Update bg-BG.h --- sonoff/language/bg-BG.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index e85ab66c3..b1ecd6fa6 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.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 v6.1.1.5 + * Updated until v6.2.0.1 \*********************************************************************/ //#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English) @@ -65,7 +65,7 @@ #define D_BY "от" // Written by me #define D_BYTES "Байта" #define D_CELSIUS "Целзий" -#define D_CHANNEL "Channel" +#define D_CHANNEL "Канал" #define D_CO2 "Въглероден диоксид" #define D_CODE "код" // Button code #define D_COLDLIGHT "Хладна" @@ -440,12 +440,12 @@ #define D_PARTICALS_BEYOND "Частици" // xsns_32_mpu6050.ino -#define D_AX_AXIS "Accel. X-Axis" -#define D_AY_AXIS "Accel. Y-Axis" -#define D_AZ_AXIS "Accel. Z-Axis" -#define D_GX_AXIS "Gyro X-Axis" -#define D_GY_AXIS "Gyro Y-Axis" -#define D_GZ_AXIS "Gyro Z-Axis" +#define D_AX_AXIS "Ускорение - ос X" +#define D_AY_AXIS "Ускорение - ос Y" +#define D_AZ_AXIS "Ускорение - ос Z" +#define D_GX_AXIS "Жироскоп - ос X" +#define D_GY_AXIS "Жироскоп - ос Y" +#define D_GZ_AXIS "Жироскоп - ос Z" // sonoff_template.h #define D_SENSOR_NONE "Няма"
%s " D_GPIO "%d %s
, {m} = , {e} =