Hello.
I am modifying the example code for a periodic loraWAN update using the RUI version of the RAK4631 Wisblock.
This code comes from here:
void loop()
{
static uint64_t last = 0;
static uint64_t elapsed;
static uint32_t execution_time = 0;
uint64_t start = 0;
Serial.printf("last execution = %ums\n", last);
if ((elapsed = millis() - last) > OTAA_PERIOD - execution_time) {
start = millis();
Serial.printf("execute at = %ums\n", elapsed);
uplink_routine();
last = millis();
execution_time = (last - start);
}
Serial.printf("elapsed %ums..", execution_time);
Serial.printf("Try sleep %ums..", OTAA_PERIOD - execution_time);
api.system.sleep.all(OTAA_PERIOD - execution_time);
Serial.println("Wakeup..");
}
I have two questions.
First, if I understand correctly, the milis() function returns a 64 bit unsigned int, so I realistically don’t have to worry about overflow in this scenario.
Second, I noticed without the guard on line 8, the loop occasionally runs a few times before sleeping. I assume this is normal and why the guard is there. Is that correct?
Caio