|
2 | 2 | #if defined(ESP32)
|
3 | 3 | #include <ESPmDNS.h>
|
4 | 4 | #include <WebServer.h>
|
5 |
| - #include "SPIFFS.h" |
6 |
| - #define STORAGE SPIFFS // Storage SPIFFS |
7 | 5 | #define WEB_SERVER WebServer
|
8 | 6 | #else
|
9 | 7 | #include <ESP8266WebServer.h>
|
10 | 8 | #include <LittleFS.h>
|
11 | 9 | #include <ESP8266mDNS.h>
|
12 |
| - #define STORAGE LittleFS // Storage LittleFS |
13 | 10 | #define WEB_SERVER ESP8266WebServer
|
14 | 11 | #endif
|
15 | 12 |
|
16 | 13 | // Setting to true will need to upload contents of /data
|
17 | 14 | // directory to esp SPIFFS using image upload
|
18 |
| -#define USE_SPIFFS_FOR_PAGES false |
| 15 | +#define USE_STORAGE_FOR_PAGES false |
19 | 16 |
|
20 | 17 | #if defined(ESP32)
|
21 |
| - #if not USE_SPIFFS_FOR_PAGES |
| 18 | + #if USE_STORAGE_FOR_PAGES |
22 | 19 | #define BODY_FILE_NAME "/src/ESPWroom32-Vis.html"
|
23 | 20 | #else
|
24 | 21 | #include "gpioPMemESP32.h"
|
25 | 22 | #endif
|
26 | 23 | #define TOTAL_PINS 40
|
27 | 24 | #else
|
28 |
| - #if not USE_SPIFFS_FOR_PAGES |
29 |
| - #include "gpioPMemESP8266.h" |
30 |
| - #else |
| 25 | + #if USE_STORAGE_FOR_PAGES |
31 | 26 | #define BODY_FILE_NAME "/src/ESP8266Wemos-Vis.html"
|
| 27 | + #else |
| 28 | + #include "gpioPMemESP8266.h" |
32 | 29 | //#define BODY_FILE_NAME "/src/test.html"
|
33 | 30 | #endif
|
34 | 31 | #define TOTAL_PINS 17
|
@@ -116,36 +113,35 @@ void readAllGpio(){
|
116 | 113 | */
|
117 | 114 | }
|
118 | 115 | }
|
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(""); |
136 | 131 | }
|
| 132 | + |
137 | 133 | void setup() {
|
138 | 134 | Serial.begin(115200);
|
139 | 135 | Serial.print("\n\n\n\n");
|
140 | 136 | Serial.flush();
|
141 | 137 | if (!STORAGE.begin()) {
|
142 |
| - Serial.println("An Error has occurred while mounting SPIFFS"); |
| 138 | + LOG_E("An Error has occurred while mounting SPIFFS\n"); |
143 | 139 | return;
|
144 | 140 | }else{
|
145 | 141 | LOG_I("Storage statred.\n");
|
146 | 142 | }
|
147 | 143 | LOG_I("Starting..\n");
|
148 |
| - listAllFilesInDir("/"); |
| 144 | + ListDir("/"); |
149 | 145 | // Connect WIFI ?
|
150 | 146 | if(strlen(st_ssid)>0){
|
151 | 147 | LOG_D("Connect Wifi to %s.\n", st_ssid);
|
@@ -176,7 +172,7 @@ void setup() {
|
176 | 172 | }
|
177 | 173 |
|
178 | 174 | // Use default CONTROLASSIST_HTML_HEADER and CONTROLASSIST_HTML_FOOTER
|
179 |
| - #if USE_SPIFFS_FOR_PAGES |
| 175 | + #if USE_STORAGE_FOR_PAGES |
180 | 176 | ctrl.setHtmlBodyFile(BODY_FILE_NAME);
|
181 | 177 | #else
|
182 | 178 | ctrl.setHtmlBody(HTML_PAGE);
|
|
0 commit comments