refactor: comment out logging for key-value storage and adjust string allocation in NVS handler

This commit is contained in:
GW_MC
2026-01-24 18:25:00 +08:00
parent d0a1e8c80f
commit 68f2c821fa

View File

@@ -47,7 +47,7 @@ void NVSStorageHandler::put(const std::string& key, const std::string& value) {
ESP_LOGE(TAG, "Error (%s) setting key-value pair in NVS!", esp_err_to_name(err)); ESP_LOGE(TAG, "Error (%s) setting key-value pair in NVS!", esp_err_to_name(err));
} else { } else {
nvs_commit(this->nvsHandle); nvs_commit(this->nvsHandle);
ESP_LOGI(TAG, "Key-value pair (%s, %s) stored in NVS.", key.c_str(), value.c_str()); // ESP_LOGI(TAG, "Key-value pair (%s, %s) stored in NVS.", key.c_str(), value.c_str());
} }
} }
@@ -67,8 +67,9 @@ std::string NVSStorageHandler::get(const std::string& key) const {
return ""; return "";
} }
std::string value; // Allocate string buffer with correct size (includes null terminator)
err = nvs_get_str(this->nvsHandle, key.c_str(), value.data(), &required_size); std::string value(required_size - 1, '\0');
err = nvs_get_str(this->nvsHandle, key.c_str(), &value[0], &required_size);
if (err != ESP_OK) { if (err != ESP_OK) {
ESP_LOGE(TAG, "Error (%s) getting value for key %s from NVS!", esp_err_to_name(err), key.c_str()); ESP_LOGE(TAG, "Error (%s) getting value for key %s from NVS!", esp_err_to_name(err), key.c_str());
return ""; return "";