Skip to content

Commit

Permalink
Merge pull request #5240 from tonhuisman/bugfix/MQTT-dont-subscribe-t…
Browse files Browse the repository at this point in the history
…o-empty-topics

[MQTT] Don't subscribe to empty topics
  • Loading branch information
TD-er authored Feb 3, 2025
2 parents 6003a09 + 042ed71 commit a952e41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/_P037_MQTTImport.ino
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,10 @@ bool MQTTSubscribe_037(struct EventStruct *event)
for (uint8_t x = 0; x < VARS_PER_TASK; x++) {
String subscribeTo = P037_data->getFullMQTTTopic(x);

if (!subscribeTo.isEmpty()) {
parseSystemVariables(subscribeTo, false);
parseSystemVariables(subscribeTo, false);
subscribeTo.trim();

if (!subscribeTo.isEmpty()) {
if (MQTTclient.subscribe(subscribeTo.c_str())) {
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
addLog(LOG_LEVEL_INFO, strformat(F("IMPT : [%s#%s] subscribed to %s"),
Expand Down
12 changes: 8 additions & 4 deletions src/src/ESPEasyCore/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,15 @@ bool MQTTConnect(controllerIndex_t controller_idx)
String subscribeTo = ControllerSettings->Subscribe;

parseSystemVariables(subscribeTo, false);
MQTTclient.subscribe(subscribeTo.c_str());
subscribeTo.trim();

if (loglevelActiveFor(LOG_LEVEL_INFO))
{
addLogMove(LOG_LEVEL_INFO, concat(F("Subscribed to: "), subscribeTo));
if (!subscribeTo.isEmpty()) {
MQTTclient.subscribe(subscribeTo.c_str());

if (loglevelActiveFor(LOG_LEVEL_INFO))
{
addLogMove(LOG_LEVEL_INFO, concat(F("Subscribed to: "), subscribeTo));
}
}

updateMQTTclient_connected();
Expand Down

0 comments on commit a952e41

Please sign in to comment.