lorol / LITTLEFS

LittleFS library for arduino-esp32
GNU General Public License v2.0
167 stars 68 forks source link

Tutorial missing - Use the built-in LITTLEFS library - how to use the library itself #51

Open Sentinel8000 opened 2 years ago

Sentinel8000 commented 2 years ago

Im wondering people creating good things for arduino/esp32 but if somebody try as beginner use these fail, because there is no tutorial, description/use case.

Without any description as beginner i have downloaded the library and added to my librarys, i got this errors:

C:\Users\X\Documents\Arduino\libraries\LittleFS_esp32\src\esp_littlefs.c:19:2: warning: #warning ("Use the built-in LITTLEFS library") [-Wcpp]

C:\Users\X\Documents\Arduino\libraries\LittleFS_esp32\src\LITTLEFS.cpp: In member function 'virtual bool LITTLEFSImpl::exists(const char)': C:\Users\X\Documents\Arduino\libraries\LittleFS_esp32\src\LITTLEFS.cpp:44:28: error: no matching function for call to 'LITTLEFSImpl::open(const char&, const char [2])' File f = open(path, "r"); ^ In file included from C:\Users\X\Documents\Arduino\libraries\LittleFS_esp32\src\LITTLEFS.cpp:17: C:\Users\X\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\FS\src/vfs_api.h:38:17: note: candidate: 'virtual fs::FileImplPtr VFSImpl::open(const char, const char, bool)' FileImplPtr open(const char path, const char mode, const bool create) override; ^~~~ C:\Users\X\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\FS\src/vfs_api.h:38:17: note: candidate expects 3 arguments, 2 provided exit status 1

Use the built-in LITTLEFS library - And?

Im sure need something todo before use, but im not sure without any tutorial.

Im using arduino ide version 1.8.12

Example code from the arduino ide forum:

define dbg(myFixedText, variableName) \

Serial.print( F(#myFixedText " " #variableName"=") ); \ Serial.println(variableName);

define dbgi(myFixedText, variableName,timeInterval) \

do { \ static unsigned long intervalStartTime; \ if ( millis() - intervalStartTime >= timeInterval ){ \ intervalStartTime = millis(); \ Serial.print( F(#myFixedText " " #variableName"=") ); \ Serial.println(variableName); \ } \ } while (false);

include

include

define FORMAT_LITTLEFS_IF_FAILED true

String MyEmail = "myEmail@myProvider.com"; String MyPassWord = "thereisnopassword"; String MySecret = "NUX007";

void prepareLittleFS() { //Start LittleFS if(!LITTLEFS.begin(FORMAT_LITTLEFS_IF_FAILED)){ Serial.println("LITTLEFS Mount failed"); return;
}
writeDefaultData(); }

void readData() { File file = LITTLEFS.open("/SavedFile.txt", "r");

if(!file){ Serial.println("No Saved Data!"); writeDefaultData();
Serial.println("writeDefaultData(); done"); } while(file.available()){ MyEmail = file.readString(); dbg("FileRead:",MyEmail);

MyPassWord = file.readString();
dbg("FileRead:",MyPassWord);

MySecret   = file.readString(); 
dbg("FileRead:",MySecret);

}
file.close(); }

void writeDefaultData() { File file = LITTLEFS.open("/SavedFile.txt", "w");

MyEmail = "MyEmail@MyProvider.com"; file.println(MyEmail);

dbg("file.println:",MyEmail);

MyPassWord = "enter_your_password"; file.println(MyPassWord); dbg("file.println:",MyPassWord);

MySecret = "enter_your_secret"; file.println(MySecret); dbg("file.println:",MySecret); delay(1);

file.close();

Serial.println("Write successful");
}

void writeData() { File file = LITTLEFS.open("/SavedFile.txt", "w");

file.println(MyEmail); dbg("file.println:",MyEmail);

file.println(MyPassWord); dbg("file.println:",MyPassWord);

file.println(MySecret); dbg("file.println:",MySecret); delay(1);

file.close();

Serial.println("Write successful"); }

void PrintFileNameDateTime() { Serial.println( F("Code running comes from file ") ); Serial.println( F(FILE) );; Serial.print( F(" compiled ") ); Serial.print( F(DATE) ); Serial.print( F(" ") ); Serial.println( F(TIME) );
}

void setup() { Serial.begin(115200); Serial.println(); Serial.println( F("Setup-Start") ); PrintFileNameDateTime(); dbg("right before prepareLittleFS()",0); prepareLittleFS(); dbg("right after prepareLittleFS()",0); readData();

}

void loop() {

}

ramanraja commented 8 months ago

Specifically, there is no documentation on end(). The examples also seem to ignore it. Is it mandatory to call LittleFS.end() after read/write operations ? If not called, is there a chance of files getting corrupted?