ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
example_deepsleep.cpp
Go to the documentation of this file.
1
14#include <Arduino.h>
15#include <ArduinoLog.h>
16
17#include "driver/gpio.h"
18#include "esp_sleep.h"
19
21RTC_DATA_ATTR int bootCount = 0;
22
23/* Method to print the reason by which ESP32 has been awaken from sleep
24 */
26 esp_sleep_wakeup_cause_t wakeup_reason;
27
28 wakeup_reason = esp_sleep_get_wakeup_cause();
29
30 switch (wakeup_reason) {
31 case ESP_SLEEP_WAKEUP_EXT0:
32 Serial.println("Wakeup caused by external signal using RTC_IO");
33 break;
34 case ESP_SLEEP_WAKEUP_EXT1:
35 Serial.println("Wakeup caused by external signal using RTC_CNTL");
36 break;
37 case ESP_SLEEP_WAKEUP_TIMER:
38 Serial.println("Wakeup caused by timer");
39 break;
40 case ESP_SLEEP_WAKEUP_TOUCHPAD:
41 Serial.println("Wakeup caused by touchpad");
42 break;
43 case ESP_SLEEP_WAKEUP_ULP:
44 Serial.println("Wakeup caused by ULP program");
45 break;
46 case ESP_SLEEP_WAKEUP_GPIO:
47 Serial.println(
48 "Wakeup caused by GPIO (light sleep only on ESP32, S2 and S3)");
49 break;
50 case ESP_SLEEP_WAKEUP_UART:
51 Serial.println("Wakeup caused by UART0 (light sleep only)");
52 break;
53 case ESP_SLEEP_WAKEUP_WIFI:
54 Serial.println("Wakeup caused by WIFI (light sleep only)");
55 break;
56 case ESP_SLEEP_WAKEUP_COCPU:
57 Serial.println("Wakeup caused by COCPU int");
58 break;
59 case ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG:
60 Serial.println("Wakeup caused by COCPU crash");
61 break;
62 case ESP_SLEEP_WAKEUP_BT:
63 Serial.println("Wakeup caused by BT (light sleep only)");
64 break;
65 default:
66 Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason);
67 break;
68 }
69}
70
71void setup() {
72 ++bootCount;
73
74 // setup serial
75 Serial.begin(115200);
76
77 Log.begin(LOG_LEVEL_NOTICE, &Serial);
78
79 Log.noticeln("ents-node esp32 firmware, compiled at %s %s", __DATE__,
80 __TIME__);
81 Log.noticeln("Git SHA: %s", GIT_REV);
82 Log.noticeln("Boot number: %d", bootCount);
83
85
86 const gpio_num_t wakeup_pin = GPIO_NUM_3;
87 const gpio_config_t config = {
88 .pin_bit_mask = BIT(GPIO_NUM_3),
89 .mode = GPIO_MODE_INPUT,
90 .pull_up_en = GPIO_PULLUP_DISABLE,
91 .pull_down_en = GPIO_PULLDOWN_DISABLE,
92 };
93 gpio_config(&config);
94 esp_deep_sleep_enable_gpio_wakeup(BIT(wakeup_pin), ESP_GPIO_WAKEUP_GPIO_HIGH);
95
96 Log.noticeln("Entering deep sleep mode!");
97
98 esp_deep_sleep_start();
99}
100
101void loop() {}
RTC_DATA_ATTR int bootCount
void setup()
void print_wakeup_reason()
void loop()