diff --git a/.gitignore b/.gitignore index 2b16c31..3903eaa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,10 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch -.DS_Store \ No newline at end of file +.DS_Store +.idea/ +CMakeLists.txt +CMakeListsPrivate.txt +cmake-build-az-delivery-devkit-v4/ +cmake-build-debug/ +venv/ \ No newline at end of file diff --git a/html/website.html b/html/website.html index e3c9216..e2e7818 100644 --- a/html/website.html +++ b/html/website.html @@ -1,13 +1,13 @@ - + ESPuino-Konfiguration - + - + @@ -15,430 +15,511 @@ - - - -
-
-

WLAN-Konfiguration

-
+
+ +
+
+

WLAN-Konfiguration

+
- - -
- Bitte SSID des WLANs eintragen. -
- - - - + + +
+ Bitte SSID des WLANs eintragen. +
+ + + +
- -
-
-
-

RFID-Zuweisungen

-
-
- - - - + +
+
+
+

RFID-Zuweisungen

+
+
+ + + + +
-
- +
+ Dateien suchen
- - -
- - - -
-
-
-

RFID-Modifkationen

-
-
- - -
- Bitte eine 12-stellige Zahl eingeben. +
+
+



Der Prozess kann mehrere Minuten dauern...

+
- - -
- - - -
-
-
-

MQTT-Konfiguration

-
-
- -
-
- - - - - - + + +
+ + +
+
+
+
+

RFID-Modifkationen

+
+
+ + +
+ Bitte eine 12-stellige Zahl eingeben.
- - - -
-
-
-

FTP-Konfiguration

-
-
+ + +
+ + +
+
+
+
+

MQTT-Konfiguration

+
+
+ + +
+
+ + + + + + +
+ + +
+
+
+
+

FTP-Konfiguration

+
+
- + - -
- - -
-
-
-
-

Allgemeine Konfiguration

-
-
- - - - - - -
-
- - - - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - -
-
-
-
-

NVS-Importer

-
-
+ +
+ + +
+
+
+
+

Allgemeine Konfiguration

+
+
+ + + + + + +
+
+ + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+
+
+
+

NVS-Importer

+
+
-
- -
-
-
- - + } + }; + var myJSON = JSON.stringify(myObj); + socket.send(myJSON); + } + + $(document).ready(function () { + connect(); + renderFileTree(); + + $(function () { + $('[data-toggle="tooltip"]').tooltip(); + }); + }); + + diff --git a/html/websiteMgmt.h b/html/websiteMgmt.h deleted file mode 100644 index f5bc9e7..0000000 --- a/html/websiteMgmt.h +++ /dev/null @@ -1,263 +0,0 @@ -static const char mgtWebsite[] PROGMEM = "\ -\ - \ - ESPuino-Konfiguration\ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
\ -
\ -

WLAN-Konfiguration

\ -
\ -
\ - \ - \ -
\ - Bitte SSID des WLANs eintragen.\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -

RFID-Zuweisungen

\ -
\ -
\ - \ - \ - \ - \ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -

RFID-Modifkationen

\ -
\ -
\ - \ - \ -
\ - Bitte eine 12-stellige Zahl eingeben.\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -

MQTT-Konfiguration

\ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ - Bitte eine gültige IPv4-Adresse eingeben, z.B. 192.168.2.89.\ -
\ -
\ - \ - \ -
\ -
\ -
\ -

FTP-Konfiguration

\ -
\ -
\ - \ - \ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -

Allgemeine Konfiguration

\ -
\ -
\ - \ - \ - \ - \ -
\ -
\ - \ - \ - \ - \ -
\ -
\ - \ - \ -
\ - \ - \ -
\ - \ -
\ - \ -\ -"; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 09908a7..525d184 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -367,6 +367,7 @@ static const char restartWebsite[] PROGMEM = "

