I’m migrating my project over from Arduino Mega to an ESP8266 environment and in doing so, it seems the RTClib library no longer works with the DS3231 RTC and/or the ESP. So I found another library that functions similarly, though when it comes to my function that attempts to update the RTC with readings from the Blynk server, the RTC time is set to 170 years into the future. I realize this is mostly a library issue, and not so much a hardware or Blynk issue. Still though, I’m asking for assistance in the event someone more skilled than I can spot any concerns or has specific knowledge of this library.
void syncRTCHardware()
{
if (!Blynk.connected())
{
return;
}//DateTime now = RTC.now(); // reads hardware time at beginning of loop
RtcDateTime dt = rtcObject.GetDateTime();
// time library is synchronized by the Blynk WidgetRTC
if (Blynk.connected())
{
bool syncClocks = false;
bool printOnce;
if (dt.Hour() != hour() || dt.Minute() != minute()) syncClocks = true;
if (syncClocks == true)
{
syncClocks = false;
Serial.println("Resynching RTC Time...");
if (printOnce)
{
terminal.println("Resynching RTC Time...");
printOnce = false;
}
RtcDateTime dt = RtcDateTime(year(), month(), day(), hour(), minute(), second()); //Sync hardware with Blynk server time
rtcObject.SetDateTime(dt); //configure the RTC with object
//rtcObject.SetDateTime(RtcDateTime(year(), month(), day(), hour(), minute(), second())); //Sync hardware with Blynk server time
terminal.flush();
}
printOnce = true;
}
}
Here is a link to the library documentation. https://github.com/Makuna/Rtc/wiki/RtcDateTime-object. When using RTClib, the syncRTChardware function worked flawlessly. I’ve adjusted the code the best I can to utilize the new library. The time populates the display widget when the above function is commented out, but when the function is implemented, it malfunctions and resets the RTC to the future.
Any help at all, even if better study leads is most wanted and welcomed. Thank you in advance!