Skip to content

Commit

Permalink
refactor(NVS): refactor setString
Browse files Browse the repository at this point in the history
  • Loading branch information
becem-gharbi committed Jun 21, 2024
1 parent 1de636f commit 1f789a4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/NVS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ namespace ESPAdmin
*/
void NVS::setString(const char *key, const char *value) const
{
esp_err_t err = nvs_set_str(_handler, key, value == nullptr ? "" : value);
const char *valueToSet = (value == nullptr) ? "" : value;

nvs_commit(_handler);
esp_err_t err = nvs_set_str(_handler, key, valueToSet);
if (err != ESP_OK)
{
_logger.warn("failed to write value of %s", key);
return;
}

err = nvs_commit(_handler);
if (err != ESP_OK)
{
_logger.warn("failed to write string %s", key);
_logger.warn("failed to commit value of %s", key);
}
}

Expand Down

0 comments on commit 1f789a4

Please sign in to comment.