arduino-libraries / ArduinoLowPower

Powersave features for SAMD boards
GNU Lesser General Public License v2.1
80 stars 57 forks source link

LowPower.DeepSleep 24h doesn't work #22

Closed JefDeRycke closed 4 years ago

JefDeRycke commented 4 years ago

Hi Everyone,

I am using following code on the MKRFOX1200. I need the board to goto sleep for 24h (or 48), wake up send a message and goto sleep again.

I have the following code:

include

include

include "Maxbotix.h"

define ReportRequest 5

define GotoSleep 4

define SLEEPTIME 1440 60 1000 // Set the delay to 1440 minutes (1440 min x 60 seconds x 1000 milliseconds)

int DEBUG = true; String strPercent; String strPercentBat; String strMessageLevel; String strMessageBat; boolean DailyLevelReported = false;

//afstandsensor

define DISTANCE_SENSOR 6 //Maxbotix PW

long duration, cm, inches; int BatteryValue; long BatteryVoltage; int BatteryPercent; //distance long distance; int tanklevel;

//afstandsensor Maxbotix rangeSensorPW(DISTANCE_SENSOR, Maxbotix::PW, Maxbotix::XL, Maxbotix::BEST);

//Response from Sigfox server int sgfResponse = 0;

void setup() {

pinMode(ReportRequest, INPUT_PULLUP); pinMode(GotoSleep, INPUT_PULLUP);

  if (!SigFox.begin()) {
  // Something is wrong
  reboot();
  }
    DailyLevelReported = false;

SigFox.end(); // Send module to standby until we need to send a message SigFox.debug(); // Important (for more information check the Forum http://forum.arduino.cc/index.php?topic=478950.0;nowap)

LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE); }

void loop() {

distance = rangeSensorPW.getRange(); BatteryValue = analogRead(ADC_BATTERY); BatteryVoltage = BatteryValue / 100; BatteryPercent = map(BatteryValue, 0, 310, 0, 100); tanklevel = map(distance, 1, 148, 100, 0);

SigFox.begin(); // Wait at least 30mS after first configuration (100mS before) delay(100); if (tanklevel < 10) strPercent = "%%%"; else strPercent = "%%"; if (BatteryPercent < 10) strPercentBat = "%%%"; else if (BatteryPercent = 100) strPercentBat = "%"; else strPercentBat = "%%"; strMessageLevel = "Tank "; strMessageBat = "Battery "; SigFox.beginPacket(); SigFox.print(tanklevel + strPercent + BatteryPercent + strPercentBat);

int ret = SigFox.endPacket();

if (ret == 0){

SigFox.end(); LowPower.deepSleep(uint32_t(SLEEPTIME));

}

}

void reboot() { NVIC_SystemReset(); while (1);

}

void dummy() { volatile int ttt = 0; }

When I use 15mins for SLEEPTIME everything is good, but when I use 1440mins, the board goes to sleep but wakes up immediatly, sends the message, goes to sleep, wakes up again without delay.

I read in another post that the max sleep time is 49 days, so far I haven't tested where the limit is for my situation. I just know it works with 8mins and 15mins but not with 1440mins.

Someone any ideas?

Thanks,

Jef