Did you attach a file? i don’t see one. Did you try something like the following, a modification of LoraSender.ino
? This code tells the ESP32 to go into deep sleep after the onTXDone()
ISR is called. onTXDone()
shouldn’t be called until the packet has been fully sent. i have not tested this code. Let me know if it works for you.
volatile bool lora_idle = true;
volatile bool enterDeepSleep = false;
RTC_DATA_ATTR double txNumber = 0; // so it survives sleep
void setup() {
// LoRa setup...
...
RadioEvents.TxDone = OnTxDone;
...
}
void loop()
{
// how many times will this loop be executed? once per wake?
if (enterDeepSleep) deepSleep();
if(lora_idle == true) // leaving this in place because it's not clear what Radio.IrqProcess does.
{
delay(1000);
txNumber += 0.01;
sprintf(txpacket,"Hello world number %0.2f",txNumber); //start a package
Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket));
Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out
lora_idle = false;
}
Radio.IrqProcess( ); // is this blocking or non-blocking?
}
void OnTxDone( void )
{
Serial.print("TX done...... ");
Serial.println(txNumber);
lora_idle = true;
// GO SLEEP!!!
enterDeepSleep = true;
}
// sleep 10 seconds
void deepSleep() {
enterDeepSleep = false; // not necessary because it'll be reset anyway after sleep
Serial.println("Going into deep sleep.");
VextOFF();
Radio.Sleep();
SPI.end();
pinMode(RADIO_DIO_1,ANALOG);
pinMode(RADIO_NSS,ANALOG);
pinMode(RADIO_RESET,ANALOG);
pinMode(RADIO_BUSY,ANALOG);
pinMode(LORA_CLK,ANALOG);
pinMode(LORA_MISO,ANALOG);
pinMode(LORA_MOSI,ANALOG);
#define sleepTime 1 // in minutes
// esp_sleep_enable_timer_wakeup(sleepTime * 60 * 1000* (uint64_t) 1000); // 60 secs * 1000 ms * 1000 us
esp_sleep_enable_timer_wakeup(10 * 1000* (uint64_t) 1000); // 10 secs * 1000 ms * 1000 us
esp_deep_sleep_start();
}