Skip to content

Commit

Permalink
Merge pull request #6962 from s-hadinger/fix_deepsleep
Browse files Browse the repository at this point in the history
Fix check deepsleep for valid values in Settings (#6961)
  • Loading branch information
arendst authored Nov 19, 2019
2 parents 6ec4373 + 5743486 commit 28725c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions tasmota/_changelog.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* 7.0.0.5 20191118
* Fix boot loop regression
* Add command TempOffset -12.6 .. 12.6 to set global temperature sensor offset (#6958)
* Fix check deepsleep for valid values in Settings (#6961)
*
* 7.0.0.4 20191108
* Add command WifiPower 0 .. 20.5 to set Wifi Output Power which will be default set to 17dBm
Expand Down
8 changes: 7 additions & 1 deletion tasmota/xdrv_29_deepsleep.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const char kDeepsleepCommands[] PROGMEM = D_PRFX_DEEPSLEEP "|"
void (* const DeepsleepCommand[])(void) PROGMEM = {
&CmndDeepsleepTime };

const uint32_t MAX_DEEPSLEEP = 10 * 366 * 24 * 60 * 60; // Allow max 10 years sleep

uint32_t deepsleep_sleeptime = 0;
uint8_t deepsleep_flag = 0;

Expand All @@ -61,6 +63,10 @@ bool DeepSleepEnabled(void)

void DeepSleepReInit(void)
{
// do a sanity check on deepsleep value
if ((0xFFFFFFFF == Settings.deepsleep) || (Settings.deepsleep > MAX_DEEPSLEEP)) {
Settings.deepsleep = 0; // issue #6961
}
if ((ResetReason() == REASON_DEEP_SLEEP_AWAKE) && DeepSleepEnabled()) {
if ((RtcSettings.ultradeepsleep > MAX_DEEPSLEEP_CYCLE) && (RtcSettings.ultradeepsleep < 1700000000)) {
// Go back to sleep after 60 minutes if requested deepsleep has not been reached
Expand Down Expand Up @@ -164,7 +170,7 @@ void DeepSleepEverySecond(void)
void CmndDeepsleepTime(void)
{
if ((0 == XdrvMailbox.payload) ||
((XdrvMailbox.payload > 10) && (XdrvMailbox.payload < (10 * 366 * 24 * 60 * 60)))) { // Allow max 10 years sleep
((XdrvMailbox.payload > 10) && (XdrvMailbox.payload < MAX_DEEPSLEEP))) {
Settings.deepsleep = XdrvMailbox.payload;
RtcSettings.nextwakeup = 0;
deepsleep_flag = (0 == XdrvMailbox.payload) ? 0 : 4;
Expand Down

0 comments on commit 28725c5

Please sign in to comment.