63 lines
1.0 KiB
C++
63 lines
1.0 KiB
C++
#include "SPIFFS.h"
|
|
|
|
File file;
|
|
|
|
void setup()
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
delay(2000);
|
|
|
|
if (!SPIFFS.begin(true))
|
|
{
|
|
Serial.println("An Error has occurred while mounting SPIFFS");
|
|
return;
|
|
}
|
|
|
|
Serial.print("SPIFFS: Total:");
|
|
Serial.print(SPIFFS.totalBytes());
|
|
Serial.print("/Used:");
|
|
Serial.println(SPIFFS.usedBytes());
|
|
|
|
Serial.print("Trying delete:");
|
|
Serial.println(SPIFFS.remove("/test.txt"));
|
|
|
|
file = SPIFFS.open("/test.txt", FILE_WRITE);
|
|
|
|
if (!file)
|
|
{
|
|
Serial.println("There was an error opening the file for writing");
|
|
return;
|
|
}
|
|
|
|
// file.close();
|
|
}
|
|
|
|
long i = 0, numw = 0;
|
|
|
|
void loop()
|
|
{
|
|
if (file.print("X"))
|
|
{
|
|
i++;
|
|
/* if (0==i%1024) {
|
|
Serial.print(i/1024);
|
|
Serial.print("/");
|
|
} */
|
|
}
|
|
else
|
|
{
|
|
Serial.print("File write failed on pos: ");
|
|
Serial.print(i);
|
|
Serial.print(" / ");
|
|
Serial.println(++numw);
|
|
|
|
file.close();
|
|
|
|
Serial.print("Trying delete:");
|
|
Serial.println(SPIFFS.remove("/test.txt"));
|
|
|
|
file = SPIFFS.open("/test.txt", FILE_WRITE);
|
|
i = 0;
|
|
}
|
|
} |