Go Down

Topic: SPIFFS how to overwrite a value inside a file (Read 217 times) previous topic - next topic

crave_

Hi guys i'm aksing for your help because i'm little stuked with this issue:

I'm writing sensors value to a file .csv using SPIFFS memory and a "flag"  read == 1 is to read and if read == 0, write the file:


if (read == 1) {
      f = SPIFFS.open(file,  "r");
    } else {
      f = SPIFFS.open(file,  "a");
    }


but I would like to have only ,lets say, 100 value written inside the file and then restart to write the new value from beginning of the file (without delating the file.csv), rewriting line by line each cycle and keeping the "old" value:

when the 100 line is reached, then the new value is stored in line 1 then line 2 , 3 ecc


in this case how i can proceed?



Thee_Captain

Do you need it done in this exact manor?

It might be easier to initialize your file to have 100 entries (this way you don't need to count ever) and then every time you want to write an entry you delete the first line in the file, then append your line to the end.

This would keep the oldest values first and the newest values last.
Throw a little karma my way. What goes around comes around.

Go Up