Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By GengusKahn
#60329 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
User avatar
By Pet Ratty
#65523 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();
User avatar
By ESP4eva
#65639 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();
}
User avatar
By gbafamily1
#65684 * 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?