ls -l implement and ota fw fix
This commit is contained in:
1 parent
b696703d45
commit
6596346d3d
6 files changed
+83
-52
No files matched your search
+27
-26
@@ -3,35 +3,36 @@
|
||||
// listDir("/");
|
||||
// deleteFile("/hello.txt");
|
||||
// writeFile("/hello.txt", "Hello ");
|
||||
// appendFile("/hello.txt", "World!\n");
|
||||
// appendFile("/hello.txt", "World!\n\r");
|
||||
// readFile("/hello.txt");
|
||||
// listDir("/");
|
||||
|
||||
FSInfo fsinfo;
|
||||
|
||||
void listDir(const char * dirname) {
|
||||
Serial.printf("Listing directory: %s\n", dirname);
|
||||
void ls(const char * dirname) {
|
||||
Serial.printf("ls -l %s\n\r", dirname);
|
||||
Dir root = LittleFS.openDir(dirname);
|
||||
|
||||
while (root.next()) {
|
||||
File file = root.openFile("r");
|
||||
Serial.print(" FILE: ");
|
||||
Serial.print(root.fileName());
|
||||
Serial.print(" SIZE: ");
|
||||
Serial.print(file.size());
|
||||
time_t cr = file.getCreationTime();
|
||||
|
||||
time_t lw = file.getLastWrite();
|
||||
struct tm * tmstruct = localtime(&lw);
|
||||
Serial.printf("%8d %02d %02d %02d:%02d %s\n\r",
|
||||
file.size(),
|
||||
tmstruct->tm_mon + 1,
|
||||
tmstruct->tm_mday,
|
||||
tmstruct->tm_hour,
|
||||
tmstruct->tm_min,
|
||||
root.fileName().c_str());
|
||||
file.close();
|
||||
struct tm * tmstruct = localtime(&cr);
|
||||
Serial.printf(" CREATION: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
|
||||
tmstruct = localtime(&lw);
|
||||
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void readFile(const char * path) {
|
||||
Serial.printf("Reading file: %s\n", path);
|
||||
Serial.printf("Reading file: %s\n\r", path);
|
||||
|
||||
File file = LittleFS.open(path, "r");
|
||||
if (!file) {
|
||||
@@ -47,7 +48,7 @@ void readFile(const char * path) {
|
||||
}
|
||||
|
||||
void writeFile(const char * path, const char * message) {
|
||||
Serial.printf("Writing file: %s\n", path);
|
||||
Serial.printf("Writing file: %s\n\r", path);
|
||||
|
||||
File file = LittleFS.open(path, "w");
|
||||
if (!file) {
|
||||
@@ -64,7 +65,7 @@ void writeFile(const char * path, const char * message) {
|
||||
}
|
||||
|
||||
void appendFile(const char * path, const char * message) {
|
||||
Serial.printf("Appending to file: %s\n", path);
|
||||
Serial.printf("Appending to file: %s\n\r", path);
|
||||
|
||||
File file = LittleFS.open(path, "a");
|
||||
if (!file) {
|
||||
@@ -80,7 +81,7 @@ void appendFile(const char * path, const char * message) {
|
||||
}
|
||||
|
||||
void renameFile(const char * path1, const char * path2) {
|
||||
Serial.printf("Renaming file %s to %s\n", path1, path2);
|
||||
Serial.printf("Renaming file %s to %s\n\r", path1, path2);
|
||||
if (LittleFS.rename(path1, path2)) {
|
||||
Serial.println("File renamed");
|
||||
} else {
|
||||
@@ -89,7 +90,7 @@ void renameFile(const char * path1, const char * path2) {
|
||||
}
|
||||
|
||||
void deleteFile(const char * path) {
|
||||
Serial.printf("Deleting file: %s\n", path);
|
||||
Serial.printf("Deleting file: %s\n\r", path);
|
||||
if (LittleFS.remove(path)) {
|
||||
Serial.println("File deleted");
|
||||
} else {
|
||||
@@ -109,20 +110,20 @@ bool mount_fs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("Filesystem opened: \n");
|
||||
printf("\ttotalBytes:\t%d\n", fsinfo.totalBytes);
|
||||
printf("\tusedBytes:\t%d\n", fsinfo.usedBytes);
|
||||
printf("\tblockSize:\t%d\n", fsinfo.blockSize);
|
||||
printf("\tpageSize:\t%d\n", fsinfo.pageSize);
|
||||
printf("\tmaxOpenFiles:\t%d\n", fsinfo.maxOpenFiles);
|
||||
printf("\tmaxPathLength:\t%d\n", fsinfo.maxPathLength);
|
||||
printf("\n");
|
||||
printf("Filesystem opened:\n\r");
|
||||
printf("\ttotalBytes:\t%d\n\r", fsinfo.totalBytes);
|
||||
printf("\tusedBytes:\t%d\n\r", fsinfo.usedBytes);
|
||||
printf("\tblockSize:\t%d\n\r", fsinfo.blockSize);
|
||||
printf("\tpageSize:\t%d\n\r", fsinfo.pageSize);
|
||||
printf("\tmaxOpenFiles:\t%d\n\r", fsinfo.maxOpenFiles);
|
||||
printf("\tmaxPathLength:\t%d\n\r", fsinfo.maxPathLength);
|
||||
printf("\n\r");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool format_fs() {
|
||||
printf("Formatting FS ! \n");
|
||||
printf("Formatting FS ! \n\r");
|
||||
return LittleFS.format();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user