Skip to content

Commit 714c2f6

Browse files
author
gemi254
committed
Updated fs
1 parent 0f14b70 commit 714c2f6

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

examples/ControlAssist-ESPVisualizer/ControlAssist-ESPVisualizer.ino

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,30 @@
22
#if defined(ESP32)
33
#include <ESPmDNS.h>
44
#include <WebServer.h>
5-
#include "SPIFFS.h"
6-
#define STORAGE SPIFFS // Storage SPIFFS
75
#define WEB_SERVER WebServer
86
#else
97
#include <ESP8266WebServer.h>
108
#include <LittleFS.h>
119
#include <ESP8266mDNS.h>
12-
#define STORAGE LittleFS // Storage LittleFS
1310
#define WEB_SERVER ESP8266WebServer
1411
#endif
1512

1613
// Setting to true will need to upload contents of /data
1714
// directory to esp SPIFFS using image upload
18-
#define USE_SPIFFS_FOR_PAGES false
15+
#define USE_STORAGE_FOR_PAGES false
1916

2017
#if defined(ESP32)
21-
#if not USE_SPIFFS_FOR_PAGES
18+
#if USE_STORAGE_FOR_PAGES
2219
#define BODY_FILE_NAME "/src/ESPWroom32-Vis.html"
2320
#else
2421
#include "gpioPMemESP32.h"
2522
#endif
2623
#define TOTAL_PINS 40
2724
#else
28-
#if not USE_SPIFFS_FOR_PAGES
29-
#include "gpioPMemESP8266.h"
30-
#else
25+
#if USE_STORAGE_FOR_PAGES
3126
#define BODY_FILE_NAME "/src/ESP8266Wemos-Vis.html"
27+
#else
28+
#include "gpioPMemESP8266.h"
3229
//#define BODY_FILE_NAME "/src/test.html"
3330
#endif
3431
#define TOTAL_PINS 17
@@ -116,36 +113,35 @@ void readAllGpio(){
116113
*/
117114
}
118115
}
119-
void listAllFilesInDir(String dir_path)
120-
{
121-
Dir dir = LittleFS.openDir(dir_path);
122-
while(dir.next()) {
123-
if (dir.isFile()) {
124-
// print file names
125-
Serial.print("File: ");
126-
Serial.println(dir_path + dir.fileName() + " : " + dir.fileSize());
127-
}
128-
if (dir.isDirectory()) {
129-
// print directory names
130-
Serial.print("Dir: ");
131-
Serial.println(dir_path + dir.fileName() + "/");
132-
// recursive file listing inside new directory
133-
listAllFilesInDir(dir_path + dir.fileName() + "/");
134-
}
135-
}
116+
// List the storage file system
117+
void ListDir(const char * dirname) {
118+
LOG_I("Listing directory: %s\n", dirname);
119+
// List details of files on file system
120+
File root = STORAGE.open(dirname, "r");
121+
File file = root.openNextFile();
122+
while (file) {
123+
#if defined(ESP32)
124+
LOG_I("File: %s, size: %u B\n", file.path(), file.size());
125+
#else
126+
LOG_I("File: %s, size: %u B\n", file.fullName(), file.size());
127+
#endif
128+
file = root.openNextFile();
129+
}
130+
Serial.println("");
136131
}
132+
137133
void setup() {
138134
Serial.begin(115200);
139135
Serial.print("\n\n\n\n");
140136
Serial.flush();
141137
if (!STORAGE.begin()) {
142-
Serial.println("An Error has occurred while mounting SPIFFS");
138+
LOG_E("An Error has occurred while mounting SPIFFS\n");
143139
return;
144140
}else{
145141
LOG_I("Storage statred.\n");
146142
}
147143
LOG_I("Starting..\n");
148-
listAllFilesInDir("/");
144+
ListDir("/");
149145
// Connect WIFI ?
150146
if(strlen(st_ssid)>0){
151147
LOG_D("Connect Wifi to %s.\n", st_ssid);
@@ -176,7 +172,7 @@ void setup() {
176172
}
177173

178174
// Use default CONTROLASSIST_HTML_HEADER and CONTROLASSIST_HTML_FOOTER
179-
#if USE_SPIFFS_FOR_PAGES
175+
#if USE_STORAGE_FOR_PAGES
180176
ctrl.setHtmlBodyFile(BODY_FILE_NAME);
181177
#else
182178
ctrl.setHtmlBody(HTML_PAGE);

0 commit comments

Comments
 (0)