Skip to content

Commit 01a7e64

Browse files
committed
OTA: Reboot task, because of missing loop()
1 parent eb32fbe commit 01a7e64

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/helpers/ESP32Board.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010

1111
#include <SPIFFS.h>
1212

13+
// Workaround for missing loop() in Board class
14+
// It is less ugly than change API of whole
15+
// project just because of one OTA reboot routine
16+
// used probably once per month
17+
static void otaRebootTask(void*) {
18+
vTaskDelay(pdMS_TO_TICKS(2000));
19+
esp_restart();
20+
}
21+
1322
bool ESP32Board::startOTAUpdate(const char* id, char reply[]) {
1423
inhibit_sleep = true; // prevent sleep during OTA
1524
WiFi.softAP("MeshCore-OTA", NULL);
@@ -32,6 +41,15 @@ bool ESP32Board::startOTAUpdate(const char* id, char reply[]) {
3241
});
3342

3443
ElegantOTA.begin(server); // Start ElegantOTA
44+
ElegantOTA.setAutoReboot(false);
45+
ElegantOTA.onEnd([](bool success) {
46+
if (success) {
47+
// Can not use ESP.restart() here, because
48+
// this callback is called before HTTP response
49+
// so we need create separated task (thread)
50+
xTaskCreate(otaRebootTask, "ota-reboot", 2048, NULL, 1, NULL);
51+
}
52+
});
3553
server->begin();
3654

3755
return true;

0 commit comments

Comments
 (0)