Retry NTP sooner after a failed attempt
The first NTP attempt after boot usually fails and the retry waited a flat 5 minutes, so the clock showed 00:00 (1970) for 5 minutes after every restart or OTA update. Retries now back off 15 s, 30 s, 1 min ... up to 5 min. Measured after an OTA update: time set at 30 s uptime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b40b5f680c
commit
9f960fae17
2 files changed
+12
-4
No files matched your search
@@ -106,7 +106,7 @@ GPIO0 to GND, tap RST to GND, then release GPIO0.
|
||||
`wledDarkWithTubes` / `wledUseBrightness` live in `prmExt`, stored in EEPROM after `prm` with
|
||||
their own magic value: never add fields to `prm` (a `MAGIC_VALUE` bump factory-resets the
|
||||
clock, WiFi included). HA switch "SignalRGB".
|
||||
7. Done (2026-10-28, not yet on the clock): new web UI. Source `firmware/uniclock/web/index.html`
|
||||
7. Done (2026-10-29, on the clock): new web UI. Source `firmware/uniclock/web/index.html`
|
||||
(one file, no jQuery, controls generated from the `PAGES` table), gzipped by `web/gzip_web.py`
|
||||
to `data/index.html.gz` (12 KB, was 147 KB), served by one `serveStatic` with `no-cache`.
|
||||
Opened from disk it runs on sample data; check it with headless Edge (`msedge --headless=new
|
||||
@@ -114,4 +114,6 @@ GPIO0 to GND, tap RST to GND, then release GPIO0.
|
||||
new fields `ip`, `hasAlarm`, `hasRadar`, real `cathProtMin`; `/getCurrentInfos` has
|
||||
`currentSec` and `mqtt` (0 off / 1 not connected / 2 connected). Network settings save with a
|
||||
Save button and offer a restart.
|
||||
NTP: the first attempt after boot usually fails; retries now back off 15 s, 30 s ... 5 min
|
||||
(was a flat 5 min, so the clock showed 00:00 for 5 minutes after every restart).
|
||||
8. Open: the user can create `secrets.h` (gitignored, never read it) for OTA and web passwords.
|
||||
@@ -878,21 +878,24 @@ void startWifiMode() {
|
||||
|
||||
|
||||
// Primary time source (see calcTime()/docs/DEVELOPER_GUIDE.md 4.4): refreshes the system clock from
|
||||
// NTP over WiFi, at most once every TIMESERVER_REFRESH (2h) - or every 5 minutes if the previous
|
||||
// attempt failed (lastTimeFailure backoff), retrying the NTP request itself up to 5 times per call.
|
||||
// NTP over WiFi, at most once every TIMESERVER_REFRESH (2h) - or, after a failed attempt, again after
|
||||
// 15 s, 30 s, 1 min ... up to 5 min (retryDelay), retrying the NTP request itself up to 5 times per call.
|
||||
// On success, rebuilds myTZ from the current prm.utc_offset/prm.enableDST (so a live timezone/DST
|
||||
// change from the web UI takes effect on the very next scheduled refresh) and calls setTime() with
|
||||
// the timezone-adjusted local time. Returns true only if this call actually refreshed the clock -
|
||||
// callers (calcTime()) use that to decide whether the RTC also needs updating this cycle.
|
||||
boolean updateTimefromTimeserver() { //true, if successful
|
||||
static unsigned long lastTimeFailure = 0;
|
||||
static unsigned long retryDelay = 15000; //after a failure: 15 s, then doubled each time, at most 5 min
|
||||
boolean res = false;
|
||||
int count = 1;
|
||||
|
||||
if (((millis()-lastTimeUpdate)<TIMESERVER_REFRESH) && (lastTimeUpdate!=0))
|
||||
return(res);
|
||||
|
||||
if ((lastTimeFailure>0) && ((millis()-lastTimeFailure)<300000)) return(res); //wait for 5min to retry, if no success
|
||||
// FIXED: was a flat 5 min, and the first attempt right after boot usually fails, so the clock showed
|
||||
// 00:00 (1970) for 5 minutes after every restart or OTA update.
|
||||
if ((lastTimeFailure>0) && ((millis()-lastTimeFailure)<retryDelay)) return(res);
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
while (true) {
|
||||
@@ -911,12 +914,15 @@ boolean updateTimefromTimeserver() { //true, if successful
|
||||
DPRINT(" time:"); DPRINT(hour()); DPRINT(":"); DPRINT(minute()); DPRINT(":"); DPRINTLN(second());
|
||||
DPRINTLN("Clock refreshed from timeserver.");
|
||||
lastTimeFailure = 0;
|
||||
retryDelay = 15000;
|
||||
}
|
||||
count ++;
|
||||
if (res) break; //success!!!
|
||||
Fdelay(1000);
|
||||
if (count > 5) { //failure, but stop trying
|
||||
if (lastTimeFailure > 0) retryDelay = min(retryDelay * 2, 300000ul);
|
||||
lastTimeFailure = millis();
|
||||
DPRINT("Timeserver failed, next try in "); DPRINT(retryDelay / 1000); DPRINTLN(" s");
|
||||
break;
|
||||
}
|
||||
} //end while
|
||||
|
||||
Reference in new issue
Block a user