Skip to content

Commit 56969ff

Browse files
committed
Code cleanup and little updates
1 parent 7cf4049 commit 56969ff

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

src/main.cpp

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,59 @@ static String getChipIDStr() {
4444
}
4545

4646
static void start_web_server() {
47-
webServer.on("/cancel", HTTP_POST, [&]() {
47+
webServer.onNotFound([]() {
48+
webServer.sendHeader("Location", "/");
49+
webServer.send(302, "text/plain", "");
50+
});
51+
52+
webServer.on("/chipspecs", HTTP_GET, [&]() {
53+
String chipSpecs = ESP.getChipModel();
54+
chipSpecs += " (" + String(ESP.getFlashChipSize() >> 20) + " MB)";
55+
webServer.send(200, "text/plain", chipSpecs.c_str());
56+
});
57+
58+
webServer.on("/sbversion", HTTP_GET, [&]() {
59+
webServer.send(200, "text/plain", __COMPILED_APP_VERSION__);
60+
});
61+
62+
webServer.on(
63+
"/cancel",
64+
HTTP_POST,
65+
[&]() {
4866
webServer.send(200, "text/plain", cancelResponse);
4967
webServer.client().stop();
50-
delay(500);
51-
ESP.restart(); }, [&]() {});
68+
delay(1000);
69+
ESP.restart();
70+
},
71+
[&]() {
72+
});
5273

5374
webServer.on("/", HTTP_GET, [&]() {
5475
webServer.sendHeader("Content-Encoding", "gzip");
5576
webServer.send_P(200, "text/html", reinterpret_cast<const char*>(update_html_start), update_html_end - update_html_start);
5677
});
5778

58-
webServer.on("/", HTTP_POST, [&]() {
79+
webServer.on(
80+
"/",
81+
HTTP_POST,
82+
[&]() {
5983
if (Update.hasError()) {
6084
webServer.send(500, "text/plain", "Update error: " + updaterError);
6185
} else {
6286
webServer.client().setNoDelay(true);
6387
webServer.send(200, "text/plain", successResponse);
6488
webServer.client().stop();
65-
delay(500);
89+
delay(1000);
6690
ESP.restart();
67-
} }, [&]() {
91+
} },
92+
[&]() {
6893
// handler for the file upload, gets the sketch bytes, and writes
6994
// them through the Update object
7095
HTTPUpload& upload = webServer.upload();
7196

7297
if (upload.status == UPLOAD_FILE_START) {
7398
updaterError.clear();
74-
int otaMode = U_FLASH;
75-
if (webServer.hasArg("mode") && webServer.arg("mode") == "1") {
76-
otaMode = U_SPIFFS;
77-
}
99+
int otaMode = webServer.hasArg("mode") && webServer.arg("mode") == "1" ? U_SPIFFS : U_FLASH;
78100
LOG("Mode: %d\n", otaMode);
79101
if (!Update.begin(UPDATE_SIZE_UNKNOWN, otaMode)) { // start with max available size
80102
Update.printError(updaterError);
@@ -90,22 +112,7 @@ static void start_web_server() {
90112
} else if (upload.status == UPLOAD_FILE_ABORTED) {
91113
Update.end();
92114
}
93-
delay(0); });
94-
95-
webServer.on("/chipspecs", HTTP_GET, [&]() {
96-
String chipSpecs = ESP.getChipModel();
97-
chipSpecs += " (" + String(ESP.getFlashChipSize() >> 20) + " MB)";
98-
webServer.send(200, "text/plain", chipSpecs.c_str());
99-
});
100-
101-
webServer.on("/sbversion", HTTP_GET, [&]() {
102-
webServer.send(200, "text/plain", __COMPILED_APP_VERSION__);
103-
});
104-
105-
webServer.onNotFound([]() {
106-
webServer.sendHeader("Location", "/");
107-
webServer.send(302, "text/plain", "");
108-
});
115+
});
109116

110117
webServer.begin();
111118

0 commit comments

Comments
 (0)