Is OTAA_PERIOD code wrong in Example of Arduino IDE?

well there is an example in Arduino ide LORAWAN OTAA

at this code if I plan to 2 motnhs about 5,000,000,000 OTAA Period it gives error. ın my opinion uint32_t should choice instead of uint64_t

void loop()
{
    static uint64_t last = 0;
    static uint64_t elapsed;
  
    if ((elapsed = millis() - last) > OTAA_PERIOD) {
        uplink_routine();
  
        last = millis();
    }
    //Serial.printf("Try sleep %ums..", OTAA_PERIOD);
    api.system.sleep.all(OTAA_PERIOD);
    //Serial.println("Wakeup..");
}

millis() is an unsigned long which is 32bit.

Your calculation where you mix uint64_t with unsigned long (32 bits) will fail already at some point.

api.system.sleep.all() is calling udrv_sleep_ms(uint32_t ms_time) which is 32bit only as well.

If you need to sleep for 2 months, you have to use another method. Maybe an external RTC with a wake-up function.

There are other options to keep the device in low power mode without using loop() and api.system.sleep.all(OTAA_PERIOD);

Maybe RUI3-LowPower-Example can give you an insight. However, there is no timer that would hit only every 2 months.

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.