Re: SPIFFS file read and write example
Posted:
Tue Jan 03, 2017 2:26 pm
by GengusKahn
Hi there, if you look through the sketch in the attached Github link this will demonstrate reading large files, use '\r' as the terminator for a line at a time.....
There are more detailed uses of these routines in the repo.....
Hope this helps....
https://github.com/EnvironmentMonitor/ESP8266-DHT11-WiFi_Sensor/blob/master/ThingSpeak_Email_log.ino
Re: SPIFFS file read and write example
Posted:
Wed May 03, 2017 4:48 pm
by Pet Ratty
Can anyone explain what I am doing wrong, I open a file in append mode every 10 minutes, add to it and close it. All works good, but if I reset the esp8266 or update firmware the file is lost. (the file isn't lost it's just empty)
File f = SPIFFS.open("/silver.txt", "a");
f.printf("%d/%d/%d %d:%d:%d - %s\n",days,months,years,hours,minutes,seconds,buf);
f.close();
Re: SPIFFS file read and write example
Posted:
Sat May 06, 2017 2:06 am
by ESP4eva
I am having trouble reading a plain text SPIFFS file. The file is 100 lines with each line being 1kb in size. It reads the first 30 lines within a couple of seconds but then each subsequent line can take 5 or more seconds.
Below is a sample sketch. Any idea what the problem is?
Code: Select all/* SearchSPIFFS.ino 6 May 2017
SPIFFS plain text file has 100 lines, each line approx 1kb
After reading 30 lines (30kb) in less than 2 seconds it takes several seconds PER line
*/
#include "FS.h"
String line;
unsigned int lineNumber;
unsigned int line2Find = 32;
File MyFile = SPIFFS.open("SomeData.txt", "r");
void test(){
while(MyFile.available()) { // we could open the file, so loop through it to find the record we require
lineNumber++;
Serial.println(lineNumber); // show line number of SPIFFS file
line = MyFile.readStringUntil('\n'); // Read line by line from the file
if(lineNumber == line2Find){
Serial.println(F("Found record"));
break; // exit while loop once record is found
}
}
}
void setup() {
Serial.begin(115200);
Serial.println(F("\nStarted"));
test(); // find line 32 of plain text SPIFFS file
}
void loop() {
yield();
}
Re: SPIFFS file read and write example
Posted:
Sun May 07, 2017 7:20 pm
by gbafamily1
* There is no call to SPIFFS.begin().
* The global variables should be moved into the test function.
* Initialize lineNumber to 0.
I do not see why it should be slow after 30 records. After fixing the test code does it really slow down?