bufix: ntp query when NTP gets enabled from UI
when NTP got enabled via UI, WLED would wait up to 12 hours before issuing the first NTP request.
This commit is contained in:
parent
1e29d9463e
commit
80c67d37c0
@ -247,7 +247,7 @@ static bool isValidNtpResponse(byte * ntpPacket) {
|
|||||||
// based on https://github.com/taranais/NTPClient/blob/master/NTPClient.cpp
|
// based on https://github.com/taranais/NTPClient/blob/master/NTPClient.cpp
|
||||||
if((ntpPacket[0] & 0b11000000) == 0b11000000) return false; //reject LI=UNSYNC
|
if((ntpPacket[0] & 0b11000000) == 0b11000000) return false; //reject LI=UNSYNC
|
||||||
// if((ntpPacket[0] & 0b00111000) >> 3 < 0b100) return false; //reject Version < 4
|
// if((ntpPacket[0] & 0b00111000) >> 3 < 0b100) return false; //reject Version < 4
|
||||||
if((ntpPacket[0] & 0b00000111) != 0b100) return false; //reject Mode == Server
|
if((ntpPacket[0] & 0b00000111) != 0b100) return false; //reject Mode != Server
|
||||||
if((ntpPacket[1] < 1) || (ntpPacket[1] > 15)) return false; //reject invalid Stratum
|
if((ntpPacket[1] < 1) || (ntpPacket[1] > 15)) return false; //reject invalid Stratum
|
||||||
if( ntpPacket[16] == 0 && ntpPacket[17] == 0 &&
|
if( ntpPacket[16] == 0 && ntpPacket[17] == 0 &&
|
||||||
ntpPacket[18] == 0 && ntpPacket[19] == 0 &&
|
ntpPacket[18] == 0 && ntpPacket[19] == 0 &&
|
||||||
|
@ -396,7 +396,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
|
|
||||||
//start ntp if not already connected
|
//start ntp if not already connected
|
||||||
if (ntpEnabled && WLED_CONNECTED && !ntpConnected) ntpConnected = ntpUdp.begin(ntpLocalPort);
|
if (ntpEnabled && WLED_CONNECTED && !ntpConnected) ntpConnected = ntpUdp.begin(ntpLocalPort);
|
||||||
ntpLastSyncTime = 0; // force new NTP query
|
ntpLastSyncTime = NTP_NEVER; // force new NTP query
|
||||||
|
|
||||||
longitude = request->arg(F("LN")).toFloat();
|
longitude = request->arg(F("LN")).toFloat();
|
||||||
latitude = request->arg(F("LT")).toFloat();
|
latitude = request->arg(F("LT")).toFloat();
|
||||||
|
@ -133,7 +133,7 @@ void WLED::loop()
|
|||||||
if (lastMqttReconnectAttempt > millis()) {
|
if (lastMqttReconnectAttempt > millis()) {
|
||||||
rolloverMillis++;
|
rolloverMillis++;
|
||||||
lastMqttReconnectAttempt = 0;
|
lastMqttReconnectAttempt = 0;
|
||||||
ntpLastSyncTime = 0;
|
ntpLastSyncTime = NTP_NEVER; // force new NTP query
|
||||||
strip.restartRuntime();
|
strip.restartRuntime();
|
||||||
}
|
}
|
||||||
if (millis() - lastMqttReconnectAttempt > 30000 || lastMqttReconnectAttempt == 0) { // lastMqttReconnectAttempt==0 forces immediate broadcast
|
if (millis() - lastMqttReconnectAttempt > 30000 || lastMqttReconnectAttempt == 0) { // lastMqttReconnectAttempt==0 forces immediate broadcast
|
||||||
|
@ -644,10 +644,11 @@ WLED_GLOBAL String escapedMac;
|
|||||||
WLED_GLOBAL DNSServer dnsServer;
|
WLED_GLOBAL DNSServer dnsServer;
|
||||||
|
|
||||||
// network time
|
// network time
|
||||||
|
#define NTP_NEVER 999000000L
|
||||||
WLED_GLOBAL bool ntpConnected _INIT(false);
|
WLED_GLOBAL bool ntpConnected _INIT(false);
|
||||||
WLED_GLOBAL time_t localTime _INIT(0);
|
WLED_GLOBAL time_t localTime _INIT(0);
|
||||||
WLED_GLOBAL unsigned long ntpLastSyncTime _INIT(999000000L);
|
WLED_GLOBAL unsigned long ntpLastSyncTime _INIT(NTP_NEVER);
|
||||||
WLED_GLOBAL unsigned long ntpPacketSentTime _INIT(999000000L);
|
WLED_GLOBAL unsigned long ntpPacketSentTime _INIT(NTP_NEVER);
|
||||||
WLED_GLOBAL IPAddress ntpServerIP;
|
WLED_GLOBAL IPAddress ntpServerIP;
|
||||||
WLED_GLOBAL uint16_t ntpLocalPort _INIT(2390);
|
WLED_GLOBAL uint16_t ntpLocalPort _INIT(2390);
|
||||||
WLED_GLOBAL uint16_t rolloverMillis _INIT(0);
|
WLED_GLOBAL uint16_t rolloverMillis _INIT(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user