From e497421ace372fc5b4f2898e118b20dd710704d4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 31 Oct 2019 17:24:06 +0100 Subject: [PATCH] Add command SetOption75 0/1 to switch between grouptopic Add command SetOption75 0/1 to switch between grouptopic (0) using fulltopic replacing %topic% or (1) is cmnd/ (#6779) --- tasmota/_changelog.ino | 3 ++- tasmota/settings.h | 2 +- tasmota/support_command.ino | 3 ++- tasmota/tasmota.ino | 23 +++++++++++++++++++---- tasmota/xdrv_01_webserver.ino | 5 +++-- tasmota/xdrv_02_mqtt.ino | 7 ++++--- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/tasmota/_changelog.ino b/tasmota/_changelog.ino index b98b89210..055d01a52 100644 --- a/tasmota/_changelog.ino +++ b/tasmota/_changelog.ino @@ -1,12 +1,13 @@ /*********************************************************************************************\ * 7.0.0.1 20191027 - * Remove references to versions before 6.x + * Remove references to versions before 6.0 * Change default GUI to dark theme * Add command SetOption73 0/1 to re-enable HTTP Cross-Origin Resource Sharing (CORS) now default disabled (#6767) * Add frequency to ADE7953 energy monitor as used in Shelly 2.5 by ljakob (#6778) * Add command SetOption74 0/1 to enable DS18x20 internal pull-up and remove define DS18B20_INTERNAL_PULLUP (#6795) * Fix better control of RGB/White when SetOption37 >128, added Dimmer1 and Dimmer2 commands (#6714) * Add hide Alexa objects with friendlyname starting with '$' (#6722, #6762) + * Add command SetOption75 0/1 to switch between grouptopic (0) using fulltopic replacing %topic% or (1) is cmnd/ (#6779) * * 6.7.1.1 20191026 * Change ArduinoSlave to TasmotaSlave (Experimental) diff --git a/tasmota/settings.h b/tasmota/settings.h index 8cd575cf1..332782162 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -88,7 +88,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t hardware_energy_total : 1; // bit 22 (v6.6.0.15) - SetOption72 - Enable / Disable hardware energy total counter as reference (#6561) uint32_t cors_enabled : 1; // bit 23 (v7.0.0.1) - SetOption73 - Enable HTTP CORS uint32_t ds18x20_internal_pullup : 1; // bit 24 (v7.0.0.1) - SetOption74 - Enable internal pullup for single DS18x20 sensor - uint32_t spare25 : 1; + uint32_t grouptopic_mode : 1; // bit 25 (v7.0.0.1) - SetOption75 - GroupTopic replaces %topic% (0) or fixed topic cmnd/grouptopic (1) uint32_t spare26 : 1; uint32_t spare27 : 1; uint32_t spare28 : 1; diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 1dbbbdc2d..47908e2d0 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -143,7 +143,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) bool grpflg = (strstr(topicBuf, Settings.mqtt_grptopic) != nullptr); char stemp1[TOPSZ]; - GetFallbackTopic_P(stemp1, CMND, ""); // Full Fallback topic = cmnd/DVES_xxxxxxxx_fb/ + GetFallbackTopic_P(stemp1, ""); // Full Fallback topic = cmnd/DVES_xxxxxxxx_fb/ fallback_topic_flag = (!strncmp(topicBuf, stemp1, strlen(stemp1))); char *type = strrchr(topicBuf, '/'); // Last part of received topic is always the command (type) @@ -718,6 +718,7 @@ void CmndSetoption(void) WiFiSetSleepMode(); // Update WiFi sleep mode accordingly break; case 18: // SetOption68 for multi-channel PWM, requires a reboot + case 25: // SetOption75 grouptopic change restart_flag = 2; break; } diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 263888558..1240a60de 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -243,18 +243,26 @@ char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopi prefix 4 = Cmnd fallback prefix 5 = Stat fallback prefix 6 = Tele fallback + prefix 8 = Cmnd topic + prefix 9 = Stat topic + prefix 10 = Tele topic */ char romram[CMDSZ]; String fulltopic; snprintf_P(romram, sizeof(romram), subtopic); if (fallback_topic_flag || (prefix > 3)) { + bool fallback = (prefix < 8); prefix &= 3; char stemp[11]; fulltopic = GetTextIndexed(stemp, sizeof(stemp), prefix, kPrefixes); fulltopic += F("/"); - fulltopic += mqtt_client; - fulltopic += F("_fb"); // cmnd/_fb + if (fallback) { + fulltopic += mqtt_client; + fulltopic += F("_fb"); // cmnd/_fb + } else { + fulltopic += topic; // cmnd/ + } } else { fulltopic = Settings.mqtt_fulltopic; if ((0 == prefix) && (-1 == fulltopic.indexOf(FPSTR(MQTT_TOKEN_PREFIX)))) { @@ -282,9 +290,16 @@ char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopi return stopic; } -char* GetFallbackTopic_P(char *stopic, uint32_t prefix, const char* subtopic) +char* GetGroupTopic_P(char *stopic, const char* subtopic) { - return GetTopic_P(stopic, prefix +4, nullptr, subtopic); + // SetOption75 0: %prefix%/nothing/%topic% = cmnd/nothing//# + // SetOption75 1: cmnd/ + return GetTopic_P(stopic, (Settings.flag3.grouptopic_mode) ? CMND +8 : CMND, Settings.mqtt_grptopic, subtopic); +} + +char* GetFallbackTopic_P(char *stopic, const char* subtopic) +{ + return GetTopic_P(stopic, CMND +4, nullptr, subtopic); } char* GetStateText(uint32_t state) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 648dca783..634759fe0 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1910,9 +1910,10 @@ void HandleInformation(void) #endif WSContentSend_P(PSTR("}1" D_MQTT_CLIENT "}2%s"), mqtt_client); WSContentSend_P(PSTR("}1" D_MQTT_TOPIC "}2%s"), Settings.mqtt_topic); - WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC "}2%s"), Settings.mqtt_grptopic); +// WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC "}2%s"), Settings.mqtt_grptopic); + WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC "}2%s"), GetGroupTopic_P(stopic, "")); WSContentSend_P(PSTR("}1" D_MQTT_FULL_TOPIC "}2%s"), GetTopic_P(stopic, CMND, mqtt_topic, "")); - WSContentSend_P(PSTR("}1" D_MQTT " " D_FALLBACK_TOPIC "}2%s"), GetFallbackTopic_P(stopic, CMND, "")); + WSContentSend_P(PSTR("}1" D_MQTT " " D_FALLBACK_TOPIC "}2%s"), GetFallbackTopic_P(stopic, "")); } else { WSContentSend_P(PSTR("}1" D_MQTT "}2" D_DISABLED)); } diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index cafdc80da..450c12d90 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -528,9 +528,9 @@ void MqttConnected(void) GetTopic_P(stopic, CMND, mqtt_topic, PSTR("#")); MqttSubscribe(stopic); if (strstr_P(Settings.mqtt_fulltopic, MQTT_TOKEN_TOPIC) != nullptr) { - GetTopic_P(stopic, CMND, Settings.mqtt_grptopic, PSTR("#")); + GetGroupTopic_P(stopic, PSTR("#")); // SetOption75 0: %prefix%/nothing/%topic% = cmnd/nothing//# or SetOption75 1: cmnd/ MqttSubscribe(stopic); - GetFallbackTopic_P(stopic, CMND, PSTR("#")); + GetFallbackTopic_P(stopic, PSTR("#")); MqttSubscribe(stopic); } @@ -538,8 +538,9 @@ void MqttConnected(void) } if (Mqtt.initial_connection_state) { + char stopic2[TOPSZ]; Response_P(PSTR("{\"" D_CMND_MODULE "\":\"%s\",\"" D_JSON_VERSION "\":\"%s%s\",\"" D_JSON_FALLBACKTOPIC "\":\"%s\",\"" D_CMND_GROUPTOPIC "\":\"%s\"}"), - ModuleName().c_str(), my_version, my_image, GetFallbackTopic_P(stopic, CMND, ""), Settings.mqtt_grptopic); + ModuleName().c_str(), my_version, my_image, GetFallbackTopic_P(stopic, ""), GetGroupTopic_P(stopic2, "")); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_INFO "1")); #ifdef USE_WEBSERVER if (Settings.webserver) {