Add support for up to four MQTT GroupTopics

- Bump version to 8.2.0.2
- Add support for up to four MQTT GroupTopics using the same optional Device Group names (#8014)
This commit is contained in:
Theo Arends 2020-03-28 16:48:36 +01:00
parent 962e22a252
commit dbc9f16ffc
10 changed files with 75 additions and 51 deletions

View File

@ -52,9 +52,13 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
## Changelog ## Changelog
### Version 8.2.0.1 ### Version 8.2.0.2
- Change HM-10 sensor type detection and add features (#7962) - Change HM-10 sensor type detection and add features (#7962)
- Change GPIO initialization solving possible Relay toggle on (OTA) restart - Fix possible Relay toggle on (OTA) restart
- Fix Zigbee sending wrong Sat value with Hue emulation - Fix Zigbee sending wrong Sat value with Hue emulation
- Add command ``ZbRestore`` to restore device configuration dumped with ``ZbStatus 2`` - Add Zigbee command ``ZbRestore`` to restore device configuration dumped with ``ZbStatus 2``
- Add Zigbee command ``ZbUnbind``
- Add support for unreachable (unplugged) Zigbee devices in Philips Hue emulation and Alexa
- Add support for 64x48 SSD1306 OLED (#6740)
- Add support for up to four MQTT GroupTopics using the same optional Device Group names (#8014)

View File

@ -1,13 +1,17 @@
## Unreleased (development) ## Unreleased (development)
### 8.2.0.2 20200328
- Add support for up to four MQTT GroupTopics using the same optional Device Group names (#8014)
### 8.2.0.1 20200321 ### 8.2.0.1 20200321
- Change HM-10 sensor type detection and add features (#7962) - Change HM-10 sensor type detection and add features (#7962)
- Change GPIO initialization solving possible Relay toggle on (OTA) restart - Fix possible Relay toggle on (OTA) restart
- Fix Zigbee sending wrong Sat value with Hue emulation - Fix Zigbee sending wrong Sat value with Hue emulation
- Add command ``ZbRestore`` to restore device configuration dumped with ``ZbStatus 2`` - Add ZIgbee command ``ZbRestore`` to restore device configuration dumped with ``ZbStatus 2``
- Add Zigbee command ``ZbUnbind``
- Add support for unreachable (unplugged) Zigbee devices in Philips Hue emulation and Alexa - Add support for unreachable (unplugged) Zigbee devices in Philips Hue emulation and Alexa
- Add Zigbee ``ZbUnbind``command
- Add support for 64x48 SSD1306 OLED (#6740) - Add support for 64x48 SSD1306 OLED (#6740)
## Released ## Released

View File

@ -344,7 +344,6 @@
// -- MQTT ---------------------------------------- // -- MQTT ----------------------------------------
#define MQTT_TELE_RETAIN 0 // Tele messages may send retain flag (0 = off, 1 = on) #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 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 ----------------------------- // -- MQTT - Domoticz -----------------------------
#define USE_DOMOTICZ // Enable Domoticz (+6k code, +0.3k mem) #define USE_DOMOTICZ // Enable Domoticz (+6k code, +0.3k mem)

View File

@ -107,9 +107,11 @@ void ResponseCmndIdxChar(const char* value)
void ResponseCmndAll(uint32_t text_index, uint32_t count) void ResponseCmndAll(uint32_t text_index, uint32_t count)
{ {
uint32_t real_index = text_index;
mqtt_data[0] = '\0'; mqtt_data[0] = '\0';
for (uint32_t i = 0; i < count; i++) { for (uint32_t i = 0; i < count; i++) {
ResponseAppend_P(PSTR("%c\"%s%d\":\"%s\""), (i) ? ',' : '{', XdrvMailbox.command, i +1, SettingsText(text_index +i)); if ((SET_MQTT_GRP_TOPIC == text_index) && (1 == i)) { real_index = SET_MQTT_GRP_TOPIC2 -1; }
ResponseAppend_P(PSTR("%c\"%s%d\":\"%s\""), (i) ? ',' : '{', XdrvMailbox.command, i +1, SettingsText(real_index +i));
} }
ResponseJsonEnd(); ResponseJsonEnd();
} }

View File

@ -130,7 +130,7 @@ char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopi
return stopic; return stopic;
} }
char* GetGroupTopic_P(char *stopic, const char* subtopic, int itopic) char* GetGroupTopic_P(char *stopic, const char* subtopic, uint32_t itopic)
{ {
// SetOption75 0: %prefix%/nothing/%topic% = cmnd/nothing/<grouptopic>/# // SetOption75 0: %prefix%/nothing/%topic% = cmnd/nothing/<grouptopic>/#
// SetOption75 1: cmnd/<grouptopic> // SetOption75 1: cmnd/<grouptopic>

View File

@ -81,6 +81,7 @@ const uint8_t MAX_NTP_SERVERS = 3; // Max number of NTP servers
const uint8_t MAX_RULE_MEMS = 16; // Max number of saved vars const uint8_t MAX_RULE_MEMS = 16; // Max number of saved vars
const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names
const uint8_t MAX_BUTTON_TEXT = 16; // Max number of GUI button labels const uint8_t MAX_BUTTON_TEXT = 16; // Max number of GUI button labels
const uint8_t MAX_GROUP_TOPICS = 4; // Max number of Group Topics
const uint8_t MAX_HUE_DEVICES = 15; // Max number of Philips Hue device per emulation const uint8_t MAX_HUE_DEVICES = 15; // Max number of Philips Hue device per emulation

View File

@ -98,7 +98,6 @@ extern "C" void resetPins();
#define CODE_IMAGE_STR "sensors" #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_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 ---------------------------- // -- Optional modules ----------------------------
//#define ROTARY_V1 // Add support for MI Desk Lamp //#define ROTARY_V1 // Add support for MI Desk Lamp
@ -274,7 +273,6 @@ extern "C" void resetPins();
#undef USE_PWM_DIMMER_REMOTE // Disbale support for remote switches to PWM Dimmer #undef USE_PWM_DIMMER_REMOTE // Disbale support for remote switches to PWM Dimmer
#undef DEBUG_THEO // Disable debug code #undef DEBUG_THEO // Disable debug code
#undef USE_DEBUG_DRIVER // 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 #endif // FIRMWARE_KNX_NO_EMULATION
/*********************************************************************************************\ /*********************************************************************************************\
@ -294,7 +292,6 @@ extern "C" void resetPins();
#undef USE_EMULATION_WEMO // Disable Belkin WeMo emulation for Alexa (+6k code, +2k mem common) #undef USE_EMULATION_WEMO // Disable Belkin WeMo emulation for Alexa (+6k code, +2k mem common)
#undef USE_DOMOTICZ // Disable Domoticz #undef USE_DOMOTICZ // Disable Domoticz
#undef USE_HOME_ASSISTANT // Disable Home Assistant #undef USE_HOME_ASSISTANT // Disable Home Assistant
#undef USE_GROUPTOPIC_SET // Disable multiple GROUPTOPIC<x>, x=1-4 (+0k1 code)
// -- Optional modules ---------------------------- // -- Optional modules ----------------------------
#undef ROTARY_V1 // Disable support for MI Desk Lamp #undef ROTARY_V1 // Disable support for MI Desk Lamp
@ -376,7 +373,6 @@ extern "C" void resetPins();
//#undef USE_SUNRISE // Disable support for Sunrise and sunset tools //#undef USE_SUNRISE // Disable support for Sunrise and sunset tools
//#undef USE_RULES // Disable support for rules //#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_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 ---------------------------- // -- Optional modules ----------------------------
#undef ROTARY_V1 // Disable support for MI Desk Lamp #undef ROTARY_V1 // Disable support for MI Desk Lamp
@ -478,7 +474,6 @@ extern "C" void resetPins();
#undef USE_DOMOTICZ // Disable Domoticz #undef USE_DOMOTICZ // Disable Domoticz
#undef USE_HOME_ASSISTANT // Disable Home Assistant #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_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_KNX // Disable KNX IP Protocol Support
//#undef USE_WEBSERVER // Disable Webserver //#undef USE_WEBSERVER // Disable Webserver
#undef USE_WEBSEND_RESPONSE // Disable command WebSend response message (+1k code) #undef USE_WEBSEND_RESPONSE // Disable command WebSend response message (+1k code)
@ -600,7 +595,6 @@ extern "C" void resetPins();
#undef USE_DOMOTICZ // Disable Domoticz #undef USE_DOMOTICZ // Disable Domoticz
#undef USE_HOME_ASSISTANT // Disable Home Assistant #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_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_KNX // Disable KNX IP Protocol Support
//#undef USE_WEBSERVER // Disable Webserver //#undef USE_WEBSERVER // Disable Webserver
#undef USE_WEBSEND_RESPONSE // Disable command WebSend response message (+1k code) #undef USE_WEBSEND_RESPONSE // Disable command WebSend response message (+1k code)

View File

@ -20,7 +20,7 @@
#ifndef _TASMOTA_VERSION_H_ #ifndef _TASMOTA_VERSION_H_
#define _TASMOTA_VERSION_H_ #define _TASMOTA_VERSION_H_
const uint32_t VERSION = 0x08020001; const uint32_t VERSION = 0x08020002;
// Lowest compatible version // Lowest compatible version
const uint32_t VERSION_COMPATIBLE = 0x07010006; const uint32_t VERSION_COMPATIBLE = 0x07010006;

View File

@ -2126,17 +2126,13 @@ void HandleInformation(void)
WSContentSend_P(PSTR("}1" D_MQTT_USER "}2%s"), SettingsText(SET_MQTT_USER)); WSContentSend_P(PSTR("}1" D_MQTT_USER "}2%s"), SettingsText(SET_MQTT_USER));
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"), SettingsText(SET_MQTT_TOPIC)); 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)); uint32_t real_index = SET_MQTT_GRP_TOPIC;
#ifdef USE_GROUPTOPIC_SET for (uint32_t i = 0; i < MAX_GROUP_TOPICS; i++) {
WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC " 1}2%s"), GetGroupTopic_P(stopic, "", SET_MQTT_GRP_TOPIC)); if (1 == i) { real_index = SET_MQTT_GRP_TOPIC2 -1; }
for(uint32_t i=0; i < 3; i++) { if (strlen(SettingsText(real_index +i))) {
if (strlen(SettingsText(SET_MQTT_GRP_TOPIC2+i))) { WSContentSend_P(PSTR("}1" D_MQTT_GROUP_TOPIC " %d}2%s"), 1 +i, GetGroupTopic_P(stopic, "", real_index +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_FULL_TOPIC "}2%s"), GetTopic_P(stopic, CMND, mqtt_topic, ""));
WSContentSend_P(PSTR("}1" D_MQTT " " D_FALLBACK_TOPIC "}2%s"), GetFallbackTopic_P(stopic, "")); WSContentSend_P(PSTR("}1" D_MQTT " " D_FALLBACK_TOPIC "}2%s"), GetFallbackTopic_P(stopic, ""));
} else { } else {

View File

@ -510,16 +510,14 @@ void MqttConnected(void)
GetTopic_P(stopic, CMND, mqtt_topic, PSTR("#")); GetTopic_P(stopic, CMND, mqtt_topic, PSTR("#"));
MqttSubscribe(stopic); MqttSubscribe(stopic);
if (strstr_P(SettingsText(SET_MQTT_FULLTOPIC), MQTT_TOKEN_TOPIC) != nullptr) { if (strstr_P(SettingsText(SET_MQTT_FULLTOPIC), MQTT_TOKEN_TOPIC) != nullptr) {
GetGroupTopic_P(stopic, PSTR("#"), SET_MQTT_GRP_TOPIC); // SetOption75 0: %prefix%/nothing/%topic% = cmnd/nothing/<grouptopic>/# or SetOption75 1: cmnd/<grouptopic> uint32_t real_index = SET_MQTT_GRP_TOPIC;
MqttSubscribe(stopic); for (uint32_t i = 0; i < MAX_GROUP_TOPICS; i++) {
#ifdef USE_GROUPTOPIC_SET if (1 == i) { real_index = SET_MQTT_GRP_TOPIC2 -1; }
for(uint32_t i=0; i < 3; i++) { if (strlen(SettingsText(real_index +i))) {
if (strlen(SettingsText(SET_MQTT_GRP_TOPIC2+i))) { GetGroupTopic_P(stopic, PSTR("#"), real_index +i); // SetOption75 0: %prefix%/nothing/%topic% = cmnd/nothing/<grouptopic>/# or SetOption75 1: cmnd/<grouptopic>
GetGroupTopic_P(stopic, PSTR("#"), SET_MQTT_GRP_TOPIC2+i);
MqttSubscribe(stopic); MqttSubscribe(stopic);
} }
} }
#endif
GetFallbackTopic_P(stopic, PSTR("#")); GetFallbackTopic_P(stopic, PSTR("#"));
MqttSubscribe(stopic); MqttSubscribe(stopic);
} }
@ -889,26 +887,52 @@ void CmndPublish(void)
void CmndGroupTopic(void) void CmndGroupTopic(void)
{ {
#if defined(USE_DEVICE_GROUPS ) || defined(USE_GROUPTOPIC_SET) if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_GROUP_TOPICS)) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 4)) { if (XdrvMailbox.data_len > 0) {
uint32_t settings_text_index = (XdrvMailbox.index <= 1 ? SET_MQTT_GRP_TOPIC : SET_MQTT_GRP_TOPIC2 + XdrvMailbox.index - 2); uint32_t settings_text_index = (1 == XdrvMailbox.index) ? SET_MQTT_GRP_TOPIC : SET_MQTT_GRP_TOPIC2 + XdrvMailbox.index - 2;
#endif // USE_DEVICE_GROUPS || USE_GROUPTOPIC_SET MakeValidMqtt(0, XdrvMailbox.data);
if (XdrvMailbox.data_len > 0) { if (!strcmp(XdrvMailbox.data, mqtt_client)) { SetShortcutDefault(); }
MakeValidMqtt(0, XdrvMailbox.data); SettingsUpdateText(settings_text_index, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_GRPTOPIC : XdrvMailbox.data);
if (!strcmp(XdrvMailbox.data, mqtt_client)) { SetShortcutDefault(); }
#if defined(USE_DEVICE_GROUPS ) || defined(USE_GROUPTOPIC_SET) // Eliminate duplicates, have at least one and fill from index 1
SettingsUpdateText(settings_text_index, (SC_DEFAULT == Shortcut()) ? MQTT_GRPTOPIC : XdrvMailbox.data); char stemp[MAX_GROUP_TOPICS][TOPSZ];
#else // USE_DEVICE_GROUPS || USE_GROUPTOPIC_SET uint32_t read_index = 0;
SettingsUpdateText(SET_MQTT_GRP_TOPIC, (SC_DEFAULT == Shortcut()) ? MQTT_GRPTOPIC : XdrvMailbox.data); uint32_t real_index = SET_MQTT_GRP_TOPIC;
#endif // USE_DEVICE_GROUPS || USE_GROUPTOPIC_SET for (uint32_t i = 0; i < MAX_GROUP_TOPICS; i++) {
restart_flag = 2; if (1 == i) { real_index = SET_MQTT_GRP_TOPIC2 -1; }
if (strlen(SettingsText(real_index +i))) {
bool not_equal = true;
for (uint32_t j = 0; j < read_index; j++) {
if (!strcmp(SettingsText(real_index +i), stemp[j])) { // Topics are case-sensitive
not_equal = false;
}
}
if (not_equal) {
strncpy(stemp[read_index], SettingsText(real_index +i), sizeof(stemp[read_index]));
read_index++;
}
}
}
if (0 == read_index) {
SettingsUpdateText(SET_MQTT_GRP_TOPIC, MQTT_GRPTOPIC);
} else {
uint32_t write_index = 0;
uint32_t real_index = SET_MQTT_GRP_TOPIC;
for (uint32_t i = 0; i < MAX_GROUP_TOPICS; i++) {
if (1 == i) { real_index = SET_MQTT_GRP_TOPIC2 -1; }
if (write_index < read_index) {
SettingsUpdateText(real_index +i, stemp[write_index]);
write_index++;
} else {
SettingsUpdateText(real_index +i, "");
}
}
}
restart_flag = 2;
}
ResponseCmndAll(SET_MQTT_GRP_TOPIC, MAX_GROUP_TOPICS);
} }
#if defined(USE_DEVICE_GROUPS ) || defined(USE_GROUPTOPIC_SET)
ResponseCmndChar(SettingsText(settings_text_index));
}
#else // USE_DEVICE_GROUPS || USE_GROUPTOPIC_SET
ResponseCmndChar(SettingsText(SET_MQTT_GRP_TOPIC));
#endif // USE_DEVICE_GROUPS || USE_GROUPTOPIC_SET
} }
void CmndTopic(void) void CmndTopic(void)