Description
Board
esp32 dev module
Device Description
NA
Hardware Configuration
NA
Version
v2.0.16
IDE Name
VSCode
Operating System
Windows 10
Flash frequency
80 Mhz setCpuFrequencyMhz(80);
PSRAM enabled
yes
Upload speed
115200
Description
Issue: preferences.putString() occasionally hangs
Hi, I'm experiencing an intermittent issue with Preferences.putString() on ESP32.
In my code, I'm updating several configuration values using Preferences. The preferences.begin() call always works fine — no issues there. But sometimes, the execution gets stuck at the beginning of the saving process, right after printing "Let Save new Configuration ...". It seems like the first putString() call is hanging or blocking, and the device doesn't proceed to the next lines (e.g., I don't see "T1", "T2", etc.).
Here's the relevant code:
Sometimes everything works perfectly and I see all the T1, T2, ... T9 messages in the Serial Monitor. Other times, it hangs after "Let Save new Configuration ...", and nothing further happens.
Any ideas on what could be causing putString() to get stuck like this? Could this be a flash memory or corruption issue?
Thanks in advance for any help or suggestions!
Sketch
void updatePreferences(JsonDocument& doc) {
if (preferences.begin("ServerConfi", false)) {
delay(500);
const char *i_protocol = doc["protocol"];
const char *i_domainename = doc["domainename"];
const char *i_port = doc["port"];
String i_path = doc["path"];
const int32_t i_aquifreq = doc["aquifreq"];
const int32_t i_sendfreq = doc["sendfreq"];
const int32_t i_ping = doc["ping"];
const char *i_staticimei = doc["staticimei"];
const char *i_devicename = doc["devicename"];
Serial.println("Let Save new Configuration ...");
delay(1000);
preferences.putString("protocol", i_protocol); delay(10); Serial.println("T1");
preferences.putString("domainename", i_domainename); delay(10); Serial.println("T2");
preferences.putString("port", i_port); delay(10); Serial.println("T3");
preferences.putString("path", i_path); delay(10); Serial.println("T4");
preferences.putInt("aquifreq", i_aquifreq); delay(10); Serial.println("T5");
preferences.putInt("sendfreq", i_sendfreq); delay(10); Serial.println("T6");
preferences.putInt("ping", i_ping); delay(10); Serial.println("T7");
preferences.putString("staticimei", i_staticimei); delay(10); Serial.println("T8");
preferences.putString("devicename", i_devicename); delay(10); Serial.println("T9");
Serial.println("New Configuration Saved ...");
preferences.end();
Serial.println("Update Setup Done.\n\n");
} else {
Serial.println("Failed to open preferences.\n\n");
}
}
Debug Message
Let Save new Configuration ...
Other Steps to Reproduce
sometimes passes sometimes hangs ...
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.