From f8666c04108f1fc8d286f3a7738cf8689f7ea1b4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 28 Aug 2018 10:26:33 +0200 Subject: [PATCH] Some requested additions * 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) --- sonoff/_changelog.ino | 3 +++ sonoff/sonoff.ino | 6 ++++++ sonoff/xdrv_10_rules.ino | 14 +++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 97822dec0..c021faba3 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -3,6 +3,9 @@ * 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) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index a006c1b0a..ad091fd8d 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2528,6 +2528,12 @@ 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)) { + for (byte i = 0; i < MAX_RULE_SETS; i++) { + if (bitRead(Settings.rule_stop, i)) { bitWrite(Settings.rule_enabled, i, 0); } + } + } + Settings.bootcount++; snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BOOT_COUNT " %d"), Settings.bootcount); AddLog(LOG_LEVEL_DEBUG); diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index f0b8611f6..fb40fc95f 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -486,7 +486,7 @@ boolean RulesCommand() } else if ((CMND_RULE == command_code) && (index > 0) && (index <= MAX_RULE_SETS)) { if ((XdrvMailbox.data_len > 0) && (XdrvMailbox.data_len < sizeof(Settings.rules[index -1]))) { - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 6)) { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 10)) { switch (XdrvMailbox.payload) { case 0: // Off case 1: // On @@ -502,6 +502,13 @@ boolean RulesCommand() case 6: // Toggle bitWrite(Settings.rule_once, index -1, bitRead(Settings.rule_once, index -1) ^1); break; + case 8: // Off + case 9: // On + bitWrite(Settings.rule_stop, index -1, XdrvMailbox.payload &1); + break; + case 10: // Toggle + bitWrite(Settings.rule_stop, index -1, bitRead(Settings.rule_stop, index -1) ^1); + break; } } else { int offset = 0; @@ -519,8 +526,9 @@ boolean RulesCommand() } rules_triggers[index -1] = 0; // Reset once flag } - snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s%d\":\"%s\",\"Once\":\"%s\",\"Free\":%d,\"Rules\":\"%s\"}"), - command, index, GetStateText(bitRead(Settings.rule_enabled, index -1)), GetStateText(bitRead(Settings.rule_once, index -1)), sizeof(Settings.rules[index -1]) - strlen(Settings.rules[index -1]) -1, Settings.rules[index -1]); + snprintf_P (mqtt_data, sizeof(mqtt_data), PSTR("{\"%s%d\":\"%s\",\"Once\":\"%s\",\"StopOnError\":\"%s\",\"Free\":%d,\"Rules\":\"%s\"}"), + command, index, GetStateText(bitRead(Settings.rule_enabled, index -1)), GetStateText(bitRead(Settings.rule_once, index -1)), + GetStateText(bitRead(Settings.rule_stop, index -1)), sizeof(Settings.rules[index -1]) - strlen(Settings.rules[index -1]) -1, Settings.rules[index -1]); } else if ((CMND_RULETIMER == command_code) && (index > 0) && (index <= MAX_RULE_TIMERS)) { if (XdrvMailbox.data_len > 0) {