Skip to content
Snippets Groups Projects
Commit f75525ed authored by Bilal Hassan's avatar Bilal Hassan
Browse files

deep sleep mode

parent 9576bb45
No related branches found
No related tags found
1 merge request!10merge serial comm and sd write into espnow
File added
File added
#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);
}
#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();
}
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment