diff --git a/include/Global.h b/include/Global.h index d4a79336..0df14fe3 100644 --- a/include/Global.h +++ b/include/Global.h @@ -124,6 +124,7 @@ extern int mqttPort; extern String mqttPrefix; extern String mqttUser; extern String mqttPass; +extern String nameId; extern unsigned long mqttUptime; extern unsigned long flashWriteNumber; diff --git a/src/Global.cpp b/src/Global.cpp index afbb6e0f..0e00c731 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -62,6 +62,7 @@ int mqttPort = 0; String mqttPrefix = ""; String mqttUser = ""; String mqttPass = ""; +String nameId = ""; unsigned long mqttUptime = 0; unsigned long flashWriteNumber = 0; diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index a2b31747..b3a26a56 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -62,7 +62,7 @@ boolean mqttConnect() { if (mqttUser != "" && mqttPass != "") { if (HOMEdDiscovery) { - connected = mqtt.connect(chipId.c_str(), mqttUser.c_str(), mqttPass.c_str(), (HOMEdDiscovery->HOMEdTopic + "/device/custom/" + chipId).c_str(), 1, true, "{\"status\":\"offline\"}"); + connected = mqtt.connect(chipId.c_str(), mqttUser.c_str(), mqttPass.c_str(), (HOMEdDiscovery->HOMEdTopic + "/device/custom/" + nameId).c_str(), 1, true, "{\"status\":\"offline\"}"); } else { @@ -72,7 +72,7 @@ boolean mqttConnect() { } else if (mqttUser == "" && mqttPass == "") { if (HOMEdDiscovery) { - connected = mqtt.connect(chipId.c_str(), (HOMEdDiscovery->HOMEdTopic + "/device/custom/" + chipId).c_str(), 1, true, "{\"status\":\"offline\"}"); + connected = mqtt.connect(chipId.c_str(), (HOMEdDiscovery->HOMEdTopic + "/device/custom/" + nameId).c_str(), 1, true, "{\"status\":\"offline\"}"); } else { @@ -120,6 +120,7 @@ void getMqttData() { mqttUser = jsonReadStr(settingsFlashJson, F("mqttUser")); mqttPass = jsonReadStr(settingsFlashJson, F("mqttPass")); mqttPrefix = jsonReadStr(settingsFlashJson, F("mqttPrefix")); + nameId = jsonReadStr(settingsFlashJson, F("name")); mqttRootDevice = mqttPrefix + "/" + chipId; } diff --git a/src/modules/virtual/DiscoveryHomeD/DiscoveryHomeD.cpp b/src/modules/virtual/DiscoveryHomeD/DiscoveryHomeD.cpp index a7c1703a..0fa8be96 100644 --- a/src/modules/virtual/DiscoveryHomeD/DiscoveryHomeD.cpp +++ b/src/modules/virtual/DiscoveryHomeD/DiscoveryHomeD.cpp @@ -90,8 +90,8 @@ public: if (mqttIsConnect() && !sendOk && topicOk) { sendOk = true; - publishRetain(_topic + "/device/custom/" + chipId, "{\"status\":\"online\"}"); - String HOMEdsubscribeTopic = _topic + "/td/custom/" + chipId; + publishRetain(_topic + "/device/custom/" + nameId, "{\"status\":\"online\"}"); + String HOMEdsubscribeTopic = _topic + "/td/custom/" + nameId; // mqtt.subscribe(HOMEdsubscribeTopic.c_str()); mqttSubscribeExternal(HOMEdsubscribeTopic); } @@ -103,7 +103,7 @@ public: void publishStatusHOMEd(const String &topic, const String &data) { - String path_h = HOMEdTopic + "/fd/custom/" + chipId; + String path_h = HOMEdTopic + "/fd/custom/" + nameId; String json_h = "{}"; if (topic != "onStart") { @@ -133,8 +133,8 @@ public: { deleteFromHOMEd(); getlayoutHOMEd(); - publishRetain(HOMEdTopic + "/device/custom/" + chipId, "{\"status\":\"online\"}"); - String HOMEdsubscribeTopic = HOMEdTopic + "/td/custom/" + chipId; + publishRetain(HOMEdTopic + "/device/custom/" + nameId, "{\"status\":\"online\"}"); + String HOMEdsubscribeTopic = HOMEdTopic + "/td/custom/" + nameId; mqtt.subscribe(HOMEdsubscribeTopic.c_str()); } } @@ -164,7 +164,7 @@ public: JsonArray arr = doc.as(); String HOMEdJSON = ""; HOMEdJSON = "{\"action\":\"updateDevice\","; - HOMEdJSON = HOMEdJSON + "\"device\":\"" + chipId + "\","; + HOMEdJSON = HOMEdJSON + "\"device\":\"" + nameId + "\","; HOMEdJSON = HOMEdJSON + "\"data\":{"; HOMEdJSON = HOMEdJSON + "\"active\": true,"; HOMEdJSON = HOMEdJSON + "\"cloud\": false,"; @@ -178,7 +178,7 @@ public: { String name = value["descr"]; String device = selectToMarkerLast(value["topic"].as(), "/"); - String id = chipId + "-" + device; + //String id = chipId + "-" + device; String expose = value["name"]; if (value["name"].as() == "toggle") { @@ -219,7 +219,7 @@ public: file.close(); - publishRetain(HOMEdTopic + "/device/custom/" + chipId, "{\"status\":\"online\"}"); + publishRetain(HOMEdTopic + "/device/custom/" + nameId, "{\"status\":\"online\"}"); for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { @@ -243,7 +243,7 @@ public: String HOMEdjson = ""; HOMEdjson = "{\"action\":\"removeDevice\","; HOMEdjson = HOMEdjson + "\"device\":\""; - HOMEdjson = HOMEdjson + chipId; + HOMEdjson = HOMEdjson + nameId; HOMEdjson = HOMEdjson + "\"}"; String topic = (HOMEdTopic + "/command/custom").c_str(); if (!publish(topic, HOMEdjson))