36 lines
1.3 KiB
C++
36 lines
1.3 KiB
C++
//Code to update time from the web
|
|
void update_time_from_web(){
|
|
//Serial.println(wifi_connected);
|
|
if (wifi_connected == 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){
|
|
h = actualHour;
|
|
m = actualMinute;
|
|
s = actualsecond;
|
|
y = actualyear;
|
|
M = actualMonth;
|
|
d = actualday;
|
|
set_clock();
|
|
Serial.println("Time Updated!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
display_text("Update Time","");
|
|
delay_gui(1000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|