diff --git a/CHANGELOG.md b/CHANGELOG.md index 29a92c959..f84d98025 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,10 @@ All notable changes to this project will be documented in this file. ## [9.4.0.3] ### Added - Make Telegram command ``TmState`` persistent (#11965) -- Add Zigbee firmware for Tube's Zigbee coordinator based on EFR32 and ESP32 -- Add Zigbee firmware 6.7.9 for Sonoff ZBBridge +- Zigbee firmware for Tube's Zigbee coordinator based on EFR32 and ESP32 +- Zigbee firmware 6.7.9 for Sonoff ZBBridge +- Defines ``USER_RULE1``, ``USER_RULE2`` and ``USER_RULE3`` to store rules at compile time +- Define ``USER_BACKLOG`` to store commands at compile time to be executed at firmware load or when executing command ``reset`` ## [9.4.0.2] 20210430 ### Added diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 337ff0a18..1b5274626 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -82,6 +82,10 @@ The binaries can be downloaded from either https://github.com/arendst/Tasmota/tr - ESP32 pulldown buttons ``Button_d`` and ``Button_id`` and switches ``Switch_d`` [#10814](https://github.com/arendst/Tasmota/issues/10814) - Support for MQTT using Azure IoT Hub by Kevin Saye [#11906](https://github.com/arendst/Tasmota/issues/11906) - Make Telegram command ``TmState`` persistent [#11965](https://github.com/arendst/Tasmota/issues/11965) +- Zigbee firmware for Tube's Zigbee coordinator based on EFR32 and ESP32 +- Zigbee firmware 6.7.9 for Sonoff ZBBridge +- Defines ``USER_RULE1``, ``USER_RULE2`` and ``USER_RULE3`` to store rules at compile time +- Define ``USER_BACKLOG`` to store commands at compile time to be executed at firmware load or when executing command ``reset`` ### Breaking Changed diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 5861c5710..6b05379e0 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -463,12 +463,15 @@ #define USE_RULES // Add support for rules (+8k code) // #define USE_EXPRESSION // Add support for expression evaluation in rules (+3k2 code, +64 bytes mem) // #define SUPPORT_IF_STATEMENT // Add support for IF statement in rules (+4k2 code, -332 bytes mem) +// #define USER_RULE1 "" // Add rule1 data saved at initial firmware load or when command reset is executed +// #define USER_RULE2 "" // Add rule2 data saved at initial firmware load or when command reset is executed +// #define USER_RULE3 "" // Add rule3 data saved at initial firmware load or when command reset is executed //#define USE_SCRIPT // Add support for script (+17k code) - //#define USE_SCRIPT_FATFS 4 // Script: Add FAT FileSystem Support - +// #define USE_SCRIPT_FATFS 4 // Script: Add FAT FileSystem Support // #define SUPPORT_MQTT_EVENT // Support trigger event with MQTT subscriptions (+3k5 code) +//#define USER_BACKLOG "" // Add commands executed at firmware load or when command reset is executed // -- Optional modules ---------------------------- #define ROTARY_V1 // Add support for Rotary Encoder as used in MI Desk Lamp (+0k8 code) diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 74e66166f..0fc0f3f74 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -1086,6 +1086,37 @@ void SettingsDefaultSet2(void) { #ifdef USER_TEMPLATE String user_template = USER_TEMPLATE; JsonTemplate((char*)user_template.c_str()); + user_template = (const char*) nullptr; // Force deallocation of the String internal memory +#endif + +#ifdef USE_RULES +#ifdef USER_RULE1 + String user_rule1 = F("Rule1 "); + user_rule1 += USER_RULE1; + ExecuteCommand((char*)user_rule1.c_str(), SRC_RESTART); + user_rule1 = (const char*) nullptr; // Force deallocation of the String internal memory +#endif + +#ifdef USER_RULE2 + String user_rule2 = F("Rule2 "); + user_rule2 += USER_RULE2; + ExecuteCommand((char*)user_rule2.c_str(), SRC_RESTART); + user_rule2 = (const char*) nullptr; // Force deallocation of the String internal memory +#endif + +#ifdef USER_RULE3 + String user_rule3 = F("Rule3 "); + user_rule3 += USER_RULE3; + ExecuteCommand((char*)user_rule3.c_str(), SRC_RESTART); + user_rule3 = (const char*) nullptr; // Force deallocation of the String internal memory +#endif +#endif // USE_RULES + +#ifdef USER_BACKLOG + String user_backlog = F("Backlog0 "); + user_backlog += USER_BACKLOG; + ExecuteCommand((char*)user_backlog.c_str(), SRC_RESTART); + user_backlog = (const char*) nullptr; // Force deallocation of the String internal memory #endif } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 13744c602..7a33fcffc 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -336,11 +336,11 @@ void CmndBacklog(void) { #endif { // Ignore semicolon (; = end of single command) between brackets {} - char *next = strchr(blcommand, '\0') +1; // Prepare for next ; - while ((next != nullptr) && (ChrCount(blcommand, "{") != ChrCount(blcommand, "}"))) { // Check for valid {} count - next--; // Select end of line - *next = ';'; // Restore ; removed by strtok() - next = strtok(nullptr, ";"); // Point to begin of next string up to next ; or nullptr + char *next = strchr(blcommand, '\0') +1; // Prepare for next ; + while ((next != nullptr) && (ChrCount(blcommand, "{") != ChrCount(blcommand, "}"))) { // Check for valid {} pair + next--; // Select end of line + *next = ';'; // Restore ; removed by strtok() + next = strtok(nullptr, ";"); // Point to begin of next string up to next ; or nullptr } // Skip unnecessary command Backlog at start of blcommand while(true) { @@ -747,8 +747,8 @@ void CmndSeriallog(void) Response_P(S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, Settings.seriallog_level, TasmotaGlobal.seriallog_level); } -void CmndRestart(void) -{ +void CmndRestart(void) { + if (TasmotaGlobal.restart_flag) { return; } switch (XdrvMailbox.payload) { case 1: TasmotaGlobal.restart_flag = 2; @@ -760,15 +760,19 @@ void CmndRestart(void) ResponseCmndChar(PSTR(D_JSON_HALTING)); break; case -1: + TasmotaGlobal.restart_flag = 255; CmndCrash(); // force a crash break; case -2: + TasmotaGlobal.restart_flag = 255; CmndWDT(); break; case -3: + TasmotaGlobal.restart_flag = 255; CmndBlockedLoop(); break; case 99: + TasmotaGlobal.restart_flag = 255; AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_RESTARTING)); EspRestart(); break; @@ -1863,8 +1867,8 @@ void CmndTeleperiod(void) ResponseCmndNumber(Settings.tele_period); } -void CmndReset(void) -{ +void CmndReset(void) { + if (TasmotaGlobal.restart_flag) { return; } switch (XdrvMailbox.payload) { case 1: TasmotaGlobal.restart_flag = 211;