37 lines
1.4 KiB
C++
37 lines
1.4 KiB
C++
//Code to update time from the web
|
|
void update_time_from_web(){
|
|
//write_log(wifi_connected);
|
|
if (wifi_connected == true && ntp_update == true)
|
|
{
|
|
strDateTime dateTime;
|
|
// first parameter: Time zone in floating point (for India); second parameter: 1 for European summer time; 2 for US daylight saving time; 0 for no DST adjustment; (contributed by viewwer, not tested by me)
|
|
dateTime = NTPch.getNTPtime(1.0, 1);
|
|
// check dateTime.valid before using the returned time
|
|
// Use "setSendInterval" or "setRecvTimeout" if required
|
|
if(dateTime.valid){
|
|
NTPch.printDateTime(dateTime);
|
|
byte actualHour = dateTime.hour;
|
|
byte actualMinute = dateTime.minute;
|
|
byte actualsecond = dateTime.second;
|
|
int actualyear = dateTime.year;
|
|
byte actualMonth = dateTime.month;
|
|
byte actualday =dateTime.day;
|
|
byte actualdayofWeek = dateTime.dayofWeek;
|
|
if (actualMinute != m && actualday != 7 && actualMonth != 2 && actualyear != 2036 && actualHour != 0){
|
|
h = actualHour;
|
|
m = actualMinute;
|
|
s = actualsecond;
|
|
y = actualyear;
|
|
M = actualMonth;
|
|
d = actualday;
|
|
set_clock();
|
|
write_log("Time Updated!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
write_log(String(h) + ":" + String(m) + " - " + String(d) + "." + String(M) + "." + String(y));
|
|
display_text("Update Time","");
|
|
delay_gui(1000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|