I have a project running based on the RAK4631_DeepSleep_LoRaWan example.
I am familar with attaching and consuming interrupts in basic arduino sketches.
However, I am not sure how to implement DIO interrupt that can cause a wakeup (and processing) in the RAK4631_DeepSleep_LoRaWan freertos example. I would like to add the DIO interrupt in addition to the existing periodic timer interrupt in the above example.
After spending a bit of time with the RAK4631-DeepSleep-LoRaWan.ino, the following modifications/additions will add a DIO interrupt wakeup to the example.
Add an interrupt handler, that sets a new eventype to be used in the loop;
void DIOInterruptHandler() {
eventType = 2;
// Give the semaphore, so the loop task will wake up
xSemaphoreGiveFromISR(taskEvent, pdFALSE);
}
In the loop, add processing for to a new switch/case;
void loop(void){
...
if (xSemaphoreTake(taskEvent, portMAX_DELAY) == pdTRUE) {
...
// Check the wake up reason
switch (eventType)
{
case 0: // Wakeup reason is package downlink arrived
...
break;
case 1: // Wakeup reason is timer
...
break;
case 2: // Wakeup reason is DIO interrupt
//Do custom processing before sending Lora
if (sendLoRaFrame())
{
Serial.println("LoRaWan package sent successfully");
}
else
{
Serial.println("LoRaWan package send failed");
/// \todo maybe you need to retry here?
}
break;
default:
break;
}
...
}
}
I have striped all the #ifndef MAX_SAVE / #endif for clarity, but they should remain in your code for max power savings.
With the above additions, the original periodic wakeup still function, in addition to the new DIO interrupt wakeup.