Skip to content

Commit

Permalink
Move different restart calls into one method
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Aug 25, 2023
1 parent b88030f commit 77a9009
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions include/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class Utils {
static uint32_t getChipId();
static uint64_t generateDtuSerial();
static int getTimezoneOffset();
static void restartDtu();
};
10 changes: 9 additions & 1 deletion src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ int Utils::getTimezoneOffset()
gmt = mktime(ptm);

return static_cast<int>(difftime(rawtime, gmt));
}
}

void Utils::restartDtu()
{
yield();
delay(1000);
yield();
ESP.restart();
}
8 changes: 3 additions & 5 deletions src/WebApi_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
#include "WebApi_config.h"
#include "Configuration.h"
#include "Utils.h"
#include "WebApi.h"
#include "WebApi_errors.h"
#include <AsyncJson.h>
Expand Down Expand Up @@ -114,7 +115,7 @@ void WebApiConfigClass::onConfigDelete(AsyncWebServerRequest* request)
request->send(response);

LittleFS.remove(CONFIG_FILENAME);
ESP.restart();
Utils::restartDtu();
}

void WebApiConfigClass::onConfigListGet(AsyncWebServerRequest* request)
Expand Down Expand Up @@ -157,10 +158,7 @@ void WebApiConfigClass::onConfigUploadFinish(AsyncWebServerRequest* request)
response->addHeader("Connection", "close");
response->addHeader("Access-Control-Allow-Origin", "*");
request->send(response);
yield();
delay(1000);
yield();
ESP.restart();
Utils::restartDtu();
}

void WebApiConfigClass::onConfigUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final)
Expand Down
6 changes: 2 additions & 4 deletions src/WebApi_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Configuration.h"
#include "Display_Graphic.h"
#include "PinMapping.h"
#include "Utils.h"
#include "WebApi.h"
#include "WebApi_errors.h"
#include "helper.h"
Expand Down Expand Up @@ -169,9 +170,6 @@ void WebApiDeviceClass::onDeviceAdminPost(AsyncWebServerRequest* request)
request->send(response);

if (performRestart) {
yield();
delay(1000);
yield();
ESP.restart();
Utils::restartDtu();
}
}
6 changes: 2 additions & 4 deletions src/WebApi_firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "WebApi_firmware.h"
#include "Configuration.h"
#include "Update.h"
#include "Utils.h"
#include "WebApi.h"
#include "helper.h"
#include <AsyncJson.h>
Expand Down Expand Up @@ -42,10 +43,7 @@ void WebApiFirmwareClass::onFirmwareUpdateFinish(AsyncWebServerRequest* request)
response->addHeader("Connection", "close");
response->addHeader("Access-Control-Allow-Origin", "*");
request->send(response);
yield();
delay(1000);
yield();
ESP.restart();
Utils::restartDtu();
}

void WebApiFirmwareClass::onFirmwareUpdateUpload(AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final)
Expand Down
6 changes: 2 additions & 4 deletions src/WebApi_maintenance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "WebApi_maintenance.h"
#include "Utils.h"
#include "WebApi.h"
#include "WebApi_errors.h"
#include <AsyncJson.h>
Expand Down Expand Up @@ -75,10 +76,7 @@ void WebApiMaintenanceClass::onRebootPost(AsyncWebServerRequest* request)

response->setLength();
request->send(response);
yield();
delay(1000);
yield();
ESP.restart();
Utils::restartDtu();
} else {
retMsg["message"] = "Reboot cancled!";
retMsg["code"] = WebApiError::MaintenanceRebootCancled;
Expand Down

0 comments on commit 77a9009

Please sign in to comment.