just some reformatting - no code changes

This commit is contained in:
Joe Tretter
2022-07-05 14:18:19 -05:00
parent ce2b8a37b0
commit 8105b786a9

View File

@@ -2,8 +2,8 @@
Source:
https://randomnerdtutorials.com/esp32-over-the-air-ota-programming/
To update the firmware with Platform IO, do a build and then upload in the web interface the file
.pio/build/esp32doit-devkit-v1/firmware.bin
To update the firmware with Platform IO, do a build and then upload in the web
interface the file .pio/build/esp32doit-devkit-v1/firmware.bin
*/
@@ -13,11 +13,11 @@ To update the firmware with Platform IO, do a build and then upload in the web i
* Complete Project Details http://randomnerdtutorials.com
*/
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Update.h>
#include <WebServer.h>
#include <WiFi.h>
#include <WiFiClient.h>
const char* host = "esp32ota";
const char* ssid = "JoNelsDarlings";
@@ -81,8 +81,11 @@ const char* loginIndex =
*/
const char* serverIndex =
"<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>"
"<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>"
"<script "
"src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></"
"script>"
"<form method='POST' action='#' enctype='multipart/form-data' "
"id='upload_form'>"
"<input type='file' name='update'>"
"<input type='submit' value='Update'>"
"</form>"
@@ -135,12 +138,12 @@ void setup(void) {
delay(500);
Serial.print(".");
if (wifiConnAttements++ > 120) {
Serial.println("<Wifi not connecting after 120 attmepts (1 min.) - rebooting>");
Serial.println(
"<Wifi not connecting after 120 attmepts (1 min.) - rebooting>");
ESP.restart();
}
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
@@ -165,25 +168,32 @@ void setup(void) {
server.send(200, "text/html", serverIndex);
});
/*handling uploading firmware file */
server.on("/update", HTTP_POST, []() {
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.printf("Update: %s\n", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
if (!Update.begin(
UPDATE_SIZE_UNKNOWN)) { // start with max available size
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
/* flashing firmware to ESP*/
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
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);
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);
}