mirror of https://github.com/arendst/Tasmota.git
Add multiple GroupTopic<x> (x=1-4) (default disabled)
grouptopic (1-4) subscription even when USE_DEVICE_GROUPS is not used.
This commit is contained in:
parent
ebb2d7a64b
commit
898fff9dbc
|
@ -344,6 +344,7 @@
|
|||
// -- MQTT ----------------------------------------
|
||||
#define MQTT_TELE_RETAIN 0 // Tele messages may send retain flag (0 = off, 1 = on)
|
||||
#define MQTT_CLEAN_SESSION 1 // Mqtt clean session connection (0 = No clean session, 1 = Clean session (default))
|
||||
//#define USE_GROUPTOPIC_SET // Enable multiple GROUPTOPIC<x>, x=1-4 (+0k1 code)
|
||||
|
||||
// -- MQTT - Domoticz -----------------------------
|
||||
#define USE_DOMOTICZ // Enable Domoticz (+6k code, +0.3k mem)
|
||||
|
|
|
@ -130,11 +130,11 @@ char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopi
|
|||
return stopic;
|
||||
}
|
||||
|
||||
char* GetGroupTopic_P(char *stopic, const char* subtopic)
|
||||
char* GetGroupTopic_P(char *stopic, const char* subtopic, int itopic)
|
||||
{
|
||||
// SetOption75 0: %prefix%/nothing/%topic% = cmnd/nothing/<grouptopic>/#
|
||||
// SetOption75 1: cmnd/<grouptopic>
|
||||
return GetTopic_P(stopic, (Settings.flag3.grouptopic_mode) ? CMND +8 : CMND, SettingsText(SET_MQTT_GRP_TOPIC), subtopic); // SetOption75 - GroupTopic replaces %topic% (0) or fixed topic cmnd/grouptopic (1)
|
||||
return GetTopic_P(stopic, (Settings.flag3.grouptopic_mode) ? CMND +8 : CMND, SettingsText(itopic), subtopic); // SetOption75 - GroupTopic replaces %topic% (0) or fixed topic cmnd/grouptopic (1)
|
||||
}
|
||||
|
||||
char* GetFallbackTopic_P(char *stopic, const char* subtopic)
|
||||
|
|
|
@ -98,6 +98,7 @@ extern "C" void resetPins();
|
|||
#define CODE_IMAGE_STR "sensors"
|
||||
|
||||
#undef USE_DISCOVERY // Disable mDNS (+8k code or +23.5k code with core 2_5_x, +0.3k mem)
|
||||
#undef USE_GROUPTOPIC_SET // Disable multiple GROUPTOPIC<x>, x=1-4 (+0k1 code)
|
||||
|
||||
// -- Optional modules ----------------------------
|
||||
//#define ROTARY_V1 // Add support for MI Desk Lamp
|
||||
|
@ -273,6 +274,7 @@ extern "C" void resetPins();
|
|||
#undef USE_PWM_DIMMER_REMOTE // Disbale support for remote switches to PWM Dimmer
|
||||
#undef DEBUG_THEO // Disable debug code
|
||||
#undef USE_DEBUG_DRIVER // Disable debug code
|
||||
#undef USE_GROUPTOPIC_SET // Disable multiple GROUPTOPIC<x>, x=1-4 (+0k1 code)
|
||||
#endif // FIRMWARE_KNX_NO_EMULATION
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -292,6 +294,7 @@ extern "C" void resetPins();
|
|||
#undef USE_EMULATION_WEMO // Disable Belkin WeMo emulation for Alexa (+6k code, +2k mem common)
|
||||
#undef USE_DOMOTICZ // Disable Domoticz
|
||||
#undef USE_HOME_ASSISTANT // Disable Home Assistant
|
||||
#undef USE_GROUPTOPIC_SET // Disable multiple GROUPTOPIC<x>, x=1-4 (+0k1 code)
|
||||
|
||||
// -- Optional modules ----------------------------
|
||||
#undef ROTARY_V1 // Disable support for MI Desk Lamp
|
||||
|
@ -373,6 +376,7 @@ extern "C" void resetPins();
|
|||
//#undef USE_SUNRISE // Disable support for Sunrise and sunset tools
|
||||
//#undef USE_RULES // Disable support for rules
|
||||
#undef USE_DISCOVERY // Disable mDNS for the following services (+8k code or +23.5k code with core 2_5_x, +0.3k mem)
|
||||
#undef USE_GROUPTOPIC_SET // Disable multiple GROUPTOPIC<x>, x=1-4 (+0k1 code)
|
||||
|
||||
// -- Optional modules ----------------------------
|
||||
#undef ROTARY_V1 // Disable support for MI Desk Lamp
|
||||
|
@ -474,6 +478,7 @@ extern "C" void resetPins();
|
|||
#undef USE_DOMOTICZ // Disable Domoticz
|
||||
#undef USE_HOME_ASSISTANT // Disable Home Assistant
|
||||
#undef USE_MQTT_TLS // Disable TLS support won't work as the MQTTHost is not set
|
||||
#undef USE_GROUPTOPIC_SET // Disable multiple GROUPTOPIC<x>, x=1-4 (+0k1 code)
|
||||
#undef USE_KNX // Disable KNX IP Protocol Support
|
||||
//#undef USE_WEBSERVER // Disable Webserver
|
||||
#undef USE_WEBSEND_RESPONSE // Disable command WebSend response message (+1k code)
|
||||
|
@ -595,6 +600,7 @@ extern "C" void resetPins();
|
|||
#undef USE_DOMOTICZ // Disable Domoticz
|
||||
#undef USE_HOME_ASSISTANT // Disable Home Assistant
|
||||
//#undef USE_MQTT_TLS // Disable TLS support won't work as the MQTTHost is not set
|
||||
#undef USE_GROUPTOPIC_SET // Disable multiple GROUPTOPIC<x>, x=1-4 (+0k1 code)
|
||||
#undef USE_KNX // Disable KNX IP Protocol Support
|
||||
//#undef USE_WEBSERVER // Disable Webserver
|
||||
#undef USE_WEBSEND_RESPONSE // Disable command WebSend response message (+1k code)
|
||||
|
|
|
@ -2127,7 +2127,16 @@ void HandleInformation(void)
|
|||
WSContentSend_P(PSTR("}1" D_MQTT_CLIENT "}2%s"), mqtt_client);
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_TOPIC "}2%s"), SettingsText(SET_MQTT_TOPIC));
|
||||
// WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC "}2%s"), SettingsText(SET_MQTT_GRP_TOPIC));
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC "}2%s"), GetGroupTopic_P(stopic, ""));
|
||||
#ifdef USE_GROUPTOPIC_SET
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC " 1}2%s"), GetGroupTopic_P(stopic, "", SET_MQTT_GRP_TOPIC));
|
||||
for(uint32_t i=0; i < 3; i++) {
|
||||
if (strlen(SettingsText(SET_MQTT_GRP_TOPIC2+i))) {
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC " %d}2%s"), 2+i, GetGroupTopic_P(stopic, "", SET_MQTT_GRP_TOPIC2+i));
|
||||
}
|
||||
}
|
||||
#else // USE_GROUPTOPIC_SET
|
||||
WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC "}2%s"), GetGroupTopic_P(stopic, "", SET_MQTT_GRP_TOPIC));
|
||||
#endif // USE_GROUPTOPIC_SET
|
||||
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, ""));
|
||||
} else {
|
||||
|
|
|
@ -510,8 +510,16 @@ void MqttConnected(void)
|
|||
GetTopic_P(stopic, CMND, mqtt_topic, PSTR("#"));
|
||||
MqttSubscribe(stopic);
|
||||
if (strstr_P(SettingsText(SET_MQTT_FULLTOPIC), MQTT_TOKEN_TOPIC) != nullptr) {
|
||||
GetGroupTopic_P(stopic, PSTR("#")); // SetOption75 0: %prefix%/nothing/%topic% = cmnd/nothing/<grouptopic>/# or SetOption75 1: cmnd/<grouptopic>
|
||||
GetGroupTopic_P(stopic, PSTR("#"), SET_MQTT_GRP_TOPIC); // SetOption75 0: %prefix%/nothing/%topic% = cmnd/nothing/<grouptopic>/# or SetOption75 1: cmnd/<grouptopic>
|
||||
MqttSubscribe(stopic);
|
||||
#ifdef USE_GROUPTOPIC_SET
|
||||
for(uint32_t i=0; i < 3; i++) {
|
||||
if (strlen(SettingsText(SET_MQTT_GRP_TOPIC2+i))) {
|
||||
GetGroupTopic_P(stopic, PSTR("#"), SET_MQTT_GRP_TOPIC2+i);
|
||||
MqttSubscribe(stopic);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
GetFallbackTopic_P(stopic, PSTR("#"));
|
||||
MqttSubscribe(stopic);
|
||||
}
|
||||
|
@ -522,7 +530,7 @@ 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, ""), GetGroupTopic_P(stopic2, ""));
|
||||
ModuleName().c_str(), my_version, my_image, GetFallbackTopic_P(stopic, ""), GetGroupTopic_P(stopic2, "", SET_MQTT_GRP_TOPIC));
|
||||
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_INFO "1"));
|
||||
#ifdef USE_WEBSERVER
|
||||
if (Settings.webserver) {
|
||||
|
@ -881,26 +889,26 @@ void CmndPublish(void)
|
|||
|
||||
void CmndGroupTopic(void)
|
||||
{
|
||||
#ifdef USE_DEVICE_GROUPS
|
||||
#if defined(USE_DEVICE_GROUPS ) || defined(USE_GROUPTOPIC_SET)
|
||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 4)) {
|
||||
uint32_t settings_text_index = (XdrvMailbox.index <= 1 ? SET_MQTT_GRP_TOPIC : SET_MQTT_GRP_TOPIC2 + XdrvMailbox.index - 2);
|
||||
#endif // USE_DEVICE_GROUPS
|
||||
#endif // USE_DEVICE_GROUPS || USE_GROUPTOPIC_SET
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
MakeValidMqtt(0, XdrvMailbox.data);
|
||||
if (!strcmp(XdrvMailbox.data, mqtt_client)) { SetShortcutDefault(); }
|
||||
#ifdef USE_DEVICE_GROUPS
|
||||
#if defined(USE_DEVICE_GROUPS ) || defined(USE_GROUPTOPIC_SET)
|
||||
SettingsUpdateText(settings_text_index, (SC_DEFAULT == Shortcut()) ? MQTT_GRPTOPIC : XdrvMailbox.data);
|
||||
#else // USE_DEVICE_GROUPS
|
||||
#else // USE_DEVICE_GROUPS || USE_GROUPTOPIC_SET
|
||||
SettingsUpdateText(SET_MQTT_GRP_TOPIC, (SC_DEFAULT == Shortcut()) ? MQTT_GRPTOPIC : XdrvMailbox.data);
|
||||
#endif // USE_DEVICE_GROUPS
|
||||
#endif // USE_DEVICE_GROUPS || USE_GROUPTOPIC_SET
|
||||
restart_flag = 2;
|
||||
}
|
||||
#ifdef USE_DEVICE_GROUPS
|
||||
#if defined(USE_DEVICE_GROUPS ) || defined(USE_GROUPTOPIC_SET)
|
||||
ResponseCmndChar(SettingsText(settings_text_index));
|
||||
}
|
||||
#else // USE_DEVICE_GROUPS
|
||||
#else // USE_DEVICE_GROUPS || USE_GROUPTOPIC_SET
|
||||
ResponseCmndChar(SettingsText(SET_MQTT_GRP_TOPIC));
|
||||
#endif // USE_DEVICE_GROUPS
|
||||
#endif // USE_DEVICE_GROUPS || USE_GROUPTOPIC_SET
|
||||
}
|
||||
|
||||
void CmndTopic(void)
|
||||
|
|
|
@ -685,7 +685,7 @@ void ShutterButtonHandler(void)
|
|||
for (uint32_t i = 0; i < MAX_SHUTTERS; i++) {
|
||||
if ((i==shutter_index) || (Settings.shutter_button[button_index] & (0x01<<30))) {
|
||||
snprintf_P(scommand, sizeof(scommand),PSTR("ShutterPosition%d"), i+1);
|
||||
GetGroupTopic_P(stopic, scommand);
|
||||
GetGroupTopic_P(stopic, scommand, SET_MQTT_GRP_TOPIC);
|
||||
Response_P("%d", position);
|
||||
MqttPublish(stopic, false);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue