mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Small refactor NTP
This commit is contained in:
parent
8865c79182
commit
46bf60ac15
@ -748,6 +748,7 @@ uint32_t WifiGetNtp(void) {
|
|||||||
char* ntp_server;
|
char* ntp_server;
|
||||||
bool resolved_ip = false;
|
bool resolved_ip = false;
|
||||||
for (uint32_t i = 0; i <= MAX_NTP_SERVERS; i++) {
|
for (uint32_t i = 0; i <= MAX_NTP_SERVERS; i++) {
|
||||||
|
if (ntp_server_id > 2) { ntp_server_id = 0; }
|
||||||
if (i < MAX_NTP_SERVERS) {
|
if (i < MAX_NTP_SERVERS) {
|
||||||
ntp_server = SettingsText(SET_NTPSERVER1 + ntp_server_id);
|
ntp_server = SettingsText(SET_NTPSERVER1 + ntp_server_id);
|
||||||
} else {
|
} else {
|
||||||
@ -760,7 +761,6 @@ uint32_t WifiGetNtp(void) {
|
|||||||
if (resolved_ip) { break; }
|
if (resolved_ip) { break; }
|
||||||
}
|
}
|
||||||
ntp_server_id++;
|
ntp_server_id++;
|
||||||
if (ntp_server_id > 2) { ntp_server_id = 0; }
|
|
||||||
}
|
}
|
||||||
if (!resolved_ip) {
|
if (!resolved_ip) {
|
||||||
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("NTP: No server found"));
|
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("NTP: No server found"));
|
||||||
@ -798,8 +798,7 @@ uint32_t WifiGetNtp(void) {
|
|||||||
packet_buffer[15] = 52;
|
packet_buffer[15] = 52;
|
||||||
|
|
||||||
if (udp.beginPacket(time_server_ip, 123) == 0) { // NTP requests are to port 123
|
if (udp.beginPacket(time_server_ip, 123) == 0) { // NTP requests are to port 123
|
||||||
ntp_server_id++;
|
ntp_server_id++; // Next server next time
|
||||||
if (ntp_server_id > 2) { ntp_server_id = 0; } // Next server next time
|
|
||||||
udp.stop();
|
udp.stop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -819,8 +818,7 @@ uint32_t WifiGetNtp(void) {
|
|||||||
// Leap-Indicator: unknown (clock unsynchronized)
|
// Leap-Indicator: unknown (clock unsynchronized)
|
||||||
// See: https://github.com/letscontrolit/ESPEasy/issues/2886#issuecomment-586656384
|
// See: https://github.com/letscontrolit/ESPEasy/issues/2886#issuecomment-586656384
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("NTP: IP %s unsynched"), time_server_ip.toString().c_str());
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR("NTP: IP %s unsynched"), time_server_ip.toString().c_str());
|
||||||
ntp_server_id++;
|
ntp_server_id++; // Next server next time
|
||||||
if (ntp_server_id > 2) { ntp_server_id = 0; } // Next server next time
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -831,8 +829,7 @@ uint32_t WifiGetNtp(void) {
|
|||||||
secs_since_1900 |= (uint32_t)packet_buffer[42] << 8;
|
secs_since_1900 |= (uint32_t)packet_buffer[42] << 8;
|
||||||
secs_since_1900 |= (uint32_t)packet_buffer[43];
|
secs_since_1900 |= (uint32_t)packet_buffer[43];
|
||||||
if (0 == secs_since_1900) { // No time stamp received
|
if (0 == secs_since_1900) { // No time stamp received
|
||||||
ntp_server_id++;
|
ntp_server_id++; // Next server next time
|
||||||
if (ntp_server_id > 2) { ntp_server_id = 0; } // Next server next time
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return secs_since_1900 - 2208988800UL;
|
return secs_since_1900 - 2208988800UL;
|
||||||
@ -842,6 +839,7 @@ uint32_t WifiGetNtp(void) {
|
|||||||
// Timeout.
|
// Timeout.
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("NTP: No reply"));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR("NTP: No reply"));
|
||||||
udp.stop();
|
udp.stop();
|
||||||
|
ntp_server_id++; // Next server next time
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user