diff --git a/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino b/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino index 87d7f1eb..884df675 100644 --- a/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino +++ b/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino @@ -48,6 +48,9 @@ void setup() { // Override the default join rate uint8_t joinDR = 4; + // Optionally provide a custom sleep function - see config.h + //node.setSleepFunction(customDelay); + // Setup the OTAA session information node.beginOTAA(joinEUI, devEUI, nwkKey, appKey); diff --git a/examples/LoRaWAN/LoRaWAN_Reference/config.h b/examples/LoRaWAN/LoRaWAN_Reference/config.h index 21c79f8e..565e32d1 100644 --- a/examples/LoRaWAN/LoRaWAN_Reference/config.h +++ b/examples/LoRaWAN/LoRaWAN_Reference/config.h @@ -142,4 +142,19 @@ void arrayDump(uint8_t *buffer, uint16_t len) { Serial.println(); } +// Custom delay function: +// Communication over LoRaWAN includes a lot of delays. +// By default, RadioLib will use the Arduino delay() function, +// which will waste a lot of power. However, you can put your +// microcontroller to sleep instead by customizing the function below, +// and providing it to RadioLib via "node.setSleepFunction". +// NOTE: You ahve to ensure that this function is timed precisely, and +// does actually wait for the amount of time specified! +// Failure to do so will result in missed downlinks or failed join! +void customDelay(RadioLibTime_t ms) { + // this is just an example, so we use the Arduino delay() function, + // but you can put your microcontroller to sleep here + ::delay(ms); +} + #endif