TTGO ESP32 LORA v1.0 unable to wakeup from sleep using LoRa interrupt
-
I wish to put the ESP32 module to sleep and then wake up from sleep when receiving a message via LoRa.
I have successfully put the ESP32 into deep sleep.
I have successfully woken up the ESP32 from deep sleep via a timer.
I have successfully woken up the ESP32 from deep sleep via a push button (using ext0 and ext1) on both GPIO25 and GPIO26.
But I am having trouble waking up the ESP32 from deep sleep using the DIO0 line from the LoRa.I have already attempted to use the GPIO26 (DIO0) to wake up using ext0 and ext1 - without any success.
I have also tested the interrupt capability of GPIO26 and DIO0 when ESP32 is awake and that is working correctly with the interrupt firing when receiving a LoRa message.
-
-
@lewis This Library is for receiving and transmitting LoRa using interrupt.
I have already successfully received and transmitted LoRa packets using interrupt.What I want is to wake up ESP32 from sleep using LoRa interrupt.
-
I am including the code I used to test the wakeup using LoRa interrupt.
If I input "SLEEP*" via LoRa or Serial, ESP32 will go to sleep but will not wake up with further commands, even though the interrupt is working correctly.#include <LoRa.h> #define LORA_MISO 19 #define LORA_MOSI 27 #define LORA_SCK 5 #define LORA_CS 18 #define LORA_RST 14 #define LORA_DIO0 26 #define LORA_DIO0_INT GPIO_NUM_26 volatile bool loraInt = false; void setup() { Serial.begin(115200); print_wakeup_reason(); loraSetup(); } void loraSendMessage(String message) { LoRa.beginPacket(); LoRa.println(message); LoRa.endPacket(); LoRa.receive(); } ICACHE_RAM_ATTR void loraInterrupt() { // Serial.println("I"); loraInt = true; } void loraSetup() { SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); LoRa.setSPI(SPI); LoRa.setPins(LORA_CS, LORA_RST, LORA_DIO0); if (!LoRa.begin(867E6)) { Serial.println("LoRa init failed. Check your connections."); while (true); } Serial.println("LoRa init succeeded."); LoRa.setSyncWord(65); LoRa.setTxPower(17); LoRa.setSignalBandwidth(125E3); LoRa.setSpreadingFactor(7); LoRa.setCodingRate4(5); LoRa.setPreambleLength(8); LoRa.enableCrc(); pinMode(LORA_DIO0, INPUT); attachInterrupt(digitalPinToInterrupt(LORA_DIO0), loraInterrupt, RISING); loraSendMessage("Hello LoRa"); } void sleep_controller(long seconds) { //Deep Sleep ESP32 Serial.println("Sleeping for " + String(seconds) + " secs"); esp_sleep_enable_timer_wakeup(1000000LL * seconds); // rtc_gpio_init(LORA_DIO0_INT); // rtc_gpio_set_direction(LORA_DIO0_INT,RTC_GPIO_MODE_INPUT_ONLY); // rtc_gpio_pulldown_dis(LORA_DIO0_INT); // rtc_gpio_pullup_en(LORA_DIO0_INT); // rtc_gpio_hold_en(LORA_DIO0_INT); esp_sleep_enable_ext0_wakeup(LORA_DIO0_INT, 1); // esp_sleep_enable_ext1_wakeup(0x4000000, ESP_EXT1_WAKEUP_ANY_HIGH); esp_deep_sleep_start(); } void sleep_lora() { // LoRa.sleep(); } void wake_lora() { loraSetup(); } void sleep_all(long seconds = 300) { sleep_lora(); sleep_controller(seconds); } void loop() { String input; bool serialFlag = false, loraFlag = false; if (Serial.available()) { input = ""; while (Serial.available()) { input = Serial.readStringUntil('\n'); serialFlag = true; } } if (loraInt) { // Serial.println("I"); int packetSize = LoRa.parsePacket(); if (packetSize) { input = ""; while (LoRa.available()) { input = LoRa.readStringUntil('\n'); loraInt = false; loraFlag = true; } LoRa.receive(); } } if (serialFlag) { loraSendMessage(input); serialFlag = false; } if (loraFlag) { Serial.println(input); loraFlag = false; } int del_1 = input.indexOf('*', 0); String command = input.substring(0, del_1); if (command == "SLEEP") { sleep_all(50); } } 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.println("Wakeup was not caused by deep sleep:" + String(wakeup_reason)); break; } }
-
I found the solution from LILYGO Support itself.
For anyone wondering how to solve this, you need to hold the RST pin of LoRa high before ESP32 goes to sleep so that LoRa will be active.Add this line before going to sleep
gpio_hold_en(GPIO_NUM_14);
The full sleep function will look like this.
void sleep_controller(long seconds) { //Deep Sleep ESP32 Serial.println("Sleeping for " + String(seconds) + " secs"); esp_sleep_enable_timer_wakeup(1000000LL * seconds); // Hold the RST pin of LoRa before going to sleep gpio_hold_en(GPIO_NUM_14); esp_sleep_enable_ext0_wakeup(LORA_DIO0_INT, 1); esp_deep_sleep_start(); }
-
@navainnovation I was having similar problem and thank you so much for the solution.
Just having 1 question is that would this still work if I put the Lora to sleep mode, or even just idle mode?