ESP32 ArduinoNVS or Preferences - unable to store Strings of 80 bytes.

Hello everyone. Having not found the solution to store 80-byte files on SPIFFS or with LittleFS, I tried initially in vain with the ArduinoNVS library and then with Preferences. In both cases, it seems impossible to store more than 8 bytes: the recording process goes well, but upon rereading, the file is empty. The recording routine:
C++
Preferences pref;

//*********NVS recording of a complete program (10 manipulations of 8 bytes each) 6x => Px x=0 to 9
case '6': {
String tempo = "";
char nFic[3];
nprog = ci(com[1]); //program number ASCII to Numeric Conversion
if (!(nprog >= 0 && nprog <= 9)) afficErreurs(prg);
else {
nFic[0] = 'P'; nFic[1] = com[1]; nFic[2] = '\0'; //file number Px with x=0 to 9
for (int i = 0; i < 80; i++) {
tempo += pg[nprog][i]; //char pg[10][80]; 10 programs of 8*10 manipulations
}
int size = pref.putString(nFic, tempo); //in file Px, we save the entire program x
lcd.clear(); lcd.print(size); delay(2000); lcd.clear();
}
}
break;
C++
Preferences pref;

//*********NVS recording of a complete program (10 manipulations of 8 bytes each) 6x => Px x=0 to 9
case '6': {
String tempo = "";
char nFic[3];
nprog = ci(com[1]); //program number ASCII to Numeric Conversion
if (!(nprog >= 0 && nprog <= 9)) afficErreurs(prg);
else {
nFic[0] = 'P'; nFic[1] = com[1]; nFic[2] = '\0'; //file number Px with x=0 to 9
for (int i = 0; i < 80; i++) {
tempo += pg[nprog][i]; //char pg[10][80]; 10 programs of 8*10 manipulations
}
int size = pref.putString(nFic, tempo); //in file Px, we save the entire program x
lcd.clear(); lcd.print(size); delay(2000); lcd.clear();
}
}
break;
The result correctly indicates the number of bytes saved. However, upon rereading, the recording is empty.
C++
//****display programmed memory x *****
case '5': {
String tempo = "";
char prog[3];
prog[0] = 'P'; prog[1] = com[1]; prog[2] = '\0';
tempo = pref.getString(prog, "");
for (i = 0; i < 10; i++) {
lcd.clear(); lcd.print(String(prog) + " " + String(i));
lcd.setCursor(0, 1); lcd.print(tempo.substring(i * 8, i * 8 + 8)); //display in sets of 8 bytes
delay('s', 2);
}
}
break;
C++
//****display programmed memory x *****
case '5': {
String tempo = "";
char prog[3];
prog[0] = 'P'; prog[1] = com[1]; prog[2] = '\0';
tempo = pref.getString(prog, "");
for (i = 0; i < 10; i++) {
lcd.clear(); lcd.print(String(prog) + " " + String(i));
lcd.setCursor(0, 1); lcd.print(tempo.substring(i * 8, i * 8 + 8)); //display in sets of 8 bytes
delay('s', 2);
}
}
break;
If anyone has an idea for this problem.
1 Reply
Marvee Amasi
Marvee Amasi11mo ago
Well the code seems good . It looks like storing large files using Preferences is causing issues. Think of Preferences like a storage box that's good for small things, not big files. To solve this, try using a different storage method like SPIFFS or LittleFS, which are like bigger storage boxes that can handle larger files. If you still want to use Preferences, imagine breaking the big file into smaller pieces and storing them separately. When you need the whole file, grab these pieces and put them together. Remember, always check the instructions for the storage method you're using to make sure it can handle the size and type of data you're dealing with.
Want results from more Discord servers?
Add your server