mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-07 03:56:57 +03:00
MQTT improvements (#1302)
* Update server_mqtt.cpp * Update server_mqtt.cpp * skipp all MQTT publishing until the next round if an error occures * improve logging * only use group for uid and topic if there is more than one number * . * .
This commit is contained in:
@@ -52,39 +52,30 @@ void sendHomeAssistantDiscoveryTopic(std::string group, std::string field,
|
||||
version = std::string(libfive_git_branch()) + " (" + std::string(libfive_git_revision()) + ")";
|
||||
}
|
||||
|
||||
std::string topic;
|
||||
std::string topicFull;
|
||||
std::string topicT;
|
||||
std::string configTopic;
|
||||
std::string payload;
|
||||
std::string nl = "\n";
|
||||
|
||||
if (group == "") {
|
||||
topic = field;
|
||||
topicT = field;
|
||||
}
|
||||
else {
|
||||
topic = group + "/" + field;
|
||||
topicT = group + "_" + field;
|
||||
}
|
||||
configTopic = field;
|
||||
|
||||
if ((*NUMBERS).size() > 1) { // There is more than one meter, prepend the group so we can differentiate them
|
||||
if (group != "") { // But only if the group is set
|
||||
name = group + " " + name;
|
||||
}
|
||||
}
|
||||
if (group != "" && (*NUMBERS).size() > 1) { // There is more than one meter, prepend the group so we can differentiate them
|
||||
configTopic = group + "_" + field;
|
||||
name = group + " " + name;
|
||||
}
|
||||
|
||||
if (field == "problem") { // Special binary sensor which is based on error topic
|
||||
topicFull = "homeassistant/binary_sensor/" + maintopic + "/" + topicT + "/config";
|
||||
topicFull = "homeassistant/binary_sensor/" + maintopic + "/" + configTopic + "/config";
|
||||
}
|
||||
else {
|
||||
topicFull = "homeassistant/sensor/" + maintopic + "/" + topicT + "/config";
|
||||
topicFull = "homeassistant/sensor/" + maintopic + "/" + configTopic + "/config";
|
||||
}
|
||||
|
||||
/* See https://www.home-assistant.io/docs/mqtt/discovery/ */
|
||||
payload = "{" + nl +
|
||||
"\"~\": \"" + maintopic + "\"," + nl +
|
||||
"\"unique_id\": \"" + maintopic + "-" + topicT + "\"," + nl +
|
||||
"\"object_id\": \"" + maintopic + "_" + topicT + "\"," + nl + // This used to generate the Entity ID
|
||||
"\"unique_id\": \"" + maintopic + "-" + configTopic + "\"," + nl +
|
||||
"\"object_id\": \"" + maintopic + "_" + configTopic + "\"," + nl + // This used to generate the Entity ID
|
||||
"\"name\": \"" + name + "\"," + nl +
|
||||
"\"icon\": \"mdi:" + icon + "\"," + nl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user