maintenance mode (error handling improved)
This commit is contained in:
parent
23b713919c
commit
6b3e8d00c2
@ -11,7 +11,6 @@
|
|||||||
#include <WebServer.h>
|
#include <WebServer.h>
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
|
|
||||||
void IRAM_ATTR exit_boot_menu(void);
|
|
||||||
void start_boot_menu(void);
|
void start_boot_menu(void);
|
||||||
|
|
||||||
#endif // BOOT_H
|
#endif // BOOT_H
|
||||||
|
37
src/boot.cpp
37
src/boot.cpp
@ -4,11 +4,6 @@
|
|||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char TAG[] = __FILE__;
|
static const char TAG[] = __FILE__;
|
||||||
|
|
||||||
void IRAM_ATTR exit_boot_menu() {
|
|
||||||
RTC_runmode = RUNMODE_NORMAL;
|
|
||||||
esp_restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
// start local web server with user interface for maintenance mode
|
// start local web server with user interface for maintenance mode
|
||||||
// used for manually uploading a firmware file via wifi
|
// used for manually uploading a firmware file via wifi
|
||||||
|
|
||||||
@ -26,9 +21,11 @@ void start_boot_menu(void) {
|
|||||||
const char *ssid = WIFI_SSID;
|
const char *ssid = WIFI_SSID;
|
||||||
const char *password = WIFI_PASS;
|
const char *password = WIFI_PASS;
|
||||||
|
|
||||||
|
RTC_runmode = RUNMODE_NORMAL;
|
||||||
|
|
||||||
hw_timer_t *timer = NULL;
|
hw_timer_t *timer = NULL;
|
||||||
timer = timerBegin(2, 80, true); // timer 2, div 80, countup
|
timer = timerBegin(2, 80, true); // timer 2, div 80, countup
|
||||||
timerAttachInterrupt(timer, &exit_boot_menu, true); // attach callback
|
timerAttachInterrupt(timer, &esp_restart, true); // callback device reset
|
||||||
timerAlarmWrite(timer, BOOTDELAY * 1000000, false); // set time in us
|
timerAlarmWrite(timer, BOOTDELAY * 1000000, false); // set time in us
|
||||||
timerAlarmEnable(timer); // enable interrupt
|
timerAlarmEnable(timer); // enable interrupt
|
||||||
|
|
||||||
@ -46,7 +43,8 @@ void start_boot_menu(void) {
|
|||||||
"<br>"
|
"<br>"
|
||||||
"</tr>"
|
"</tr>"
|
||||||
"<tr>"
|
"<tr>"
|
||||||
"<td><input type='submit' onclick='start(this.form)' value='Start'></td>"
|
"<td><input type='submit' onclick='start(this.form)' "
|
||||||
|
"value='Start'></td>"
|
||||||
"</tr>"
|
"</tr>"
|
||||||
"</table>"
|
"</table>"
|
||||||
"</form>"
|
"</form>"
|
||||||
@ -95,14 +93,26 @@ void start_boot_menu(void) {
|
|||||||
"</script>";
|
"</script>";
|
||||||
|
|
||||||
// Connect to WiFi network
|
// Connect to WiFi network
|
||||||
WiFi.mode(WIFI_STA);
|
// workaround applied here to avoid WIFI_AUTH failure
|
||||||
WiFi.begin(ssid, password);
|
// see https://github.com/espressif/arduino-esp32/issues/2501
|
||||||
|
|
||||||
// Wait for connection
|
WiFi.disconnect(true, true);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
|
// 1st try
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
while (WiFi.status() == WL_DISCONNECTED) {
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2nd try
|
||||||
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MDNS.begin(host);
|
MDNS.begin(host);
|
||||||
|
|
||||||
server.on("/", HTTP_GET, [&server, &loginMenu]() {
|
server.on("/", HTTP_GET, [&server, &loginMenu]() {
|
||||||
@ -122,8 +132,9 @@ void start_boot_menu(void) {
|
|||||||
[&server]() {
|
[&server]() {
|
||||||
server.sendHeader("Connection", "close");
|
server.sendHeader("Connection", "close");
|
||||||
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
|
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
|
||||||
|
RTC_runmode = Update.hasError() ? RUNMODE_NORMAL : RUNMODE_POWERCYCLE;
|
||||||
WiFi.disconnect(true, true);
|
WiFi.disconnect(true, true);
|
||||||
do_reset(false); // coldstart
|
esp_restart();
|
||||||
},
|
},
|
||||||
[&server, &timer]() {
|
[&server, &timer]() {
|
||||||
HTTPUpload &upload = server.upload();
|
HTTPUpload &upload = server.upload();
|
||||||
|
Loading…
Reference in New Issue
Block a user