Add compile time rules and commands

- Add defines ``USER_RULE1``, ``USER_RULE2`` and ``USER_RULE3`` to store rules at compile time
- Add define ``USER_BACKLOG`` to store commands at compile time to be executed at firmware load or when executing command ``reset``
This commit is contained in:
Theo Arends 2021-05-02 17:57:03 +02:00
parent 6c46278778
commit 38ab8c4826
5 changed files with 57 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -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 "<Any rule1 data>" // Add rule1 data saved at initial firmware load or when command reset is executed
// #define USER_RULE2 "<Any rule2 data>" // Add rule2 data saved at initial firmware load or when command reset is executed
// #define USER_RULE3 "<Any rule3 data>" // 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 SUPPORT_MQTT_EVENT // Support trigger event with MQTT subscriptions (+3k5 code)
//#define USER_BACKLOG "<Any command separated by a semicolon (;)>" // 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)

View File

@ -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
}

View File

@ -337,7 +337,7 @@ void CmndBacklog(void) {
{
// 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
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
@ -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;