1#ifndef _LONGDEEPSLEEP_H_
2#define _LONGDEEPSLEEP_H_
5#include "MockTestSetup.h"
7#include <ESP8266WiFi.h>
10#include <include/WiFiState.h>
63 LongDeepSleep(
CloneWorkaround param_cloneWorkaround,
const char* ssid =
nullptr,
const char* password =
nullptr, NTPClient* ntpClient =
nullptr);
72 LongDeepSleep(
const char* ssid =
nullptr,
const char* password =
nullptr, NTPClient* ntpClient =
nullptr)
84 int checkWakeUp(uint32_t toleranceSec = 0, uint16_t failureSleepSecs = 0);
131 maxQuickConnectCycles = quickConnectCycles;
132 maxWifiWaitCycles = wifiWaitCycles;
161 void saveRTCAndCallLongDeepSleep(uint64_t sleepTimeSec);
162 bool readFromRTCmemory();
163 void writeRTCmemory();
164 void saveWifiInformation();
168 uint32_t calculateCRC32(
const uint8_t *data,
size_t length);
170 bool RTCmemoryValid =
false;
171 int sleepTimeUntilWifiReconnectSec = 60 * 60;
173 uint16_t maxQuickConnectCycles = 20;
174 uint16_t maxWifiWaitCycles = 2000;
176 const char* wifiSsid;
177 const char* wifiPassword;
178 NTPClient* timeClient;
187 uint32_t rebootCounter;
188 uint64_t remainingSleepTimeUs;
189 uint32_t sleepUntilEpocheTime;
void changeWaitCycles(uint16_t quickConnectCycles, uint16_t wifiWaitCycles)
Customizes connection wait cycles.
Definition LongDeepSleep.h:129
LongDeepSleep(CloneWorkaround param_cloneWorkaround, const char *ssid=nullptr, const char *password=nullptr, NTPClient *ntpClient=nullptr)
Second constructor for clone modules with deep sleep problems.
Definition LongDeepSleep.cpp:7
void performLongDeepSleep(uint64_t sleepTimeSec)
Sleep for a relative amount of time (seconds).
Definition LongDeepSleep.cpp:155
void resetRebootCounter()
Releases WiFi to conserve power.
Definition LongDeepSleep.h:149
static uint32_t UsedRTCDataSize()
Releases WiFi to conserve power.
Definition LongDeepSleep.h:158
void restoreWifi(uint16_t failureSleepSecs=0)
Restores WiFi after wake-up from deep sleep.
Definition LongDeepSleep.cpp:187
int checkWakeUp(uint32_t toleranceSec=0, uint16_t failureSleepSecs=0)
Checks whether the device woke up from deep sleep and handles state.
Definition LongDeepSleep.cpp:14
CloneWorkaround
Differrent types of workarounds for deepsleep problems with clone modules.
Definition LongDeepSleep.h:47
@ UNKNOWN
Definition LongDeepSleep.h:51
@ WEMOS_D1_V3_CLONE
This worked for my Wemos D1 mini V3 clones.
Definition LongDeepSleep.h:49
@ NO_WORKAROUND
This is standard solution, no workaround is applied.
Definition LongDeepSleep.h:48
@ ESP01_MODULE
esp01 modules, not tested yet. Just copy/pasted code from here: https://github.com/nokxs/esp8266-alte...
Definition LongDeepSleep.h:50
void releaseWifi()
Releases WiFi to conserve power.
Definition LongDeepSleep.cpp:285
@ DEEP_SLEEP_UNTIL_DONE
Wake-up completed, WiFi and time server already available.
Definition LongDeepSleep.h:27
@ DEEP_SLEEP_DONE
Wake-up completed, proceed. WiFi not yet restored.
Definition LongDeepSleep.h:26
@ ABSOLUTE_TIME_CHECK_FAILED
Wake-up for absolute time failed due to time server/WiFi issues.
Definition LongDeepSleep.h:30
@ RTC_MEMORY_CHECK_FAILED
RTC memory is invalid or corrupted.
Definition LongDeepSleep.h:29
@ OTHER_WAKE_UP_REASON
Wake-up due to other reason (reset, power-on, etc.).
Definition LongDeepSleep.h:28
uint32_t rebootCounter()
Releases WiFi to conserve power.
Definition LongDeepSleep.h:142
@ SPECIFIED_TIME_IN_PAST
The specified until time stamp lies in the past, hence sleep not required, do whatever you want to do...
Definition LongDeepSleep.h:41
@ OK
Will never be seen as then the ESP will go into deep sleep.
Definition LongDeepSleep.h:38
@ NO_ABSOLUE_TIME_AVAILABLE
time client was specified, but it was not possible to determine an absolute time, hence this function...
Definition LongDeepSleep.h:40
@ NO_TIME_CLIENT
No time client specified when creating class longdeepsleep, hence this function is not available.
Definition LongDeepSleep.h:39
LongDeepSleep(const char *ssid=nullptr, const char *password=nullptr, NTPClient *ntpClient=nullptr)
Constructor.
Definition LongDeepSleep.h:72
int performLongDeepSleepUntil(uint64_t epocheTime)
Sleep until an absolute epoch time.
Definition LongDeepSleep.cpp:162