I'm completely removing power from a DS3231 RTC module and my call to rtc.lostPower() is never hit when I reconnect everything. I'm also removing the battery, I left it overnight and it remembers the time just before I disconnected everything, but doesn't register a power loss. I'm using this with a D1 mini.
void setup() {
// put your setup code here, to run once:
Serial.begin(baud);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC.");
while (1); // while true
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, resetting time.");
ConnectWiFi();
GetNtpTime();
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
Serial.println("Time set after power loss");
}
}
lostPower()method returns the “Oscillator Stop Flag” from the status register (c.f. datasheet, p. 14). – Edgar Bonet Jan 20 '20 at 08:51