@@ -44,37 +44,59 @@ static String getChipIDStr() {
44
44
}
45
45
46
46
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
+ [&]() {
48
66
webServer.send (200 , " text/plain" , cancelResponse);
49
67
webServer.client ().stop ();
50
- delay (500 );
51
- ESP.restart (); }, [&]() {});
68
+ delay (1000 );
69
+ ESP.restart ();
70
+ },
71
+ [&]() {
72
+ });
52
73
53
74
webServer.on (" /" , HTTP_GET, [&]() {
54
75
webServer.sendHeader (" Content-Encoding" , " gzip" );
55
76
webServer.send_P (200 , " text/html" , reinterpret_cast <const char *>(update_html_start), update_html_end - update_html_start);
56
77
});
57
78
58
- webServer.on (" /" , HTTP_POST, [&]() {
79
+ webServer.on (
80
+ " /" ,
81
+ HTTP_POST,
82
+ [&]() {
59
83
if (Update.hasError ()) {
60
84
webServer.send (500 , " text/plain" , " Update error: " + updaterError);
61
85
} else {
62
86
webServer.client ().setNoDelay (true );
63
87
webServer.send (200 , " text/plain" , successResponse);
64
88
webServer.client ().stop ();
65
- delay (500 );
89
+ delay (1000 );
66
90
ESP.restart ();
67
- } }, [&]() {
91
+ } },
92
+ [&]() {
68
93
// handler for the file upload, gets the sketch bytes, and writes
69
94
// them through the Update object
70
95
HTTPUpload& upload = webServer.upload ();
71
96
72
97
if (upload.status == UPLOAD_FILE_START) {
73
98
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;
78
100
LOG (" Mode: %d\n " , otaMode);
79
101
if (!Update.begin (UPDATE_SIZE_UNKNOWN, otaMode)) { // start with max available size
80
102
Update.printError (updaterError);
@@ -90,22 +112,7 @@ static void start_web_server() {
90
112
} else if (upload.status == UPLOAD_FILE_ABORTED) {
91
113
Update.end ();
92
114
}
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
+ });
109
116
110
117
webServer.begin ();
111
118
0 commit comments