[SYS] Avoid nvs errors (#1588)
Avoid nvs errors when trying to load or erase non-existent nvs preferences.
This commit is contained in:
1 parent
9b6133ff03
commit
e560bd7904
3 files changed
+46
-37
No files matched your search
@@ -176,8 +176,10 @@ void MQTTtoSSD1306(char* topicOri, JsonObject& SSD1306data) { // json object dec
|
||||
} else if (SSD1306data.containsKey("erase") && SSD1306data["erase"]) {
|
||||
// Erase config from NVS (non-volatile storage)
|
||||
preferences.begin(Gateway_Short_Name, false);
|
||||
success = preferences.remove("SSD1306Config");
|
||||
preferences.end();
|
||||
if (preferences.isKey("SSD1306Config")) {
|
||||
success = preferences.remove("SSD1306Config");
|
||||
preferences.end();
|
||||
}
|
||||
if (success) {
|
||||
Log.notice(F("SSD1306 config erased" CR));
|
||||
}
|
||||
@@ -222,8 +224,7 @@ void SSD1306Config_init() {
|
||||
bool SSD1306Config_load() {
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
preferences.begin(Gateway_Short_Name, true);
|
||||
bool exists = preferences.isKey("SSD1306Config");
|
||||
if (exists) {
|
||||
if (preferences.isKey("SSD1306Config")) {
|
||||
auto error = deserializeJson(jsonBuffer, preferences.getString("SSD1306Config", "{}"));
|
||||
preferences.end();
|
||||
if (error) {
|
||||
|
||||
Reference in new issue
Block a user