1- #if defined(ESP8266)
2- #include < ESP8266mDNS.h>
3- #elif defined(ESP32)
4- #include < ESPmDNS.h>
5- #endif
1+ #include < Arduino.h>
62#include < FS.h>
73#include < LittleFS.h>
84#include < AsyncFsWebServer.h> // https://github.com/cotestatnt/async-esp-fs-webserver/
@@ -56,37 +52,9 @@ void getUpdatedtime(const uint32_t timeout)
5652
5753
5854// ////////////////////////////// Filesystem /////////////////////////////////////////
59- void listDir (fs::FS &fs, const char * dirname, uint8_t levels){
60- Serial.printf (" \n Listing directory: %s\n " , dirname);
61- File root = fs.open (dirname, " r" );
62- if (!root) {
63- Serial.println (" - failed to open directory" );
64- return ;
65- }
66- if (!root.isDirectory ()) {
67- Serial.println (" - not a directory" );
68- return ;
69- }
70- File file = root.openNextFile ();
71- while (file) {
72- if (file.isDirectory ()) {
73- if (levels) {
74- #ifdef ESP32
75- listDir (fs, file.path (), levels - 1 );
76- #elif defined(ESP8266)
77- listDir (fs, file.fullName (), levels - 1 );
78- #endif
79- }
80- } else {
81- Serial.printf (" |__ FILE: %s (%d bytes)\n " ,file.name (), file.size ());
82- }
83- file = root.openNextFile ();
84- }
85- }
86-
8755bool startFilesystem () {
8856 if (FILESYSTEM.begin ()){
89- listDir (FILESYSTEM, " /" , 1 ) ;
57+ server. printFileList (FILESYSTEM, " /" , 2 ), Serial ;
9058 return true ;
9159 }
9260 else {
@@ -115,18 +83,6 @@ void setup() {
11583 // Enable ACE FS file web editor and add FS info callback function
11684 server.enableFsCodeEditor ();
11785
118- /*
119- * Getting FS info (total and free bytes) is strictly related to
120- * filesystem library used (LittleFS, FFat, SPIFFS etc etc) and ESP framework
121- */
122- #ifdef ESP32
123- server.setFsInfoCallback ([](fsInfo_t* fsInfo) {
124- fsInfo->fsName = " LittleFS" ;
125- fsInfo->totalBytes = LittleFS.totalBytes ();
126- fsInfo->usedBytes = LittleFS.usedBytes ();
127- });
128- #endif
129-
13086 // Start server with custom websocket event handler
13187 server.init (onWsEvent);
13288 Serial.print (F (" ESP Web Server started on IP Address: " ));
@@ -137,32 +93,10 @@ void setup() {
13793 " Open /edit page to view, edit or upload example or your custom webserver source files."
13894 ));
13995
140- // Start MDNS responder
141- if (WiFi.status () == WL_CONNECTED) {
142- // Set hostname
143- #ifdef ESP8266
144- WiFi.hostname (hostname);
145- #elif defined(ESP32)
146- WiFi.setHostname (hostname);
147- #endif
148- if (MDNS.begin (hostname)) {
149- Serial.println (F (" MDNS responder started." ));
150- Serial.printf (" You should be able to connect with address\t http://%s.local/\n " , hostname);
151- // Add service to MDNS-SD
152- MDNS.addService (" http" , " tcp" , 80 );
153- }
154- }
15596}
15697
15798
158- void loop () {
159-
160- if (WiFi.status () == WL_CONNECTED) {
161- #ifdef ESP8266
162- MDNS.update ();
163- #endif
164- }
165-
99+ void loop () {
166100 // Send ESP system time (epoch) and heap stats to WS client
167101 static uint32_t sendToClientTime;
168102 if (millis () - sendToClientTime > 1000 ) {
0 commit comments