FIrst steps towards file serving with spiffs,
but need to implement remote replace of spiffs files.
This commit is contained in:
41
data/index.html
Normal file
41
data/index.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<H1>SPIFF!abb</H1>
|
||||
<form name='loginForm'>
|
||||
<table width='20%' bgcolor='A09F9F' align='center'>
|
||||
<tr>
|
||||
<td colspan=2>
|
||||
<center><font size=4><b>ESP32 Login Page</b></font></center>
|
||||
<br>
|
||||
</td>
|
||||
<br>
|
||||
<br>
|
||||
</tr>
|
||||
<td>Username:</td>
|
||||
<td><input type='text' size=25 name='userid'><br></td>
|
||||
</tr>
|
||||
<br>
|
||||
<br>
|
||||
<tr>
|
||||
<td>Password:</td>
|
||||
<td><input type='Password' size=25 name='pwd'><br></td>
|
||||
<br>
|
||||
<br>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input type='submit' onclick='check(this.form)' value='Login'></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<script>
|
||||
function check(form)
|
||||
{
|
||||
if(form.userid.value=='admin' && form.pwd.value=='admin')
|
||||
{
|
||||
window.open('/serverIndex')
|
||||
}
|
||||
else
|
||||
{
|
||||
alert('Error Password or Username')/*displays error message*/
|
||||
}
|
||||
}
|
||||
</script>;
|
||||
|
||||
0
data/update.html
Normal file
0
data/update.html
Normal file
26
src/main.cpp
26
src/main.cpp
@@ -5,6 +5,7 @@
|
||||
#include <WebServer.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <Update.h>
|
||||
#include <SPIFFS.h>
|
||||
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user