From 3e7a9a40a01aee402dadcddfa26a62de56928f93 Mon Sep 17 00:00:00 2001 From: Joe Tretter Date: Thu, 23 Jun 2022 16:35:11 -0500 Subject: [PATCH] FIrst steps towards file serving with spiffs, but need to implement remote replace of spiffs files. --- data/index.html | 41 +++++++++++++++++++++++++++++++++++++++++ data/update.html | 0 src/main.cpp | 26 ++++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 data/index.html create mode 100644 data/update.html diff --git a/data/index.html b/data/index.html new file mode 100644 index 0000000..502557f --- /dev/null +++ b/data/index.html @@ -0,0 +1,41 @@ +

SPIFF!abb

+
+ + + +
+
+ + + + +
+
+ + + +
+
+ + + + +
+
ESP32 Login Page
+
+
Username:
Password:
+
+; + \ No newline at end of file diff --git a/data/update.html b/data/update.html new file mode 100644 index 0000000..e69de29 diff --git a/src/main.cpp b/src/main.cpp index 1fcaf29..845fef0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include const char* host = "esp32gragedoor"; const char* ssid = "JoNelsDarlings"; @@ -163,19 +164,40 @@ void setup(void) { /*use mdns for host name resolution*/ if (!MDNS.begin(host)) { //http://esp32garagedoor.local - Serial.println("Error setting up MDNS responder!"); while (1) { + Serial.println("Error setting up MDNS responder!"); delay(1000); } } Serial.println("mDNS responder started"); + if(!SPIFFS.begin(true)){ + while (1) { + Serial.println("An Error has occurred while mounting SPIFFS"); + delay(1000); + } + } + send_notification("garagedoor.rebooted.livorno.address"); /*return index page which is stored in serverIndex */ server.on("/", HTTP_GET, []() { server.sendHeader("Connection", "close"); - server.send(200, "text/html", loginIndex); + File file = SPIFFS.open("/index.html"); + + String thePage = ""; + + if (!file) { + Serial.println("There was a problem opening the file for reading."); + thePage += "There was a problem opening the file for reading."; + } + + while (file.available()) { + thePage+=String((char)file.read()); + } + + file.close(); + server.send(200, "text/html", thePage); }); server.on("/serverIndex", HTTP_GET, []() { server.sendHeader("Connection", "close");