Der Tonuino wird neu gestartet. SPIClass spiSD(HSPI); TaskHandle_t mp3Play; TaskHandle_t rfid; +TaskHandle_t fileTaskHandle; #ifdef NEOPIXEL_ENABLE TaskHandle_t LED; #endif @@ -553,6 +554,14 @@ void createFile(fs::FS &fs, const char * path, const char * message){ file.close(); } +bool fileExists(fs::FS &fs, const char *file){ + if (fs.exists(file)) { + return true; + } else { + return false; + } +} + /** * Appends raw input to a file * @param fs @@ -610,6 +619,7 @@ void appendNodeToJSONFile(fs::FS &fs, const char * path, const char *filename, c file.print("\"\n }"); // i/o is timing critical keep all stuff running esp_task_wdt_reset(); + yield(); file.close(); if(isFirstJSONtNode){ @@ -638,11 +648,16 @@ bool pathValid(const char *_fileItem) { * @param parent * @param levels */ +char fileNameBuf[255]; +bool notifyOverWebsocket = true; + +//FIXME: This function blocks the websocket connection void parseSDFileList(fs::FS &fs, const char * dirname, const char * parent, uint8_t levels){ - char fileNameBuf[255]; + // i/o is timing critical keep all stuff running esp_task_wdt_reset(); + yield(); File root = fs.open(dirname); if(!root){ @@ -672,9 +687,10 @@ void parseSDFileList(fs::FS &fs, const char * dirname, const char * parent, uint } strncpy(fileNameBuf, (char *) file.name(), sizeof(fileNameBuf) / sizeof(fileNameBuf[0])); - // we have a folder if(file.isDirectory()){ + + esp_task_wdt_reset(); if (pathValid(fileNameBuf)){ appendNodeToJSONFile(SD, DIRECTORY_INDEX_FILE, fileNameBuf, parent, "folder" ); @@ -696,23 +712,33 @@ void parseSDFileList(fs::FS &fs, const char * dirname, const char * parent, uint } // TODO: maybe this is not save with asyncWebserver -bool indexingIsRunning = false; - +uint8_t runFileIndexing = 0; +uint8_t fileIndexingDone = 0; /** * Public function for creating file index json on SD-Card. * It notifies the user client via websockets when the indexing * is done. */ void createJSONFileList(){ + createFile(SD, DIRECTORY_INDEX_FILE, "[\n"); + parseSDFileList(SD, "/", NULL, FS_DEPTH); + appendToFile(SD, DIRECTORY_INDEX_FILE, "]"); + isFirstJSONtNode = true; + sendWebsocketData(0, 30); +} + +void fileHandlingTask(void *arguments){ + + while(true) { - if(!indexingIsRunning){ - indexingIsRunning = true; - createFile(SD, DIRECTORY_INDEX_FILE, "[\n"); - parseSDFileList(SD, "/", NULL, FS_DEPTH); - appendToFile(SD, DIRECTORY_INDEX_FILE, "]"); - isFirstJSONtNode = true; - sendWebsocketData(0, 30); - indexingIsRunning = false; + if(runFileIndexing){ + runFileIndexing = 0; + //createJSONFileList(); + fileIndexingDone = 1; + } + + esp_task_wdt_reset(); + vTaskDelay(portTICK_PERIOD_MS*150); } } @@ -3002,7 +3028,6 @@ bool getWifiEnableStatusFromNVS(void) { prefsSettings.putUInt("enableWifi", 1); wifiStatus = 1; } - return wifiStatus; } @@ -3290,6 +3315,8 @@ bool processJsonRequest(char *_serialJson) { sendWebsocketData(0, 20); return false; } else if (doc.containsKey("refreshFileList")) { + //createJSONFileList(); + runFileIndexing = 1; createJSONFileList(); } @@ -3313,8 +3340,12 @@ void sendWebsocketData(uint32_t client, uint8_t code) { object["pong"] = "pong"; } else if (code == 30){ object["refreshFileList"] = "ready"; + }else if (code == 31){ + object["indexingState"] = fileNameBuf; + esp_task_wdt_reset(); } - char jBuf[50]; + + char jBuf[255]; serializeJson(doc, jBuf, sizeof(jBuf) / sizeof(jBuf[0])); if (client == 0) { @@ -3322,6 +3353,7 @@ void sendWebsocketData(uint32_t client, uint8_t code) { } else { ws.printf(client, jBuf); } + notifyOverWebsocket = true; } @@ -3897,6 +3929,18 @@ void setup() { 1 /* Core where the task should run */ ); + /** + * SD Card File Indexing Task + */ + xTaskCreatePinnedToCore( + fileHandlingTask, /* Function to implement the task */ + "fileHandlingTask", /* Name of the task */ + 2000, /* Stack size in words */ + NULL, /* Task input parameter */ + 3, /* Priority of the task */ + &fileTaskHandle, /* Task handle. */ + 1 /* Core where the task should run */ + ); //esp_sleep_enable_ext0_wakeup((gpio_num_t) DREHENCODER_BUTTON, 0); @@ -3924,10 +3968,18 @@ void setup() { lastTimeActiveTimestamp = millis(); // initial set after boot + /** + * Create empty Index json file when no file exists. + */ + if(!fileExists(SD,DIRECTORY_INDEX_FILE)){ + createFile(SD,DIRECTORY_INDEX_FILE,"[]"); + ESP.restart(); + } bootComplete = true; Serial.print(F("Free heap: ")); Serial.println(ESP.getFreeHeap()); + } @@ -3945,6 +3997,13 @@ void loop() { sleepHandler(); deepSleepManager(); rfidPreferenceLookupHandler(); + + /* + if(fileIndexingDone){ + fileIndexingDone = 0; + sendWebsocketData(0,30); + }*/ + if (wifiManager() == WL_CONNECTED) { #ifdef MQTT_ENABLE if (enableMqtt) { @@ -3965,6 +4024,7 @@ void loop() { #ifdef PLAY_LAST_RFID_AFTER_REBOOT recoverLastRfidPlayed(); #endif + ws.cleanupClients(); } diff --git a/src/websiteMgmt.h b/src/websiteMgmt.h index 9fe3f05..1d9e557 100644 --- a/src/websiteMgmt.h +++ b/src/websiteMgmt.h @@ -1,13 +1,13 @@ static const char mgtWebsite[] PROGMEM = "\ \ - \ +\ ESPuino-Konfiguration\ \ \ \ - \ + \ \ - \ + \ \ \ \ @@ -15,365 +15,449 @@ static const char mgtWebsite[] PROGMEM = "\ \ \ \ - \ - \ -

