Perry
Perry
Explore... Chat... Share...
Moderator: igrr
bool spiffsConsistencyCheck()
{
//SPIFFS CONSISTENCY CHECK
Serial.println(F("SPIFFS reading consistency check: "));
// Check each file for reading firt line
Dir dir = SPIFFS.openDir("/");
while(dir.next())
{
yield();
File f = dir.openFile("r");
if(f.size() == 0)
{
Serial.println((String)f.name() + F(" - size: ") + f.size() + F(" - Deleting!!"));
removeFileOrFormatSPIFSS(f);
continue;
}
if(!f.available())
{
Serial.println((String)f.name() + F(" - size: ") + f.size() + F(" - NOT AVAILABLE - Deleting!!"));
removeFileOrFormatSPIFSS(f);
continue;
}
String loadedLine = String(f.readStringUntil('\n'));
if(loadedLine.length() >= 1)
{
if(SPIFFS_DEBUG == false)
loadedLine = "";
Serial.println((String)f.name() + F(" - size: ") + f.size() + F(" - OK") + F(" (") + loadedLine + F(")"));
}
else
{
Serial.println((String)f.name() + F(" - size: ") + f.size() + F(" - LENGTH ZERO - Deleting!!"));
removeFileOrFormatSPIFSS(f);
continue;
}
f.close();
}
Serial.print(F("SPIFFS writing consistency check: "));
File writeTestFile = SPIFFS.open("/testFile","w");
if(writeTestFile)
{
String randomNumber = (String)random(1000000);
writeTestFile.println(randomNumber);
writeTestFile.close();
SPIFFS.end();
delay(100);
SPIFFS.begin();
writeTestFile = SPIFFS.open("/testFile","r");
String readString = writeTestFile.readStringUntil('\n');
Serial.print((String)F("(") + randomNumber + "&" + readString + F("): "));
if(randomNumber.equals(readString) != 0 || SPIFFS.remove("/testFile") == false)
{
Serial.println(F("Problem!! Formating SPIFFS.."));
SPIFFS.format();
}
else
Serial.println(F("OK!"));
return true;
}
else
{
Serial.println(F("Problem!! Formating SPIFFS.."));
SPIFFS.format();
}
return false;
}
bool removeFileOrFormatSPIFSS(File f)
{
String fileName = f.name();
f.close();
if(SPIFFS.remove(fileName))
return true;
else
{
SPIFFS.format();
}
return false;
}
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]