ESP32 - Variables after Deep Sleep
Posted: Tue Sep 24, 2024 4:33 am
Hello all,
I'm new and playing around with deep sleep on an ESP32-S3. The first time I run my code, everything goes as planned. After the device sleeps, however, I never get to the i = 0 condition so the device will no longer print "Just woke up!"
Does anyone know why this may be? Thank you!
I'm new and playing around with deep sleep on an ESP32-S3. The first time I run my code, everything goes as planned. After the device sleeps, however, I never get to the i = 0 condition so the device will no longer print "Just woke up!"
Does anyone know why this may be? Thank you!
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_sleep.h"
#include "esp_timer.h"
#include "esp_log.h"
void awake_operations(void)
{
static int i = 0;
while (i <= 10) {
if (i == 0) {
printf("Just woke up!\n");
}
else if (i == 1) {
printf("I've been awake for %i second.\n", i);
}
else if (i > 1) {
printf("I've been awake for %i seconds.\n", i);
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
i++;
}
}
void deep_sleep(void)
{
printf("Going to deep-sleep for 5 seconds.\n");
// vTaskDelay(100 / portTICK_PERIOD_MS);
// Configure deep-sleep wake up timer for 5 seconds.
uint64_t sleeptime = 5000000;
esp_sleep_enable_timer_wakeup(sleeptime);
// Go to deep sleep.
esp_deep_sleep_start();
}
void app_main(void)
{
awake_operations();
deep_sleep();
}