Thanks for the suggestion, @PJ_Glasso. I tried that, and it didn’t seem to help. Here’s my current code (slight changes from @Graeme’s):
#include "driver/rtc_io.h"
#include <RadioLib.h>
#include <string>
#define USE_EXT0_WAKEUP 1 // 1 = EXT0 wakeup, 0 = EXT1 wakeup
#define WAKEUP_GPIO GPIO_NUM_1 // Only RTC IO are allowed - ESP32 Pin example
RTC_DATA_ATTR int bootCount = 0;
// Pins number for SX1262 Chip
#define LORA_MISO 8
#define LORA_SCK 7
#define LORA_MOSI 9
#define LORA_CS 41 //NSS
#define LORA_DIO2 38
#define LORA_DIO1 39 // irq
#define LORA_RESET 42
#define LORA_BUSY 40
SX1262 radio = new Module(LORA_CS, LORA_DIO1, LORA_RESET, LORA_BUSY);
void setup() {
Serial.begin(115200);
struct timeval tv_now;
gettimeofday(&tv_now, nullptr);
delay(5000); //Take some time to open up the Serial Monitor
Serial.print("Boot time: ");
Serial.println(tv_now.tv_sec * 1000 + tv_now.tv_usec / 1000);
pinMode(41, OUTPUT);
++bootCount;
Serial.print("Boot number: ");
Serial.println(bootCount);
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason) {
case ESP_SLEEP_WAKEUP_UNDEFINED:
Serial.println("Wakeup was not caused by deep sleep");
break;
case ESP_SLEEP_WAKEUP_EXT0:
Serial.println("Wakeup caused by ESP_SLEEP_WAKEUP_EXT0");
break;
case ESP_SLEEP_WAKEUP_EXT1:
Serial.println("Wakeup caused by ESP_SLEEP_WAKEUP_EXT1");
break;
case ESP_SLEEP_WAKEUP_TIMER:
Serial.println("Wakeup caused by ESP_SLEEP_WAKEUP_TIMER");
break;
default:
Serial.print("Wakeup cause unknown: ");
Serial.println(wakeup_reason);
}
// SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI);
esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); //1 = High, 0 = Low
rtc_gpio_pullup_dis(WAKEUP_GPIO);
rtc_gpio_pulldown_en(WAKEUP_GPIO);
// Go to sleep now
Serial.println("Putting Radio to Sleep");
radio.sleep();
gettimeofday(&tv_now, nullptr);
Serial.print("Going to sleep at: ");
Serial.println(tv_now.tv_sec * 1000 + tv_now.tv_usec / 1000);
Serial.flush();
Serial.end();
esp_deep_sleep_start();
}
void loop() {
}
And the output I’m getting:
Boot time: 13
Boot number: 1
Wakeup was not caused by deep sleep
Putting Radio to Sleep
Going to sleep at: 5014
Disconnected (read failed: [Errno 6] Device not configured)
Reconnecting to /dev/cu.usbmodem101 Connected!
Boot time: 5070
Boot number: 2
Wakeup caused by ESP_SLEEP_WAKEUP_EXT0
Putting Radio to Sleep
Going to sleep at: 10071
Disconnected (read failed: [Errno 6] Device not configured)
Reconnecting to /dev/cu.usbmodem101 Connected!
Boot time: 10126
Boot number: 3
Wakeup caused by ESP_SLEEP_WAKEUP_EXT0
Putting Radio to Sleep
Going to sleep at: 15126
Disconnected (read failed: [Errno 6] Device not configured)
Reconnecting to /dev/cu.usbmodem101 Connected!
Boot time: 15182
Boot number: 4
Wakeup caused by ESP_SLEEP_WAKEUP_EXT0
Putting Radio to Sleep
Going to sleep at: 20182
...