diff --git a/src/WebOTA.cpp b/src/WebOTA.cpp index 0620b83..7d7347a 100644 --- a/src/WebOTA.cpp +++ b/src/WebOTA.cpp @@ -148,3 +148,16 @@ int init_web_ota(WebServer *server) { server->begin(); } + +// If the MCU is in a delay() it cannot respond to HTTP OTA requests +// We do a "fake" looping delay and listen for incoming HTTP requests while waiting +void webota_delay(int ms) { + int last = millis(); + + extern WebServer OTAServer; + + while ((millis() - last) < ms) { + OTAServer.handleClient(); + delay(5); + } +} diff --git a/src/WebOTA.h b/src/WebOTA.h index d0e425a..0c94026 100644 --- a/src/WebOTA.h +++ b/src/WebOTA.h @@ -1,6 +1,9 @@ #include +extern WebServer OTAServer; + int init_wifi(const char *ssid, const char *password, const char *mdns_hostname); String ip2string(IPAddress ip); int init_mdns(const char *host); int init_web_ota(WebServer *server); +void webota_delay(int ms);