From fa1d29c62772f254b4f7ece8e663a98d7873a585 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 13 Nov 2022 22:27:06 +0100 Subject: [PATCH] fix sleep mode oddities --- README.md | 2 +- include/lorawan.h | 2 +- include/reset.h | 3 +-- src/irqhandler.cpp | 4 ++-- src/lorawan.cpp | 2 +- src/power.cpp | 2 +- src/reset.cpp | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bcf4f367..0c474ac6 100644 --- a/README.md +++ b/README.md @@ -518,7 +518,7 @@ Send for example `83` `86` as Downlink on Port 2 to get battery status and time/ 0x19 set sleep cycle bytes 1..2 = device sleep cycle in seconds/10 (MSB), 1 ... 255 - e.g. {0x04, 0xB0} -> device sleeps 20 minutes after each send cycle [default = 0] + e.g. {0x04, 0xB0} -> device sleeps 200 minutes after each send cycle [default = 0] 0x20 load device configuration diff --git a/include/lorawan.h b/include/lorawan.h index 32ddc4ba..a8e7e588 100644 --- a/include/lorawan.h +++ b/include/lorawan.h @@ -25,7 +25,7 @@ extern char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer esp_err_t lmic_init(void); void lora_setupForNetwork(bool preJoin); -void SaveLMICToRTC(int deepsleep_sec); +void SaveLMICToRTC(uint32_t deepsleep_sec); void LoadLMICFromRTC(); void lmictask(void *pvParameters); void gen_lora_deveui(uint8_t *pdeveui); diff --git a/include/reset.h b/include/reset.h index 8f700769..c82ede9f 100644 --- a/include/reset.h +++ b/include/reset.h @@ -14,8 +14,7 @@ void reset_rtc_vars(void); void do_reset(bool warmstart); void do_after_reset(void); -void enter_deepsleep(const uint64_t wakeup_sec = 60, - const gpio_num_t wakeup_gpio = GPIO_NUM_MAX); +void enter_deepsleep(const uint32_t wakeup_sec, const gpio_num_t wakeup_gpio); unsigned long long uptime(void); enum runmode_t { diff --git a/src/irqhandler.cpp b/src/irqhandler.cpp index 87f6c7bd..477c70b5 100644 --- a/src/irqhandler.cpp +++ b/src/irqhandler.cpp @@ -76,9 +76,9 @@ void irqHandler(void *pvParameters) { // goto sleep if we have a sleep cycle if (cfg.sleepcycle) #ifdef HAS_BUTTON - enter_deepsleep(cfg.sleepcycle * 10, (gpio_num_t)HAS_BUTTON); + enter_deepsleep(cfg.sleepcycle * 10UL, (gpio_num_t)HAS_BUTTON); #else - enter_deepsleep(cfg.sleepcycle * 10); + enter_deepsleep(cfg.sleepcycle * 10UL, GPIO_NUM_MAX); #endif } } // for diff --git a/src/lorawan.cpp b/src/lorawan.cpp index cda3a2d8..23c73ebf 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -501,7 +501,7 @@ bool ttn_rtc_restore() { // following code includes snippets taken from // https://github.com/JackGruber/ESP32-LMIC-DeepSleep-example/blob/master/src/main.cpp -void SaveLMICToRTC(int deepsleep_sec) { +void SaveLMICToRTC(uint32_t deepsleep_sec) { // ESP32 can't track millis during DeepSleep and no option to advance // millis after DeepSleep. Therefore reset DutyCyles before saving LMIC struct diff --git a/src/power.cpp b/src/power.cpp index 61f7e27d..ab137ea2 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -57,7 +57,7 @@ void AXP192_powerevent_IRQ(void) { #ifdef HAS_BUTTON // short press -> esp32 deep sleep mode, must be exited by user button if (pmu.isPekeyShortPressIrq()) - enter_deepsleep(0, HAS_BUTTON); + enter_deepsleep(0UL, HAS_BUTTON); #endif pmu.clearIrqStatus(); diff --git a/src/reset.cpp b/src/reset.cpp index 9c58efb8..32843f0a 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -84,7 +84,7 @@ void do_after_reset(void) { } } -void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) { +void enter_deepsleep(const uint32_t wakeup_sec, gpio_num_t wakeup_gpio) { ESP_LOGI(TAG, "Preparing to sleep..."); RTC_runmode = RUNMODE_SLEEP;