Skip to content

Commit

Permalink
- Added setAutoReboot
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushsharma82 committed Sep 23, 2023
1 parent 49b6f64 commit e9204cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/ElegantOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/ElegantOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;

Expand Down

0 comments on commit e9204cf

Please sign in to comment.