[SYS] Catch preferences operation returns (#1646)

in the logs
This commit is contained in:
Florian authored and GitHub committed 2023-05-20 15:18:10 -05:00
1 parent aa63571537
commit 4b7b47c30c
4 files changed
+15 -12

No files matched your search

+4 -4
View File
@@ -47,9 +47,9 @@ void ONOFFConfig_fromJson(JsonObject& ONOFFdata) {
// Erase config from NVS (non-volatile storage)
preferences.begin(Gateway_Short_Name, false);
if (preferences.isKey("ONOFFConfig")) {
preferences.remove("ONOFFConfig");
int result = preferences.remove("ONOFFConfig");
Log.notice(F("ONOFF config erase result: %d" CR), result);
preferences.end();
Log.notice(F("ONOFF config erased" CR));
return; // Erase prevails on save, so skipping save
} else {
Log.notice(F("ONOFF config not found" CR));
@@ -65,9 +65,9 @@ void ONOFFConfig_fromJson(JsonObject& ONOFFdata) {
String conf = "";
serializeJson(jsonBuffer, conf);
preferences.begin(Gateway_Short_Name, false);
preferences.putString("ONOFFConfig", conf);
int result = preferences.putString("ONOFFConfig", conf);
preferences.end();
Log.notice(F("ONOFF config saved" CR));
Log.notice(F("ONOFF Config_save: %s, result: %d" CR), conf.c_str(), result);
}
}
+2 -2
View File
@@ -207,9 +207,9 @@ void SSD1306Config_save() {
String conf = "";
serializeJson(jsonBuffer, conf);
preferences.begin(Gateway_Short_Name, false);
preferences.putString("SSD1306Config", conf);
int result = preferences.putString("SSD1306Config", conf);
preferences.end();
Log.notice(F("SSD1306 config saved" CR));
Log.notice(F("SSD1306 Config_save: %s, result: %d" CR), conf.c_str(), result);
}
void SSD1306Config_init() {
+6 -5
View File
@@ -252,9 +252,9 @@ void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) {
// Erase config from NVS (non-volatile storage)
preferences.begin(Gateway_Short_Name, false);
if (preferences.isKey("BTConfig")) {
preferences.remove("BTConfig");
int result = preferences.remove("BTConfig");
Log.notice(F("BT config erase result: %d" CR), result);
preferences.end();
Log.notice(F("BT config erased" CR));
return; // Erase prevails on save, so skipping save
} else {
preferences.end();
@@ -289,9 +289,9 @@ void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) {
String conf = "";
serializeJson(jsonBuffer, conf);
preferences.begin(Gateway_Short_Name, false);
preferences.putString("BTConfig", conf);
int result = preferences.putString("BTConfig", conf);
preferences.end();
Log.notice(F("BT config saved" CR));
Log.notice(F("BT config save: %s, result: %d" CR), conf.c_str(), result);
}
}
@@ -954,7 +954,8 @@ void changelowpowermode(int newLowPowerMode) {
# endif
lowpowermode = newLowPowerMode;
preferences.begin(Gateway_Short_Name, false);
preferences.putUInt("lowpowermode", lowpowermode);
int result = preferences.putUInt("lowpowermode", lowpowermode);
Log.notice(F("BT LPM config save result: %d" CR), result);
preferences.end();
// Publish the states to update the controller switch status
stateMeasures();
+3 -1
View File
@@ -773,8 +773,10 @@ void setup() {
preferences.begin(Gateway_Short_Name, false);
if (preferences.isKey("lowpowermode")) {
lowpowermode = preferences.getUInt("lowpowermode", DEFAULT_LOW_POWER_MODE);
preferences.end();
} else {
Log.notice(F("No lowpowermode config to load" CR));
}
preferences.end();
# endif
# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH)
setupM5();