-->
Page 1 of 1

SPIFFS very slow after 1.5MB read.

PostPosted: Sun Nov 19, 2017 4:58 am
by Barnabybear
Hi, can offer some insight into why SPIFFS reads become very slow after 1.5MB please.
Arduino IDE 1.6.20
ESP8266 2.3.0
4M(3M SPIFFS)
Wemos mini D1

I load into SPIFFS a 2.5MB file containing RGB lighting data (single bytes), read the 28 bit header file which give me the four parameters I need to process the data. I then run the following loop.
Data_Offset = 28
Step_Length = 6000
Number_Channels = 512
Frame_Time = 50

Code: Select allvoid loop() {
  FSEQ_Data = SPIFFS.open("/tree-4min.fseq", "r");  //open file in read only mode.
  FSEQ_Data.seek(Data_Offset, SeekSet); // set read pointer to correct byte.
  for  (nn = 0; nn < Step_Lenght ; nn++) {  // loop number of steps in sequence (fps*time).
  for  (n = 0; n < Number_Channels ; n++) {  // loop number of channels times.

    byte Data = FSEQ_Data.read();  // read one byte of data from .FSEQ file.
    Serial.print(Data, HEX);  // print byte as hex value.
    Serial.print(" ");
  }
    delay(Frame_Time);  // delay (1 sec / fps) - not final code.
  }
}


If I comment out the prints this runs as expected until the 3029 read at which point the reads take about 10 seconds each.
I changed Number_Channels = 512 to 256 and it completes the loop and starts again.
I changed Data_Offset = 28 to 5120 and the reads slow ten loops earlier (3019) so it’s something to do with the quantity of data or a storage position.

28 + (512 * 3029) = 1,550,876 bytes from the start of the file.

Thanks Phil.

Full code:
Code: Select all// posted for progress infomation - this is not finished code and will only print data values over serial - it does not light pixels.

#include <ESP8266WiFi.h>
#include <FS.h>

int n;  // variable for loop.
int nn;  // variable for loop.
File FSEQ_Data;
long int Data_Offset;  // start of data in .FSEQ file (length of headder) (read from file).
long int Number_Channels;  //  total number of channels in .FSEQ file (read from file).
long int Step_Lenght;  // number of frames in .FSEQ file (read from file).
int Frame_Time;  // FPS of of frames in .FSEQ file (read from file).
bool Debug = 1; // minimum debug.
bool FSEQ_Headder_Debug = 1; // debug .FSEQ headder.

void setup() {
  WiFi.mode(WIFI_OFF);  // disable wifi.
  SPIFFS.begin();  // start an instance of SPIFFS.
  Serial.begin(115200);  // debug print - comment out during normal use.
  FESQ_Headder_Read();  // call function.
}

void loop() {
  FSEQ_Data = SPIFFS.open("/tree-4min.fseq", "r");  //open file in read only mode.
  FSEQ_Data.seek(Data_Offset, SeekSet); // set read pionter to correct byte.
  for  (nn = 0; nn < Step_Lenght ; nn++) {  // loop number of steps in sequence (fps*time).
  for  (n = 0; n < Number_Channels ; n++) {  // loop number of channels times.

    byte Data = FSEQ_Data.read();  // read one byte of data from .FSEQ file.
    Serial.print(Data, HEX);  // print byte as hex value.
    Serial.print(" ");
  }
    delay(Frame_Time);  // delay (1 sec / fps) - not final code.
  }
}

//*************** void FESQ_Headder_Read ***************//
void FESQ_Headder_Read() {
  Serial.print("Opened "); // debug print.
  FSEQ_Data =  SPIFFS.open("/tree-4min.fseq", "r");
  if (FSEQ_Data) { // check file open.
    //-----------------------------------------
    FSEQ_Data.seek(4, SeekSet); // set read pionter to correct byte.
    Data_Offset = (FSEQ_Data.read()); // read LSB.
    Data_Offset = Data_Offset + (FSEQ_Data.read() * 256); // read MSB & add to LSB.
    while (FSEQ_Headder_Debug) { // debug print.
      Serial.println(); // debug print.
      Serial.print("Data Offset: "); // debug print.
      Serial.print(Data_Offset); // debug print.
      Serial.print(" "); // debug print.
      break;
    }
    //-----------------------------------------
    FSEQ_Data.seek(10, SeekSet); // set read pionter to correct byte.
    Number_Channels = (FSEQ_Data.read()); // read LSB.
    Number_Channels = Number_Channels + (FSEQ_Data.read() * 256); // read MSB & add to LSB.
    while (FSEQ_Headder_Debug) { // debug print.
      Serial.println(); // debug print.
      Serial.print("Channels: "); // debug print.
      Serial.print(Number_Channels); // debug print.
      Serial.print(" "); // debug print.
      break;
    }
    //-----------------------------------------
    FSEQ_Data.seek(14, SeekSet); // set read pionter to correct byte.
    Step_Lenght = (FSEQ_Data.read()); // read LSB.
    Step_Lenght = Step_Lenght + (FSEQ_Data.read() * 256); // read MSB & add to LSB.
    while (FSEQ_Headder_Debug) { // debug print.
      Serial.println(); // debug print.
      Serial.print("Step Length: "); // debug print.
      Serial.print(Step_Lenght); // debug print.
      Serial.print(" "); // debug print.
      break;
    }
    //-----------------------------------------
    FSEQ_Data.seek(18, SeekSet); // set read pionter to correct byte.
    Frame_Time = (FSEQ_Data.read()); // Read FPS.
    while (FSEQ_Headder_Debug) { // debug print.
      Serial.println(); // debug print.
      Serial.print("Frame Timing: "); // debug print.
      Serial.print(Frame_Time, DEC); // debug print.
      Serial.print(" "); // debug print.
      break;
    }
    //-----------------------------------------
    while (Debug) { // debug print.
      Serial.println(); // debug print.
      Serial.print("FSEQ_Data read"); // debug print.
      Serial.println(" and variables set."); // debug print.
      delay(10);
      break;
    }
  }
  // if the file isn't open, pop up an error:
  else {
    while (Debug) { // debug print.
      Serial.print("error opening "); // debug print.
      Serial.println("FSEQ_Data"); // debug print.
      break;
    }
  }
  return;
}