mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-06 19:46:54 +03:00
Improve MQTT (#2091)
* moved functions * use hostname as default MQTT maintopic if parameter is not set * use hostname as default MQTT client ID * Only send Homassistant Discovery and Static Topics on the first connect. Retry in next round if any topic failed * . * add missing return code usage * send maintopic/connection on every round like the system topics --------- Co-authored-by: CaCO3 <caco@ruinelli.ch>
This commit is contained in:
@@ -963,3 +963,34 @@ std::string UrlDecode(const std::string& value)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith) {
|
||||
return replaceString(s, toReplace, replaceWith, true);
|
||||
}
|
||||
|
||||
|
||||
bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith, bool logIt) {
|
||||
std::size_t pos = s.find(toReplace);
|
||||
|
||||
if (pos == std::string::npos) { // Not found
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string old = s;
|
||||
s.replace(pos, toReplace.length(), replaceWith);
|
||||
if (logIt) {
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Migrated Configfile line '" + old + "' to '" + s + "'");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool isInString(std::string& s, std::string const& toFind) {
|
||||
std::size_t pos = s.find(toFind);
|
||||
|
||||
if (pos == std::string::npos) { // Not found
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user