[PlatformIO, LittleFS] Code getting hung up on LittleFS.open(file)…?
In the setup() of my main.cpp file, I have the following code to setup the LittleFS framework:
Serial.begin(115200); // initialize
// set up file system
if(!LittleFS.begin(true)) {Serial.println("LittleFS mount failed.");} else {Serial.println("LittleFS mount succeeded");}
And of course I have the preprocessing directive:
#include "LittleFS.h"
I then have this bit to try and check to see if a file exists and open it. If not, then create it:
Now when I test it, it gets hung up on the line with the arrow and doesn’t even show the “open attempt failed”, even though in the past it did not and was able to actually enter this block.
I’m a bit embarrassed to admit, I’ve seen that example sketch and it def looks helpful, bur I’m not sure how I would try that in my project. Do i just download it and add it to my project as a library?
Will get back to you on the platformio.ini config.
This library is part of the Espressif Arduino framework and already available on your computer. No download required.
You can simply copy & paste the code from the github page.
But as the code is also available on your computer, you can navigate to the example file:
Ctrl + left click on “LittleFS.h” in the #include <LittleFS.h> line.
This will bring you to the LittleFS.h source file on your computer.
Now click on src and navigate to examples / LITTLEFS_test / LITTLEFS_test.ino:
How can I run it? Do I need to copy the file into one of the folders in the project directory? Or is it like a CLI command? Sorry, I’m not used to running anything other than my main.cpp file on an ESP. Some step-by-step instructions would help.
SPIFFS-like write file to new path and delete it w/folders
Create missing folders of: /new1/new2/new3/hello3.txt
Writing file to: /new1/new2/new3/hello3.txt
- file written
Listing directory: /
DIR : folder1
Listing directory: /folder1
FILE: plantdata.txt SIZE: 0
DIR : new1
Listing directory: /new1
DIR : new2
Listing directory: /new1/new2
DIR : new3
Listing directory: /new1/new2/new3
FILE: hello3.txt SIZE: 6
FILE: test.txt SIZE: 0
Deleting file and empty folders on path: /new1/new2/new3/hello3.txt
- file deleted
Removing all empty folders on path: /new1/new2/new3/hello3.txt
Listing directory: /
DIR : folder1
Listing directory: /folder1
FILE: plantdata.txt SIZE: 0
FILE: test.txt SIZE: 0
Creating Dir: /mydir
Dir created
Writing file: /mydir/hello2.txt
- file written
Listing directory: /
DIR : folder1
Listing directory: /folder1
FILE: plantdata.txt SIZE: 0
DIR : mydir
Listing directory: /mydir
FILE: hello2.txt SIZE: 6
FILE: test.txt SIZE: 0
Deleting file: /mydir/hello2.txt
- file deleted
Removing Dir: /mydir
Dir removed
Listing directory: /
DIR : folder1
Listing directory: /folder1
FILE: plantdata.txt SIZE: 0
FILE: test.txt SIZE: 0
Writing file: /hello.txt
- file written
Appending to file: /hello.txt
- message appended
Reading file: /hello.txt
- read from file:
Hello World!
Renaming file /hello.txt to /foo.txt
- file renamed
Reading file: /foo.txt
- read from file:
Hello World!
Deleting file: /foo.txt
- file deleted
Testing file I/O with /test.txt
- writing................................................................
- 1048576 bytes written in 15214 ms
- reading................................................................
- 1048576 bytes read in 310 ms
Deleting file: /test.txt
- file deleted
Test complete
So it looks like it’s otherwise working properly in this project. So it’s probably not a hardware or library issue, but rather something with my earlier project.
That proves that LittleFS.open works without issues and the issue must be something in your code. Without knowing your code it is hard to find out what the cause is. Maybe you can publish your code, like on github?
I can try. Unfortunately I got locked out of my Gitlab account and Gitlab isn’t sending the email password reset emails…I can try to find an alternate.
OK, so I created a new platformio project, copying only the “main.cpp” and “platformio.ini” from the original project (plus dependencies ArduinoJson and NTPClient, which I don’t think are the problem), then running it again.
It seems it’s stuck on the same command (stalls on the “fs.open(path)” portion):
File file = fs.open(path);
This tells me that the problem is isolated to the “main” method, or to the platformio.ini. Or perhaps to some sort of configuration in my files.