Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sentinel8000 opened this issue Jun 25, 2022 · 1 comment

Comments

@Sentinel8000
Copy link

Sentinel8000 commented Jun 25, 2022

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 <FS.h>
#include <LITTLEFS.h>
#define FORMAT_LITTLEFS_IF_FAILED true

String MyEmail = "[email protected]";
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 = "[email protected]";
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
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants