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/<grouptopic> (#6779)
This commit is contained in:
Theo Arends 2019-10-31 17:24:06 +01:00
parent 23cef04b9e
commit e497421ace
6 changed files with 31 additions and 12 deletions

View File

@ -1,12 +1,13 @@
/*********************************************************************************************\ /*********************************************************************************************\
* 7.0.0.1 20191027 * 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 * 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 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 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) * 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) * 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 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/<grouptopic> (#6779)
* *
* 6.7.1.1 20191026 * 6.7.1.1 20191026
* Change ArduinoSlave to TasmotaSlave (Experimental) * Change ArduinoSlave to TasmotaSlave (Experimental)

View File

@ -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 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 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 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 spare26 : 1;
uint32_t spare27 : 1; uint32_t spare27 : 1;
uint32_t spare28 : 1; uint32_t spare28 : 1;

View File

@ -143,7 +143,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len)
bool grpflg = (strstr(topicBuf, Settings.mqtt_grptopic) != nullptr); bool grpflg = (strstr(topicBuf, Settings.mqtt_grptopic) != nullptr);
char stemp1[TOPSZ]; 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))); fallback_topic_flag = (!strncmp(topicBuf, stemp1, strlen(stemp1)));
char *type = strrchr(topicBuf, '/'); // Last part of received topic is always the command (type) 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 WiFiSetSleepMode(); // Update WiFi sleep mode accordingly
break; break;
case 18: // SetOption68 for multi-channel PWM, requires a reboot case 18: // SetOption68 for multi-channel PWM, requires a reboot
case 25: // SetOption75 grouptopic change
restart_flag = 2; restart_flag = 2;
break; break;
} }

View File

@ -243,18 +243,26 @@ char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopi
prefix 4 = Cmnd fallback prefix 4 = Cmnd fallback
prefix 5 = Stat fallback prefix 5 = Stat fallback
prefix 6 = Tele fallback prefix 6 = Tele fallback
prefix 8 = Cmnd topic
prefix 9 = Stat topic
prefix 10 = Tele topic
*/ */
char romram[CMDSZ]; char romram[CMDSZ];
String fulltopic; String fulltopic;
snprintf_P(romram, sizeof(romram), subtopic); snprintf_P(romram, sizeof(romram), subtopic);
if (fallback_topic_flag || (prefix > 3)) { if (fallback_topic_flag || (prefix > 3)) {
bool fallback = (prefix < 8);
prefix &= 3; prefix &= 3;
char stemp[11]; char stemp[11];
fulltopic = GetTextIndexed(stemp, sizeof(stemp), prefix, kPrefixes); fulltopic = GetTextIndexed(stemp, sizeof(stemp), prefix, kPrefixes);
fulltopic += F("/"); fulltopic += F("/");
fulltopic += mqtt_client; if (fallback) {
fulltopic += F("_fb"); // cmnd/<mqttclient>_fb fulltopic += mqtt_client;
fulltopic += F("_fb"); // cmnd/<mqttclient>_fb
} else {
fulltopic += topic; // cmnd/<grouptopic>
}
} else { } else {
fulltopic = Settings.mqtt_fulltopic; fulltopic = Settings.mqtt_fulltopic;
if ((0 == prefix) && (-1 == fulltopic.indexOf(FPSTR(MQTT_TOKEN_PREFIX)))) { 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; 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/<grouptopic>/#
// SetOption75 1: cmnd/<grouptopic>
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) char* GetStateText(uint32_t state)

View File

@ -1910,9 +1910,10 @@ void HandleInformation(void)
#endif #endif
WSContentSend_P(PSTR("}1" D_MQTT_CLIENT "}2%s"), mqtt_client); 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_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_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 { } else {
WSContentSend_P(PSTR("}1" D_MQTT "}2" D_DISABLED)); WSContentSend_P(PSTR("}1" D_MQTT "}2" D_DISABLED));
} }

View File

@ -528,9 +528,9 @@ void MqttConnected(void)
GetTopic_P(stopic, CMND, mqtt_topic, PSTR("#")); GetTopic_P(stopic, CMND, mqtt_topic, PSTR("#"));
MqttSubscribe(stopic); MqttSubscribe(stopic);
if (strstr_P(Settings.mqtt_fulltopic, MQTT_TOKEN_TOPIC) != nullptr) { 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/<grouptopic>/# or SetOption75 1: cmnd/<grouptopic>
MqttSubscribe(stopic); MqttSubscribe(stopic);
GetFallbackTopic_P(stopic, CMND, PSTR("#")); GetFallbackTopic_P(stopic, PSTR("#"));
MqttSubscribe(stopic); MqttSubscribe(stopic);
} }
@ -538,8 +538,9 @@ void MqttConnected(void)
} }
if (Mqtt.initial_connection_state) { 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\"}"), 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")); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_INFO "1"));
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
if (Settings.webserver) { if (Settings.webserver) {