From 89b922675d7ed49519104839f469aaf03c8bc8ad Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 29 Apr 2021 17:00:04 +0200 Subject: [PATCH] Add backward compatibility to Template CMND fieldpair using | as command separator Add backward compatibility to Template CMND fieldpair using | as command separator (#11788) --- CHANGELOG.md | 2 +- RELEASENOTES.md | 2 +- tasmota/support.ino | 13 +++++++------ tasmota/support_tasmota.ino | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dda462284..32ad7bbd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. ## [9.4.0.2] ### Added -- Initial support for optional ``Template`` JSON fieldpair ``"CMND":";;..."`` (#11788) +- Initial support for optional ``Template`` JSON fieldpair ``"CMND":"||..."`` (#11788) - ESP32 pulldown buttons ``Button_d`` and ``Button_id`` and switches ``Switch_d`` (#10814) - Support for MQTT using Azure IoT Hub by Kevin Saye (#11906) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index ab9114bf0..4b97efa26 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -78,7 +78,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota ## Changelog v9.4.0.2 ### Added -- Initial support for optional ``Template`` JSON fieldpair ``"CMND":";;..."`` [#11788](https://github.com/arendst/Tasmota/issues/11788) +- Initial support for optional ``Template`` JSON fieldpair ``"CMND":"||..."`` [#11788](https://github.com/arendst/Tasmota/issues/11788) - 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) diff --git a/tasmota/support.ino b/tasmota/support.ino index e56b9cf82..954a553bd 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -515,7 +515,7 @@ char* UpperCase_P(char* dest, const char* source) return dest; } -char* StrStr_P(const char* source, const char* search) { +char* StrCaseStr_P(const char* source, const char* search) { char case_source[strlen(source) +1]; UpperCase_P(case_source, source); char case_search[strlen(search) +1]; @@ -1412,7 +1412,7 @@ bool ValidTemplate(const char *search) { return (strstr(template_name, search_name) != nullptr); */ - return (StrStr_P(SettingsText(SET_TEMPLATE_NAME), search) != nullptr); + return (StrCaseStr_P(SettingsText(SET_TEMPLATE_NAME), search) != nullptr); } String AnyModuleName(uint32_t index) @@ -1658,13 +1658,14 @@ bool JsonTemplate(char* dataBuf) val = root[PSTR(D_JSON_CMND)]; if (val) { - if ((USER_MODULE == Settings.module) || (StrStr_P(val.getStr(), PSTR(D_CMND_MODULE " 0")))) { // Only execute if current module = USER_MODULE = this template + if ((USER_MODULE == Settings.module) || (StrCaseStr_P(val.getStr(), PSTR(D_CMND_MODULE " 0")))) { // Only execute if current module = USER_MODULE = this template char* backup_data = XdrvMailbox.data; - XdrvMailbox.data = (char*)val.getStr(); // Backlog commands + XdrvMailbox.data = (char*)val.getStr(); // Backlog commands + ReplaceChar(XdrvMailbox.data, '|', ';'); // Support '|' as command separator for JSON backwards compatibility uint32_t backup_data_len = XdrvMailbox.data_len; - XdrvMailbox.data_len = 1; // Any data + XdrvMailbox.data_len = 1; // Any data uint32_t backup_index = XdrvMailbox.index; - XdrvMailbox.index = 0; // Backlog0 - no delay + XdrvMailbox.index = 0; // Backlog0 - no delay CmndBacklog(); XdrvMailbox.index = backup_index; XdrvMailbox.data_len = backup_data_len; diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 9f52d2747..893d8418e 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1149,7 +1149,7 @@ void Every250mSeconds(void) } #endif // FIRMWARE_MINIMAL if (ota_retry_counter < OTA_ATTEMPTS / 2) { - if (StrStr_P(TasmotaGlobal.mqtt_data, PSTR(".gz"))) { + if (StrCaseStr_P(TasmotaGlobal.mqtt_data, PSTR(".gz"))) { ota_retry_counter = 1; } else { strcat_P(TasmotaGlobal.mqtt_data, PSTR(".gz"));