This commit is contained in:
2019-05-04 12:51:55 +02:00
committed by feedc0de
parent 9e1d88db16
commit 531a10fa19
5 changed files with 96 additions and 9 deletions
+44 -2
View File
@@ -20,6 +20,9 @@ bool rotatePattern = true;
void setup()
{
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.begin(WIFI_SSID, WIFI_PASSWD);
server.on("/", HTTP_GET, []()
@@ -43,11 +46,11 @@ void setup()
"}"
"</style>"
"<title>Hello, world!</title>"
"<title>LED-Control</title>"
"</head>"
"<body>"
"<div class=\"container\">"
"<h1>Hello, world!</h1>"
"<h1>LED-Control</h1>"
"<p>"
"<a href=\"setPower?val=true\" id=\"enablePower\" class=\"softLink\">Turn LEDs on</a> "
"<a href=\"setPower?val=false\" id=\"disablePower\" class=\"softLink\">Turn LEDs off</a> "
@@ -132,6 +135,45 @@ void setup()
);
});
server.on("/update", HTTP_GET, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/html",
"<form method=\"POST\" action=\"/update\" enctype=\"multipart/form-data\">"
"<input type=\"file\" name=\"update\" />"
"<button type=\"submit\">Install</button>"
"</form>");
});
server.on("/update", HTTP_POST, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
ESP.restart();
}, []() {
HTTPUpload& upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.setDebugOutput(true);
Serial.printf("Update: %s\n", upload.filename.c_str());
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace)) { //start with max available size
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Update.printError(Serial);
}
Serial.setDebugOutput(false);
}
yield();
});
server.on("/status", HTTP_GET, []()
{
server.sendHeader("Connection", "close");