I have heard that NTPClient 3.2 is supposed to be able to get the day of the week using a getDay() function. Does anyone know if this getDay() function actually works and if so, can you post a sample code of how it is used?
Thanks
I have heard that NTPClient 3.2 is supposed to be able to get the day of the week using a getDay() function. Does anyone know if this getDay() function actually works and if so, can you post a sample code of how it is used?
Thanks
Why don't you have a look at the code?
int NTPClient::getDay() const {
return (((this->getEpochTime() / 86400L) + 4 ) % 7); //0 is Sunday
}
So thee method takes the seconds since 01.01.1970 (which is a pretty basic function which I expect to work in a library at version 3.2), finds out how many days that corresponds to, offsets by the DOW of the 01.01.1970 and does mod 7. That is a working way to get the number. Why do you doubt that?
The lib also has examples. What are you looking for?
I asked because I'm not knowledgable to look at the code and know that it is workable code. I loaded the advanced example into a Wemos D1 R2, set the SSID and the Password and pool but I get nothing in the serial monitor, just a long string of dots. I don't know if the dots indicates that it is not connecting but I have a different program that accesses the NTP server and it connects fine with the same settings. Also, the sample code does not show how to use getDay() to get the weekday, which is what I am trying to get. It looks like it just displays the formatted time using getFormattedTime().
As for the usage of the getDay() in the code would I use something like this?
formattedDate = timeClient.getFormattedDate();
weekday = getDay();
Serial.print(weekday);
Thanks