Uebperpruefung ob FileSystem gemounted ist?

Hallo,

wie macht man eien Ueberpruefung ob ein Filesystem gemounte ist oder nicht?

Aktuell ueberpruefe ich mit (!LittleFS.begin()) vor einer Dateioperation ob das Filesystem gemounted ist. ISt dies der richtige Weg? oder we macht man das richtig?

hier mein Sketch

#include "LittleFS.h"
//function prototypes
void readData();
void writeData(String data);
void deleteData();
void setup() {
  //Start the serial monitor
  Serial.begin(115200);
  //Start LittleFS
  if(!LittleFS.begin()){
    Serial.println("An Error has occurred while mounting LittleFS");
    return;
  }
  //Read the saved data
  readData(); 
}
void loop() {
 
}
void readData()
{
   //Open the file
  if(!LittleFS.begin()){
   File file = LittleFS.open("/SavedFile.txt", "r");
  //Check if the file exists
   if(!file){
   //Read the file data and display it on LCD
    Serial.println("No Saved Data!");
    return;
   }
   //Close the file
    file.close();
}
}

Hallo,
schau mal hier in der Doku
https://arduino-esp8266.readthedocs.io/en/3.1.2/filesystem.html#begin

Ja aber genau da finde ich nichts wie ismounted oder so

Hallo,
aus dem Link kopiert

This method mounts file system. It must be called before any other FS APIs are used. Returns true if file system was mounted successfully, false otherwise. With no options it will format SPIFFS if it is unable to mount it on the first try.

für mich ist das eindeutig oder so :wink:

Hallo,
ich mach das einmal im Setup , warum willst Du das ständig abfragen.

das macht sicher Sinn mit einer SD Karte die man rausnehmen will bei laufendem Betrieb , vorher ein end zu machen.

Bevor ich ein Fehler in einer file Aktion bekomme wollte ich es abfragen. -->fehler Vermeidung bzw. debuggen

Ich glaub Du machst Dir zuviele Gedanken.
Du müsstest vor jedem Zugriff also prüfen, ob das Dateisystem angelegt ist.

Was ist ein Zugriff?
Meine Antwort: Jedes verdammte Bit, was da reintropft.
Nu überleg mal.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.