From d7ea186c1fb252c932bfb7c324882a759c7740d4 Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Mon, 28 Mar 2016 18:29:38 +0200 Subject: [PATCH] Less aggressive topic subscribing, in order to try to solve #46 --- src/Homie/Boot/BootNormal.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Homie/Boot/BootNormal.cpp b/src/Homie/Boot/BootNormal.cpp index fdb717c7..fa1939ff 100644 --- a/src/Homie/Boot/BootNormal.cpp +++ b/src/Homie/Boot/BootNormal.cpp @@ -122,15 +122,31 @@ void BootNormal::_mqttSetup() { strcpy(MqttClient.getTopicBuffer(), Config.get().mqtt.baseTopic); strcat(MqttClient.getTopicBuffer(), Helpers.getDeviceId()); - strcat_P(MqttClient.getTopicBuffer(), PSTR("/#")); - Logger.logln(F("Subscribing to topics")); + strcat_P(MqttClient.getTopicBuffer(), PSTR("/+/+/set")); + Logger.logln(F("Subscribing to /set topics")); MqttClient.subscribe(1); + + strcpy(MqttClient.getTopicBuffer(), Config.get().mqtt.baseTopic); + strcat(MqttClient.getTopicBuffer(), Helpers.getDeviceId()); + strcat_P(MqttClient.getTopicBuffer(), PSTR("/$reset")); + Logger.logln(F("Subscribing to $reset topic")); + MqttClient.subscribe(1); + + if (Config.get().ota.enabled) { + strcpy(MqttClient.getTopicBuffer(), Config.get().mqtt.baseTopic); + strcat(MqttClient.getTopicBuffer(), Helpers.getDeviceId()); + strcat_P(MqttClient.getTopicBuffer(), PSTR("/$ota")); + Logger.logln(F("Subscribing to $ota topic")); + MqttClient.subscribe(1); + } } void BootNormal::_mqttCallback(char* topic, char* payload) { String message = String(payload); String unified = String(topic); unified.remove(0, strlen(Config.get().mqtt.baseTopic) + strlen(Helpers.getDeviceId()) + 1); // Remove devices/${id}/ --- +1 for / + + // Device properties if (Config.get().ota.enabled && unified == "$ota") { if (message != this->_interface->firmware.version) { Logger.log(F("✴ OTA available (version ")); @@ -150,12 +166,7 @@ void BootNormal::_mqttCallback(char* topic, char* payload) { return; } - if (unified.substring(unified.length() - 4) != "/set") { - return; // Invalid message - } - - // Implicit node property - + // Implicit node properties unified.remove(unified.length() - 4, 4); // Remove /set int separator; for (int i = 0; i < unified.length(); i++) {