Here’s some suggested feedback for your software folks (It's NOT a request for help thanks).
You might be interested in these additions to the (Chronodot) RTClib library as it stands in gitweb,
1:
It’s an assignment operator so that we can update an existing DateTime variable by assigning it another DateTime variable (which we assume is more recent).
RTClib.h:
DateTime operator =(const DateTime& other) ;
RTClib.cpp:
Code: Select all
DateTime DateTime::operator=(const DateTime& other)
{
yOff = other.yOff;
m = other.m;
d = other.d;
hh = other.hh;
mm = other.mm;
ss = other.ss;
return *this;
}
//Usage (part of my 'getting NTP time’ function):
...
uint32_t myeTime = (uint32_t) epoch + 34200 + daylight_saving;
//Serial.println("\n Got NTP time ....");
#ifdef USE_RTC_DS3231
DateTime NewDate(myeTime);
NTPTime = NewDate; //using assignment operator (Updating my global copy of NTPTime)
RTC.adjust(NTPTime); //Correct the RTC
#endif //USE_RTC_DS3231
(For info:The global copy of the NTP time takes over if the RTC fails (which I had happen with another brand RTC), and gives a slightly less accurate time.)
I’m happy to send the rest of the NTP example as well if you like, it works well to keep the rtc spot on time.
2:
I’ve also changed my version of so that the date prints out the day, but I changed the order of the month and the date to make this work (see example).
18/November Edit: Corrected the order of the Days, 'dayOfWeek()' returns 0 for Sunday.
Code: Select all
const char *days[] = { "Sun, ", "Mon, ", "Tue, ", "Wed, ", "Thu, ", "Fri, ", "Sat, " };
const char* months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
// as a string
char* DateTime::toString(char* buf, int maxlen) const
{
snprintf(buf,maxlen,"%s %02u %s, %04u - %02u : %02u : %02u",
days[dayOfWeek()],
d,
months[m-1],
2000 + yOff,
hh,
mm,
ss
);
return buf;
}
Danny Vagg