From 4b7b47c30c305a3de7ba839cae9c2ef6aeb02dd1 Mon Sep 17 00:00:00 2001 From: Florian Date: Sat, 20 May 2023 15:18:10 -0500 Subject: [PATCH] [SYS] Catch preferences operation returns (#1646) in the logs --- main/ZactuatorONOFF.ino | 8 ++++---- main/ZdisplaySSD1306.ino | 4 ++-- main/ZgatewayBT.ino | 11 ++++++----- main/main.ino | 4 +++- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/main/ZactuatorONOFF.ino b/main/ZactuatorONOFF.ino index c92bd7f..5d1e544 100644 --- a/main/ZactuatorONOFF.ino +++ b/main/ZactuatorONOFF.ino @@ -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); } } diff --git a/main/ZdisplaySSD1306.ino b/main/ZdisplaySSD1306.ino index d45a176..a019edc 100644 --- a/main/ZdisplaySSD1306.ino +++ b/main/ZdisplaySSD1306.ino @@ -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() { diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 394e7f9..4a070f1 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -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(); diff --git a/main/main.ino b/main/main.ino index 5660abe..3af21d4 100644 --- a/main/main.ino +++ b/main/main.ino @@ -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();