-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
253 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ build_flags = | |
-D FT_NTP=1 | ||
-D FT_OTA=1 | ||
-D FT_UPLOAD_FIRMWARE=1 | ||
-D FT_SLEEP=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* ESP32 SvelteKit | ||
* | ||
* A simple, secure and extensible framework for IoT projects for ESP32 platforms | ||
* with responsive Sveltekit front-end built with TailwindCSS and DaisyUI. | ||
* https://github.com/theelims/ESP32-sveltekit | ||
* | ||
* Copyright (C) 2023 theelims | ||
* | ||
* All Rights Reserved. This software may be modified and distributed under | ||
* the terms of the LGPL v3 license. See the LICENSE file for details. | ||
**/ | ||
|
||
#include <SleepService.h> | ||
|
||
// Definition of static member variable | ||
void (*SleepService::_callbackSleep)() = nullptr; | ||
|
||
SleepService::SleepService(AsyncWebServer *server, SecurityManager *securityManager) | ||
{ | ||
server->on(SLEEP_SERVICE_PATH, | ||
HTTP_POST, | ||
securityManager->wrapRequest(std::bind(&SleepService::sleep, this, std::placeholders::_1), | ||
AuthenticationPredicates::IS_AUTHENTICATED)); | ||
} | ||
|
||
void SleepService::sleep(AsyncWebServerRequest *request) | ||
{ | ||
request->onDisconnect(SleepService::sleepNow); | ||
request->send(200); | ||
} | ||
|
||
void SleepService::sleepNow() | ||
{ | ||
Serial.println("Going into deep sleep now"); | ||
// Callback for main code sleep preparation | ||
if (_callbackSleep != nullptr) | ||
{ | ||
_callbackSleep(); | ||
} | ||
delay(100); | ||
|
||
MDNS.end(); | ||
delay(100); | ||
|
||
WiFi.disconnect(true); | ||
delay(500); | ||
|
||
// Prepare ESP for sleep | ||
uint64_t bitmask = (uint64_t)1 << (WAKEUP_PIN_NUMBER); | ||
esp_sleep_enable_ext1_wakeup(bitmask, (esp_sleep_ext1_wakeup_mode_t)WAKEUP_SIGNAL); | ||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); | ||
|
||
Serial.println("Good by!"); | ||
|
||
// Just to be sure | ||
delay(100); | ||
|
||
// Hibernate | ||
esp_deep_sleep_start(); | ||
} |
Oops, something went wrong.