diff --git a/src/ElegantOTA.cpp b/src/ElegantOTA.cpp index 33f3df0..6f677bb 100644 --- a/src/ElegantOTA.cpp +++ b/src/ElegantOTA.cpp @@ -206,8 +206,10 @@ void ElegantOTAClass::begin(ELEGANTOTA_WEBSERVER *server, const char * username, request->send(response); // Set reboot flag if (!Update.hasError()) { - _reboot_request_millis = millis(); - _reboot = true; + if (_auto_reboot) { + _reboot_request_millis = millis(); + _reboot = true; + } } }, [&](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { //Upload handler chunks in data @@ -256,8 +258,10 @@ void ElegantOTAClass::begin(ELEGANTOTA_WEBSERVER *server, const char * username, _server->send((Update.hasError()) ? 400 : 200, "text/plain", (Update.hasError()) ? _update_error_str.c_str() : "OK"); // Set reboot flag if (!Update.hasError()) { - _reboot_request_millis = millis(); - _reboot = true; + if (_auto_reboot) { + _reboot_request_millis = millis(); + _reboot = true; + } } }, [&](){ // Actual OTA Download @@ -313,6 +317,10 @@ void ElegantOTAClass::clearAuth(){ _authenticate = false; } +void ElegantOTAClass::setAutoReboot(bool enable){ + _auto_reboot = enable; +} + void ElegantOTAClass::loop() { // Check if 2 seconds have passed since _reboot_request_millis was set if (_reboot && millis() - _reboot_request_millis > 2000) { diff --git a/src/ElegantOTA.h b/src/ElegantOTA.h index 96e9206..a5ece98 100644 --- a/src/ElegantOTA.h +++ b/src/ElegantOTA.h @@ -100,6 +100,7 @@ class ElegantOTAClass{ void setAuth(const char * username, const char * password); void clearAuth(); + void setAutoReboot(bool enable); void loop(); void onStart(void callable(void)); @@ -113,6 +114,7 @@ class ElegantOTAClass{ char _username[64]; char _password[64]; + bool _auto_reboot = false; bool _reboot = false; unsigned long _reboot_request_millis = 0;