You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.4 KiB
95 lines
2.4 KiB
void ntp()
|
|
{
|
|
// while(!timeClient.update()) {
|
|
// timeClient.forceUpdate();
|
|
//}
|
|
|
|
for(int i=0; i<5 && !timeClient.update(); i++)
|
|
{
|
|
|
|
timeClient.forceUpdate();
|
|
}
|
|
|
|
// The formattedDate comes with the following format:
|
|
// 2018-05-28T16:00:13Z
|
|
// We need to extract date and time
|
|
// formattedDate = timeClient.getFormattedDate();
|
|
formattedTime =timeClient.getFormattedTime();
|
|
Serial.println(formattedTime);
|
|
Serial.println("NTP3");
|
|
// getDay
|
|
//getHours
|
|
//getMinutes
|
|
//getSeconds
|
|
//getFormattedTime
|
|
// formattedDate =timeClient.getFormattedDate();
|
|
// int splitT = formattedDate.indexOf("T");
|
|
// dayStamp = formattedDate.substring(0, splitT);
|
|
// Serial.println(timeClient.getDay());
|
|
|
|
// Extract time
|
|
// timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1);
|
|
// Serial.println("ntp");
|
|
// Serial.println(timeClient.getEpochTime());
|
|
stamp.getDateTime(timeClient.getEpochTime());
|
|
EpochTime=timeClient.getEpochTime();
|
|
// забираем вот так
|
|
// Serial.println(stamp.year);
|
|
Serial.println(stamp.month);
|
|
Serial.println(stamp.day);
|
|
// Serial.println(stamp.hour);
|
|
// Serial.println(stamp.minute);
|
|
// Serial.println(stamp.second);
|
|
Serial.println(stamp.dayOfWeek);
|
|
timeserv=formatTimeDigits(stamp.hour,stamp.minute);
|
|
//dataserv=formatDateDigits(stamp.day, stamp.month, stamp.year);
|
|
|
|
hour1=stamp.hour;
|
|
min1=stamp.minute;
|
|
|
|
dataserv=stamp.day;
|
|
munthserv=strm[stamp.month-1] ;
|
|
weekserv=strweek[stamp.dayOfWeek];
|
|
//Serial.println(timeserv);
|
|
//Serial.println(dataserv);
|
|
}
|
|
|
|
char *formatTimeDigits(int hour, int minute)
|
|
{
|
|
char *time_str = new char[5];
|
|
time_str[0] = '0' + (hour / 10);
|
|
time_str[1] = '0' + (hour % 10);
|
|
time_str[2] = ':';
|
|
time_str[3] = '0' + (minute / 10);
|
|
time_str[4] = '0' + (minute % 10);
|
|
time_str[5] = '\0';
|
|
|
|
return time_str;
|
|
}
|
|
|
|
char *formatDateDigits(int date, int mounth, int year)
|
|
{
|
|
char *date_str = new char[9];
|
|
|
|
date_str[1] = '0' + (date % 10);
|
|
date_str[2] = '/';
|
|
date_str[0] = '0' + (date / 10);
|
|
date_str[3] = '0' + (mounth / 10);
|
|
date_str[4] = '0' + (mounth % 10);
|
|
date_str[5] = '/';
|
|
date_str[6] = '0' + ((year % 100) / 10);
|
|
date_str[7] = '0' + (year % 10);
|
|
date_str[8] = '\0';
|
|
|
|
return date_str;
|
|
}
|
|
|
|
void ntphome()
|
|
{
|
|
stamp.getDateTime(timeClient.getEpochTime());
|
|
timeserv=formatTimeDigits(stamp.hour,stamp.minute);
|
|
hour1=stamp.hour;
|
|
min1=stamp.minute;
|
|
// dataserv=formatDateDigits(stamp.day, stamp.month, stamp.year);
|
|
dataserv=stamp.day;
|
|
}
|
|
|