-->
Page 1 of 1

How to make my SPIFFS write faster

PostPosted: Sat Apr 24, 2021 5:53 am
by Anoop S
Here is the code of my project where I am reading the serial data from arduino. The data coming from arduino is bytes which should be put into a spiffs file. Now the problem is spiffs.write() function is taking too much time to write and some of the bytes gets lost during this process. Please someone help.
Code: Select all#include "FS.h"
#include <SoftwareSerial.h>
SoftwareSerial s(D6,D5);

int flag = 0;

void setup() {
  s.begin(9600);
  Serial.begin(9600);
  SPIFFS.begin();
  SPIFFS.remove("/myFile.bin");
}

void loop() {
  uint8_t buff[512];
  File testFile = SPIFFS.open("/myFile.bin", "a+");
  if (s.available()>0){
    if (flag == 0){
      char ch = s.read();
      if (ch == ':'){
        flag = 1;
      }
    }
   
    else{
      s.readBytes(buff, sizeof(buff));
      //Serial.write(buff, sizeof(buff));
      testFile.write(buff, sizeof(buff));
      testFile.close();
    }
  }
}