-#include "include/web_server.h"
-#include "include/web_HTML.h"
-#include "include/sd_card.h"
-
-#ifdef ESP8266
- static ESP8266WebServer server{SERVER_PORT};
-#else
- static ESP32WebServer server{SERVER_PORT};
-#endif
-
-static void send_HTML_page(const char* webpage)
-{
- server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
- server.sendHeader("Pragma", "no-cache");
- server.sendHeader("Expires", "-1");
- server.setContentLength(CONTENT_LENGTH_UNKNOWN);
- server.send(200, "text/html", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
- server.sendContent(HTML_data::append_page_header);
-
- server.sendContent(webpage);
- server.sendContent(HTML_data::append_page_footer);
- server.client().stop();
-}
-
-static void home_page()
-{
- send_HTML_page(HTML_data::home_page_str);
-}
-
-static void dir_page()
-{
- // Only lists files and directories in root "/", no recursion into folders...
-
- std::unique_ptr<File> root = SD_card_fs::get_file("/");
- if (*root)
- {
- root->rewindDirectory();
- String web_content {HTML_data::dir_page_str};
-
- File file = root->openNextFile();
- while (file)
- {
- // Serial.print(String(file.name())+"\t");
- web_content += "<tr><td>" + String(file.name()) + "</td>";
- Serial.print(String(file.isDirectory() ? "Dir " : "File ") + String(file.name()) + "\t");
- web_content += "<td>" + String(file.isDirectory() ? "Dir" : "File") + "</td>";
- int bytes = file.size();
- String fsize = "";
- if (bytes < 1024)
- fsize = String(bytes) + " B";
- else if (bytes < (1024 * 1024))
- fsize = String(bytes / 1024.0, 3) + " KB";
- else if (bytes < (1024 * 1024 * 1024))
- fsize = String(bytes / 1024.0 / 1024.0, 3) + " MB";
- else
- fsize = String(bytes / 1024.0 / 1024.0 / 1024.0, 3) + " GB";
- web_content += "<td>" + fsize + "</td></tr>";
- Serial.println(String(fsize));
-
- file = root->openNextFile();
- }
- web_content += "</table>";
- send_HTML_page(web_content.c_str());
- root->close();
- }
- else
- {
- send_HTML_page("<h3>No Files Found</h3>");
- }
-}
-
-static void file_upload()
-{
- send_HTML_page(HTML_data::file_upload_str);
-}
-
-static void handle_file_upload()
-{
- HTTPUpload &uploadfile = server.upload();
-
- if (uploadfile.status == UPLOAD_FILE_START)
- {
- String filename {uploadfile.filename};
-
- if (!filename.startsWith("/"))
- filename = "/" + filename;
-
- Serial.print("Upload File Name: ");
- Serial.println(filename);
- SD_card_fs::delete_file(filename.c_str()); // Remove a previous version, otherwise data is appended the file again
- SD_card_fs::open_file(filename.c_str()); // Open the file for writing in SPIFFS (create it, if doesn't exist)
- }
- else if (uploadfile.status == UPLOAD_FILE_WRITE)
- {
- Serial.println("Writing file...");
- SD_card_fs::append_to_file(uploadfile.buf, uploadfile.currentSize);
- }
- else if (uploadfile.status == UPLOAD_FILE_END)
- {
- Serial.print("Upload Size: ");
- Serial.println(uploadfile.totalSize);
- SD_card_fs::close_file();
-
- send_HTML_page(HTML_data::upload_finished_str);
-
- epd_spi_pinout pinout{
-
- }
- EPD_SPI_interface epd_display{}
- BMP my_bitmap{filename.c_str()};
-
-
- }
- else
- {
- server.send(500, "text/plain", "500: couldn't create file");
- }
-}
-
-namespace Web_server
-{
- void init_server()
- {
- server.on("/", home_page);
- server.on("/upload", file_upload);
- server.on("/fupload", HTTP_POST,[](){server.send(200);}, handle_file_upload);
- //server.on("/delete", file_delete);
- server.on("/dir", dir_page);
- Serial.println("Web-server starting!");
- server.begin();
- }
-
- void init_wifi()
- {
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, passw);
- Serial.println("Connecting");
-
- while(WiFi.status() != WL_CONNECTED){
- Serial.print(".");
- delay(500);
- }
-
- Serial.println("\nConnected to the WiFi network");
- Serial.print("Local ESP32 IP: ");
- Serial.println(WiFi.localIP());
- }
-
- void handle_client()
- {
- server.handleClient();
- }
-};
-
-
-
-
-
-
+#include "include/web_server.h"\r
+#include "include/web_HTML.h"\r
+#include "include/sd_card.h"\r
+\r
+#ifdef ESP8266\r
+ static ESP8266WebServer server{SERVER_PORT};\r
+#else\r
+ static ESP32WebServer server{SERVER_PORT};\r
+#endif\r
+\r
+static void send_HTML_page(const char* webpage)\r
+{\r
+ server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); \r
+ server.sendHeader("Pragma", "no-cache"); \r
+ server.sendHeader("Expires", "-1"); \r
+ server.setContentLength(CONTENT_LENGTH_UNKNOWN); \r
+ server.send(200, "text/html", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. \r
+ server.sendContent(HTML_data::append_page_header);\r
+\r
+ server.sendContent(webpage);\r
+ server.sendContent(HTML_data::append_page_footer);\r
+ server.client().stop();\r
+}\r
+\r
+static void home_page()\r
+{\r
+ send_HTML_page(HTML_data::home_page_str);\r
+}\r
+\r
+static void dir_page()\r
+{\r
+ // Only lists files and directories in root "/", no recursion into folders...\r
+\r
+ std::unique_ptr<File> root = SD_card_fs::get_file("/");\r
+ if (*root)\r
+ {\r
+ root->rewindDirectory();\r
+ String web_content {HTML_data::dir_page_str};\r
+\r
+ File file = root->openNextFile();\r
+ while (file)\r
+ {\r
+ // Serial.print(String(file.name())+"\t");\r
+ web_content += "<tr><td>" + String(file.name()) + "</td>";\r
+ Serial.print(String(file.isDirectory() ? "Dir " : "File ") + String(file.name()) + "\t");\r
+ web_content += "<td>" + String(file.isDirectory() ? "Dir" : "File") + "</td>";\r
+ int bytes = file.size();\r
+ String fsize = "";\r
+ if (bytes < 1024)\r
+ fsize = String(bytes) + " B";\r
+ else if (bytes < (1024 * 1024))\r
+ fsize = String(bytes / 1024.0, 3) + " KB";\r
+ else if (bytes < (1024 * 1024 * 1024))\r
+ fsize = String(bytes / 1024.0 / 1024.0, 3) + " MB";\r
+ else\r
+ fsize = String(bytes / 1024.0 / 1024.0 / 1024.0, 3) + " GB";\r
+ web_content += "<td>" + fsize + "</td></tr>";\r
+ Serial.println(String(fsize));\r
+\r
+ file = root->openNextFile();\r
+ }\r
+ web_content += "</table>";\r
+ send_HTML_page(web_content.c_str());\r
+ root->close();\r
+ }\r
+ else\r
+ {\r
+ send_HTML_page("<h3>No Files Found</h3>");\r
+ }\r
+}\r
+\r
+static void file_upload()\r
+{\r
+ send_HTML_page(HTML_data::file_upload_str);\r
+}\r
+\r
+static void handle_file_upload()\r
+{\r
+ HTTPUpload &uploadfile = server.upload();\r
+\r
+ if (uploadfile.status == UPLOAD_FILE_START)\r
+ {\r
+ String filename {uploadfile.filename};\r
+\r
+ if (!filename.startsWith("/"))\r
+ filename = "/" + filename;\r
+\r
+ Serial.print("Upload File Name: ");\r
+ Serial.println(filename);\r
+ SD_card_fs::delete_file(filename.c_str()); // Remove a previous version, otherwise data is appended the file again\r
+ SD_card_fs::open_file(filename.c_str()); // Open the file for writing in SPIFFS (create it, if doesn't exist)\r
+ }\r
+ else if (uploadfile.status == UPLOAD_FILE_WRITE)\r
+ {\r
+ Serial.println("Writing file...");\r
+ SD_card_fs::append_to_file(uploadfile.buf, uploadfile.currentSize);\r
+ }\r
+ else if (uploadfile.status == UPLOAD_FILE_END)\r
+ {\r
+ Serial.print("Upload Size: ");\r
+ Serial.println(uploadfile.totalSize);\r
+ SD_card_fs::close_file();\r
+\r
+ send_HTML_page(HTML_data::upload_finished_str);\r
+\r
+ epd_spi_pinout pinout{\r
+ \r
+ }\r
+ EPD_SPI_interface epd_display{}\r
+ BMP my_bitmap{filename.c_str()};\r
+\r
+\r
+ }\r
+ else \r
+ {\r
+ server.send(500, "text/plain", "500: couldn't create file");\r
+ }\r
+}\r
+\r
+namespace Web_server\r
+{\r
+ void init_server()\r
+ {\r
+ server.on("/", home_page);\r
+ server.on("/upload", file_upload);\r
+ server.on("/fupload", HTTP_POST,[](){server.send(200);}, handle_file_upload);\r
+ //server.on("/delete", file_delete);\r
+ server.on("/dir", dir_page);\r
+ Serial.println("Web-server starting!");\r
+ server.begin();\r
+ }\r
+\r
+ void init_wifi()\r
+ {\r
+ WiFi.mode(WIFI_STA);\r
+ WiFi.begin(ssid, passw);\r
+ Serial.println("Connecting");\r
+\r
+ while(WiFi.status() != WL_CONNECTED){\r
+ Serial.print(".");\r
+ delay(500);\r
+ }\r
+\r
+ Serial.println("\nConnected to the WiFi network");\r
+ Serial.print("Local ESP32 IP: ");\r
+ Serial.println(WiFi.localIP());\r
+ }\r
+\r
+ void handle_client()\r
+ {\r
+ server.handleClient();\r
+ }\r
+};\r
+\r
+\r
+\r
+\r
+\r
+\r