Select one of the symbols to view example projects that use it.
 
Outline
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_sleep.h"
#include "esp_wake_stub.h"
#include "driver/rtc_io.h"
#include "rtc_wake_stub_example.h"
sleep_enter_time
app_main()
Files
loading...
SourceVuESP-IDF Framework and Examplesdeep_sleep_wake_stub samplemain/wake_stub_example_main.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 *//* ... */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> #include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_sleep.h" #include "esp_wake_stub.h" #include "driver/rtc_io.h" #include "rtc_wake_stub_example.h"12 includes // sleep_enter_time stored in RTC memory static RTC_DATA_ATTR struct timeval sleep_enter_time; void app_main(void) { struct timeval now; gettimeofday(&now, NULL); int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000; if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER) { printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms); }{...} vTaskDelay(1000 / portTICK_PERIOD_MS); const int wakeup_time_sec = CONFIG_WAKE_UP_TIME; printf("Enabling timer wakeup, %ds\n", wakeup_time_sec); esp_sleep_enable_timer_wakeup(wakeup_time_sec * 1000000); #if CONFIG_IDF_TARGET_ESP32 // Isolate GPIO12 pin from external circuits. This is needed for modules // which have an external pull-up resistor on GPIO12 (such as ESP32-WROVER) // to minimize current consumption. rtc_gpio_isolate(GPIO_NUM_12);/* ... */ #endif esp_set_deep_sleep_wake_stub(&wake_stub_example); printf("Entering deep sleep\n"); gettimeofday(&sleep_enter_time, NULL); esp_deep_sleep_start(); }{ ... }
Details