diff --git a/code-snippets/client/deep_sleep/ESP32_LOW_POWER Management.pdf b/code-snippets/client/deep_sleep/ESP32_LOW_POWER Management.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c93ade6a83ac217e56d40a0e53fe2f56c9b0dcc7 Binary files /dev/null and b/code-snippets/client/deep_sleep/ESP32_LOW_POWER Management.pdf differ diff --git a/code-snippets/client/deep_sleep/documentaion DeepSleep Timer wake up.docx b/code-snippets/client/deep_sleep/documentaion DeepSleep Timer wake up.docx new file mode 100644 index 0000000000000000000000000000000000000000..ec4930d43b77bb43e1a22e65f8c6fc565b9ae987 Binary files /dev/null and b/code-snippets/client/deep_sleep/documentaion DeepSleep Timer wake up.docx differ diff --git a/code-snippets/client/deep_sleep/f_deep_sleep/examples/deep_sleep_timer_wake_up/deep_sleep_timer_wake_up.ino b/code-snippets/client/deep_sleep/f_deep_sleep/examples/deep_sleep_timer_wake_up/deep_sleep_timer_wake_up.ino new file mode 100644 index 0000000000000000000000000000000000000000..c17462c33f91d844ba4e09cbe9e2de11685e633c --- /dev/null +++ b/code-snippets/client/deep_sleep/f_deep_sleep/examples/deep_sleep_timer_wake_up/deep_sleep_timer_wake_up.ino @@ -0,0 +1,31 @@ +#include <f_deep_sleep.h> +/* +This code is under Public Domain License. +Author: Pranav Cherukupalli <cherukupallip@gmail.com> +*/ + +/* Data saved on the RTC memory will not be deletet while the deep sleep mode */ +RTC_DATA_ATTR int bootCount = 0; +/* First we configure the wake up source We set our ESP32 to wake up every 5 seconds */ +#define TIME_TO_SLEEP 5 + +void setup(){ + Serial.begin(115200); + Serial.println("******************After weak up Programm starts in setup**********************"); + delay(1000); //Take some time to open up the Serial Monitor + +} + + +void loop(){ + ++bootCount; + Serial.println("Boot number: " + String(bootCount)); + //Print the wakeup reason for ESP32 + print_wakeup_reason(); + Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds"); + Serial.println("Going to sleep now"); + Serial.println(); + Serial.flush(); + //going to sleep + deep_sleep(TIME_TO_SLEEP); +} diff --git a/code-snippets/client/deep_sleep/f_deep_sleep/f_deep_sleep.cpp b/code-snippets/client/deep_sleep/f_deep_sleep/f_deep_sleep.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fc827756ab8792770dad6c1fdc41ccbfb3fbcd09 --- /dev/null +++ b/code-snippets/client/deep_sleep/f_deep_sleep/f_deep_sleep.cpp @@ -0,0 +1,23 @@ +#include "f_deep_sleep.h" + +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){//Increment boot number and print it every reboot + esp_sleep_enable_timer_wakeup(time_in_sec * 1000000); + esp_deep_sleep_start(); +} diff --git a/code-snippets/client/deep_sleep/f_deep_sleep/f_deep_sleep.h b/code-snippets/client/deep_sleep/f_deep_sleep/f_deep_sleep.h new file mode 100644 index 0000000000000000000000000000000000000000..876500d27ddac67e99ff0bbc4cecf74acdbeca6a --- /dev/null +++ b/code-snippets/client/deep_sleep/f_deep_sleep/f_deep_sleep.h @@ -0,0 +1,6 @@ +#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