Skip to content

Commit

Permalink
revolve issue where sleep max duration was limited (71 minutes !!) by…
Browse files Browse the repository at this point in the history
… uint32 type
  • Loading branch information
ejalal committed Sep 23, 2023
1 parent 8e64436 commit d87b252
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/MQTTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
if (doc.containsKey("sleep"))
{
DisplayManager.setPower(false);
PowerManager.sleep(doc["sleep"].as<uint32_t>());
PowerManager.sleep(doc["sleep"].as<uint64_t>());
}

delete[] payloadCopy;
Expand Down
6 changes: 3 additions & 3 deletions src/PowerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <ArduinoJson.h>
#include "Globals.h"

#define uS_TO_S_FACTOR 1000000
#define uS_TO_S_FACTOR 1000000L

// The getter for the instantiated singleton instance
PowerManager_ &PowerManager_::getInstance()
Expand Down Expand Up @@ -32,12 +32,12 @@ void PowerManager_::sleepParser(const char *json)

if (doc.containsKey("sleep"))
{
uint32_t seconds = doc["sleep"].as<uint32_t>();
uint64_t seconds = doc["sleep"].as<uint64_t>();
sleep(seconds);
}
}

void PowerManager_::sleep(uint32_t seconds)
void PowerManager_::sleep(uint64_t seconds)
{
esp_sleep_enable_timer_wakeup(seconds * uS_TO_S_FACTOR);
Serial.print("Going to sleep...\n");
Expand Down
2 changes: 1 addition & 1 deletion src/PowerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PowerManager_
static PowerManager_ &getInstance();
void setup();
void sleepParser(const char*);
void sleep(uint32_t);
void sleep(uint64_t);
};

extern PowerManager_ &PowerManager;
Expand Down

0 comments on commit d87b252

Please sign in to comment.