Go Down

Topic: MKRFOX Max DeepSleep Period (Read 2883 times) previous topic - next topic

jefatperondidoteu

Hi All,

I am trying to put the MKRFOX1200 in Deepsleep using LowPower.DeepSleep(milliseconds).
When I try LowPower.DeepSleep(8*60*1000) everything works, the board goes to sleep for 8mins and then wakes up again, sends message and goes back to sleep for 8mins. When I try to make it go to sleep for 24hrs using LowPower.DeepSleep(1440*60*1000) the board goes to sleep but wakes up immediatly. It gets caught in a loop of sleeping and waking up without interval. I have also tried LowPower.Deepsleep(720*60*1000), it goes to sleep the first time, but doesn't wake up after 12hrs.
I have also read in another topic that #Define WAKE_UP_INTERVAL_24HR 86400000UL doesn't work either but #Define WAKE_UP_INTERVAL_6HR 21600000UL does work. I have thought about a work around to have the board wake up at it's max deepsleep period and use a counter. Just make it send the message every 4 or 8 wake ups. That will avoid sending more messages than I want but my battery life will probably suffer a lot.
Preferrably I want to send 1 message every 1-2 days on battery. Triggering with external pin is not possible, unless it is the only option.

Thanks for any help or suggestions.

Jef

pert

I can reproduce the issue. For me, the wake up is not immediate, but it is less than 1 second.

According to this:
https://github.com/arduino-libraries/ArduinoLowPower/issues/11#issuecomment-446109241
Quote
sleep(uint32_t milliseconds) internally calls rtc.setAlarmEpoch , so unless this one is bugged it should allow to sleep for almost 49 days (UINT32_MAX milliseconds).
So I think this is a bug in the library. You can submit a bug report here:
https://github.com/arduino-libraries/ArduinoLowPower/issues
I looked through the existing issues and didn't find anything about this.

jefatperondidoteu

Hi,

Thanks you for your answer and suggestion. I posted the problem in the Github issues without any result.
Meanwhile I digged a little further and discovered the following. I am using the following to make the MKRFOX1200 goto deepsleep:
LowPower.deepSleep(uint32_t(SLEEPTIME));
where SLEEPTIME is defined as:
#define SLEEPTIME 1440* 60 * 1000   // Set the delay to 1440 minutes (1440 min x 60 seconds x 1000 milliseconds)
Trying to find out to what point it works, I found out that everything works fine, except for multiples of 1440. If I used 1440 (24h) or 2880 (48h), the board gets in a sleep/wakeup loop without delay, as you said you were able to reproduce.
I found out that everything works fine with 1439 minutes and also with 2879 minutes, but not 1440 and 2880. Isn't that strange. It seems like the RTC is messing up with multiples of 1440.
Any ideas?
Thanks,

Jef

pert

@jefatperondidoteu's bug report:
https://github.com/arduino-libraries/ArduinoLowPower/issues/22
thanks for reporting that!

I did an investigation and I believe I found the problem. Line 59 of the library's src/samd/ArduinoLowPower.cpp is:
Code: [Select]
rtc.enableAlarm(rtc.MATCH_HHMMSS);
If you look at src/ArduinoLowPower.h, you find this helpful information:
Code: [Select]
  enum Alarm_Match: uint8_t // Should we have this enum or just use the identifiers from /component/rtc.h ?
  {
    MATCH_OFF          = RTC_MODE2_MASK_SEL_OFF_Val,          // Never
    MATCH_SS           = RTC_MODE2_MASK_SEL_SS_Val,           // Every Minute
    MATCH_MMSS         = RTC_MODE2_MASK_SEL_MMSS_Val,         // Every Hour
    MATCH_HHMMSS       = RTC_MODE2_MASK_SEL_HHMMSS_Val,       // Every Day
    MATCH_DHHMMSS      = RTC_MODE2_MASK_SEL_DDHHMMSS_Val,     // Every Month
    MATCH_MMDDHHMMSS   = RTC_MODE2_MASK_SEL_MMDDHHMMSS_Val,   // Every Year
    MATCH_YYMMDDHHMMSS = RTC_MODE2_MASK_SEL_YYMMDDHHMMSS_Val  // Once, on a specific date and a specific time
  };

So what happens is because they used MATCH_HHMMSS, the sleep duration "overflows" at 1 day. If you set it to one day, it ends immediately, if you set it to three days and one minute, it ends in one minute, and so on.

The solution is to change line 59 of src/samd/ArduinoLowPower.cpp from:
Code: [Select]
rtc.enableAlarm(rtc.MATCH_HHMMSS);
to:
Code: [Select]
rtc.enableAlarm(rtc.MATCH_YYMMDDHHMMSS);
that will allow sleep durations up to the maximum of ~49 days.

I'll let it run for a day to make sure long sleep durations are working as expected, then submit a fix to the library.

pert

I've now submitted the pull request with the fix for the Arduino Low Power library:
https://github.com/arduino-libraries/ArduinoLowPower/pull/24

jefatperondidoteu

Thank you so much!!
Realy appreciate you help and valuable solution
Regards,

Jef

pert

You're very welcome. I'm glad I was able to make a small improvement to the library. Thanks for bringing this issue to our attention.
Enjoy!
Per

Go Up