\ -
\ -
\ -

WLAN-Konfiguration

\ -
\ +
\ +\ +
\ +
\ +

WLAN-Konfiguration

\ + \
\ - \ - \ -
\ - Bitte SSID des WLANs eintragen.\ -
\ - \ - \ - \ - \ + \ + \ +
\ + Bitte SSID des WLANs eintragen.\ +
\ + \ + \ + \ + \
\ \ \ - \ -
\ -
\ -
\ -

RFID-Zuweisungen

\ -
\ -
\ - \ - \ - \ - \ + \ +
\ +
\ +
\ +

RFID-Zuweisungen

\ +
\ +
\ + \ + \ + \ + \ +
\
\
\ -
\ - \ +
\ + Dateien suchen\
\
\ - \ - \ -
\ - \ - \ - \ -
\ -
\ -
\ -

RFID-Modifkationen

\ -
\ -
\ - \ - \ -
\ - Bitte eine 12-stellige Zahl eingeben.\ +
\ +
\ +



Der Prozess kann mehrere Minuten dauern...

\ +
\
\ - \ - \ -
\ - \ - \ - \ -
\ -
\ -
\ -

MQTT-Konfiguration

\ -
\ -
\ - \ - \
\ -
\ - \ - \ - \ - \ - \ - \ + \ + \ +
\ + \ + \ +
\ +
\ +
\ +
\ +

RFID-Modifkationen

\ +
\ +
\ + \ + \ +
\ + Bitte eine 12-stellige Zahl eingeben.\
\ - \ - \ - \ -
\ -
\ -
\ -

FTP-Konfiguration

\ -
\ -
\ + \ + \ +
\ + \ + \ +
\ +
\ +
\ +
\ +

MQTT-Konfiguration

\ +
\ +
\ + \ + \ +
\ +
\ + \ + \ + \ + \ + \ + \ +
\ + \ + \ +
\ +
\ +
\ +
\ +

FTP-Konfiguration

\ +
\ +
\ \ - \ + \ \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -

Allgemeine Konfiguration

\ -
\ -
\ - \ - \ - \ - \ - \ - \ -
\ -
\ - \ - \ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -

NVS-Importer

\ -
\ -
\ + \ +
\ + \ + \ +
\ +
\ +
\ +
\ +

Allgemeine Konfiguration

\ +
\ +
\ + \ + \ + \ + \ + \ + \ +
\ +
\ + \ + \ + \ + \ +
\ +
\ + \ + \ +
\ +
\ + \ + \ +
\ +
\ + \ + \ +
\ +
\ + \ + \ +
\ +
\ + \ + \ +
\ + \ + \ +
\ +
\ +
\ +
\ +

NVS-Importer

\ +
\ +
\ \ \ -
\ - \ -
\ -
\ -
\ - \ - \ + }\ + };\ + var myJSON = JSON.stringify(myObj);\ + socket.send(myJSON);\ + }\ +\ + $(document).ready(function () {\ + connect();\ + renderFileTree();\ +\ + $(function () {\ + $('[data-toggle=\"tooltip\"]').tooltip();\ + });\ + });\ +\ +\ \ "; \ No newline at end of file