diff --git a/src/Power.cpp b/src/Power.cpp index 6b5bebe4d..4bce83afb 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -350,12 +350,12 @@ void Power::readPowerStatus() char mac[18]; sprintf(mac, "!%02x%02x%02x%02x", dmac[2], dmac[3], dmac[4], dmac[5]); auto newHeap = ESP.getFreeHeap(); - std::string heapTopic = "msh/2/heap/" + std::string(mac); + std::string heapTopic = (*moduleConfig.mqtt.root ? moduleConfig.mqtt.root : "msh") + "/2/heap/" + std::string(mac); std::string heapString = std::to_string(newHeap); mqtt->pubSub.publish(heapTopic.c_str(), heapString.c_str(), false); // auto fragHeap = ESP.getHeapFragmentation(); auto wifiRSSI = WiFi.RSSI(); - heapTopic = "msh/2/wifi/" + std::string(mac); + heapTopic = (*moduleConfig.mqtt.root ? moduleConfig.mqtt.root : "msh") + "/2/wifi/" + std::string(mac); std::string wifiString = std::to_string(wifiRSSI); mqtt->pubSub.publish(heapTopic.c_str(), wifiString.c_str(), false); } diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index c0758019a..bd1a85641 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -19,10 +19,6 @@ const int reconnectMax = 5; MQTT *mqtt; -std::string statusTopic = "/2/stat/"; -std::string cryptTopic = "/2/c/"; // msh/2/c/CHANNELID/NODEID -std::string jsonTopic = "/2/json/"; // msh/2/json/CHANNELID/NODEID - static MemoryDynamic staticMqttPool; Allocator &mqttPool = staticMqttPool; @@ -164,7 +160,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_ assert(!mqtt); mqtt = this; - if (moduleConfig.mqtt.root) { + if (*moduleConfig.mqtt.root) { statusTopic = moduleConfig.mqtt.root + statusTopic; cryptTopic = moduleConfig.mqtt.root + cryptTopic; jsonTopic = moduleConfig.mqtt.root + jsonTopic; diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index 3065cc08e..1e626c3e0 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -69,6 +69,9 @@ class MQTT : private concurrency::OSThread virtual int32_t runOnce() override; private: + std::string statusTopic = "/2/stat/"; + std::string cryptTopic = "/2/c/"; // msh/2/c/CHANNELID/NODEID + std::string jsonTopic = "/2/json/"; // msh/2/json/CHANNELID/NODEID /** return true if we have a channel that wants uplink/downlink */ bool wantsLink() const;