diff --git a/client/client/lib/deep_sleep/f_deep_sleep.cpp b/client/client/lib/deep_sleep/f_deep_sleep.cpp new file mode 100644 index 0000000000000000000000000000000000000000..60d1ac0b44d850f809d44be2b2fd609536fb54a0 --- /dev/null +++ b/client/client/lib/deep_sleep/f_deep_sleep.cpp @@ -0,0 +1,23 @@ +#include "f_deep_sleep.hpp" + +void print_wakeup_reason(){ + esp_sleep_wakeup_cause_t wakeup_reason; + + wakeup_reason = esp_sleep_get_wakeup_cause(); + + switch(wakeup_reason) + { + case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break; + case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break; + case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break; + case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break; + case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break; + default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break; + } +} + + +void deep_sleep(int time_in_sec){ + esp_sleep_enable_timer_wakeup(time_in_sec * 1000000); + esp_deep_sleep_start(); +} diff --git a/client/client/lib/deep_sleep/f_deep_sleep.hpp b/client/client/lib/deep_sleep/f_deep_sleep.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b0c91129d025c7cd48f0350a269a765c7c8e0f5b --- /dev/null +++ b/client/client/lib/deep_sleep/f_deep_sleep.hpp @@ -0,0 +1,9 @@ +#ifndef F_DEEP_SLEEP_H +#define F_DEEP_SLEEP_H + +#include <Arduino.h> + +void deep_sleep(int time_to_sleep); +void print_wakeup_reason(); + +#endif diff --git a/client/client/src/main.cpp b/client/client/src/main.cpp index 2356891f844d1d0e9ef44eadb25d7ae8c30fcbff..3f34c4f4c06b4ce50c9c02b3433f77cf9f6a7149 100644 --- a/client/client/src/main.cpp +++ b/client/client/src/main.cpp @@ -3,6 +3,8 @@ #include <Arduino.h> #include <ArduinoJson.h> #include "Time.hpp" +#include "f_deep_sleep.hpp" + void setup() { @@ -47,5 +49,6 @@ void loop() Serial.println(esptime::rtc.getMillis()); Serial.println("delaying..."); Serial.flush(); - delay(5000); + delay(5000); // 5 second receive window + deep_sleep(900); // go to sleep for 15 mins (900s) } \ No newline at end of file