46 lines
913 B
C++
46 lines
913 B
C++
#include <Arduino.h>
|
|
#include <FS.h>
|
|
#include <LittleFS.h>
|
|
|
|
void listFiles() {
|
|
Serial.println("\nListing files in LittleFS:");
|
|
Dir dir = LittleFS.openDir("/");
|
|
while (dir.next()) {
|
|
Serial.printf(" %s (%d bytes)\n", dir.fileName().c_str(), dir.fileSize());
|
|
}
|
|
}
|
|
|
|
void readFile(const char *path) {
|
|
File file = LittleFS.open(path, "r");
|
|
if (!file) {
|
|
Serial.printf("Failed to open file: %s\n", path);
|
|
return;
|
|
}
|
|
Serial.printf("Contents of %s:\n", path);
|
|
while (file.available()) {
|
|
Serial.write(file.read());
|
|
}
|
|
Serial.println();
|
|
file.close();
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
delay(500);
|
|
|
|
if (!LittleFS.begin()) {
|
|
Serial.println("LittleFS mount failed! Did you upload data folder?");
|
|
return;
|
|
}
|
|
|
|
Serial.println("LittleFS mounted successfully.");
|
|
listFiles();
|
|
|
|
// Read demo files
|
|
readFile("/info.txt");
|
|
readFile("/config.json");
|
|
}
|
|
|
|
void loop() {
|
|
}
|