diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 82bc73be3..5cc1da8e3 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,9 +1,11 @@ /* 5.14.0b * Add two rule sets of 511 characters using commands rule1, rule2 and rule3 + * Add Ukranian language file * Add rule support for IrReceive and RfReceive (#2758) * Add command WebSend [(:,:)] (#2821) * Add source information to command execution to be shown with logging option 3 (#2843) * Fix some Pow R2 and S31 checksum errors (#1907) + * Fix Hardware Watchdog restart when using event command (#2853) * * 5.14.0a * Add feature information to Status 4 diff --git a/sonoff/support.ino b/sonoff/support.ino index 6bfc32063..f92d32235 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -244,6 +244,29 @@ char* LTrim(char* p) return p; } +char* RTrim(char* p) +{ + char* q = p + strlen(p) -1; + while ((q >= p) && (isblank(*q))) { + q--; // Trim trailing spaces + } + q++; + *q = '\0'; + return p; +} + +char* Trim(char* p) +{ + if (*p == '\0') { return p; } + while (isspace(*p)) { p++; } // Trim leading spaces + if (*p == '\0') { return p; } + char* q = p + strlen(p) -1; + while (isspace(*q) && q >= p) { q--; } // Trim trailing spaces + q++; + *q = '\0'; + return p; +} + char* NoAlNumToUnderscore(char* dest, const char* source) { char* write = dest; diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 6293ebec9..b33872b7e 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -90,6 +90,7 @@ uint32_t rules_triggers[MAX_RULE_SETS] = { 0 }; uint8_t rules_trigger_count[MAX_RULE_SETS] = { 0 }; uint8_t rules_teleperiod = 0; +char event_data[100]; char vars[RULES_MAX_VARS][10] = { 0 }; /*******************************************************************************************/ @@ -374,7 +375,26 @@ void RulesEvery50ms() } } rules_old_power = rules_new_power; - } else { + } + else if(event_data[0]) { + char *event; + char *parameter; + event = strtok_r(event_data, "=", ¶meter); // event_data = fanspeed=10 + if (event) { + event = Trim(event); + if (parameter) { + parameter = Trim(parameter); + } else { + parameter = event + strlen(event); // '\0' + } + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"Event\":{\"%s\":\"%s\"}}"), event, parameter); + event_data[0] ='\0'; + RulesProcess(); + } else { + event_data[0] ='\0'; + } + } + else { rules_quota++; if (rules_quota &1) { // Every 100 ms mqtt_data[0] = '\0'; @@ -464,17 +484,7 @@ boolean RulesCommand() } else if (CMND_EVENT == command_code) { if (XdrvMailbox.data_len > 0) { - String event = XdrvMailbox.data; - String parameter = ""; - int pos = event.indexOf('='); - if (pos > 0) { - parameter = event.substring(pos +1); - parameter.trim(); - event = event.substring(0, pos); - } - event.trim(); - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"Event\":{\"%s\":\"%s\"}}"), event.c_str(), parameter.c_str()); - RulesProcess(); + strlcpy(event_data, XdrvMailbox.data, sizeof(event_data)); } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_DONE); }