fixbug: getting empty value

This commit is contained in:
Terrence
2025-01-19 03:53:48 +08:00
parent ea0333c0ce
commit e2c5578ede
3 changed files with 1 additions and 6 deletions

View File

@@ -39,7 +39,6 @@ bool MqttProtocol::StartMqttClient() {
client_id_ = settings.GetString("client_id"); client_id_ = settings.GetString("client_id");
username_ = settings.GetString("username"); username_ = settings.GetString("username");
password_ = settings.GetString("password"); password_ = settings.GetString("password");
subscribe_topic_ = settings.GetString("subscribe_topic");
publish_topic_ = settings.GetString("publish_topic"); publish_topic_ = settings.GetString("publish_topic");
if (endpoint_.empty()) { if (endpoint_.empty()) {
@@ -92,9 +91,6 @@ bool MqttProtocol::StartMqttClient() {
} }
ESP_LOGI(TAG, "Connected to endpoint"); ESP_LOGI(TAG, "Connected to endpoint");
if (!subscribe_topic_.empty()) {
mqtt_->Subscribe(subscribe_topic_, 2);
}
return true; return true;
} }

View File

@@ -37,7 +37,6 @@ private:
std::string client_id_; std::string client_id_;
std::string username_; std::string username_;
std::string password_; std::string password_;
std::string subscribe_topic_;
std::string publish_topic_; std::string publish_topic_;
std::mutex channel_mutex_; std::mutex channel_mutex_;

View File

@@ -31,7 +31,7 @@ std::string Settings::GetString(const std::string& key, const std::string& defau
std::string value; std::string value;
value.resize(length); value.resize(length);
ESP_ERROR_CHECK(nvs_get_str(nvs_handle_, key.c_str(), value.data(), &length)); ESP_ERROR_CHECK(nvs_get_str(nvs_handle_, key.c_str(), value.data(), &length));
while (value.back() == '\0') { while (!value.empty() && value.back() == '\0') {
value.pop_back(); value.pop_back();
} }
return value; return value;