Skip to content

Commit

Permalink
Merge pull request #62 from theelims/task-isolation-restart-sleep
Browse files Browse the repository at this point in the history
Isolate non-returning functions in new tasks
  • Loading branch information
theelims authored Dec 20, 2024
2 parents 86e165f + 7140b48 commit f44de68
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
14 changes: 11 additions & 3 deletions lib/framework/RestartService.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <WiFi.h>

#include <ESPmDNS.h>
#include <PsychicHttp.h>
#include <SecurityManager.h>

Expand All @@ -31,9 +32,16 @@ class RestartService

static void restartNow()
{
WiFi.disconnect(true);
delay(500);
ESP.restart();
xTaskCreate(
[](void *pvParams) {
delay(250);
MDNS.end();
delay(100);
WiFi.disconnect(true);
delay(500);
ESP.restart();
},
"Restart task", 4096, nullptr, 10, nullptr);
}

private:
Expand Down
11 changes: 6 additions & 5 deletions lib/framework/SleepService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ void SleepService::sleepNow()
Serial.println("Good by!");
#endif

// Just to be sure
delay(100);

// Hibernate
esp_deep_sleep_start();
xTaskCreate(
[](void *pvParams) {
delay(200);
esp_deep_sleep_start();
},
"Sleep task", 4096, nullptr, 10, nullptr);
}

0 comments on commit f44de68

Please sign in to comment.