This commit is contained in:
proddy
2026-05-03 15:19:49 +02:00
parent 666ba41f67
commit eab7cdd7b5
7 changed files with 219 additions and 141 deletions

View File

@@ -359,7 +359,6 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
// either via the Web UI or via the Console
void WebSettingsService::onUpdate() {
// skip if we're restarting anyway
if (WebSettings::has_flags(WebSettings::ChangeFlags::RESTART)) {
return;
}

View File

@@ -369,6 +369,20 @@ void WebStatusService::getVersions(JsonObject root) {
#endif
}
// schedule the next versions.json fetch a few seconds out so the network stack has time to settle
// (DHCP completion, default-netif assignment and DNS server propagation through lwip) before
// HTTPClient::begin() does the hostByName() lookup. Without this delay the very first fetch races
// with the link-up event and arduino-esp32 logs a noisy "DNS Failed ... error '-54'".
void WebStatusService::schedule_versions_refresh() {
#ifndef EMSESP_STANDALONE
uint32_t next = uuid::get_uptime() + VERSIONS_INITIAL_FETCH_DELAY_MS;
if (next == 0) {
next = 1; // 0 is the "idle" sentinel — never let the wrap land there
}
versions_next_fetch_ms_ = next;
#endif
}
// periodic refresh (1 hour) of the cached versions.json
// runs on the main loop task, which has a much bigger stack than AsyncTCP needed for https
void WebStatusService::loop() {
@@ -378,8 +392,6 @@ void WebStatusService::loop() {
return;
}
// TODO handle a network re-connect to fetch the values again (set versions_next_fetch_ms_ to 1)
// 0 = idle, nothing scheduled
if (versions_next_fetch_ms_ == 0) {
return;
@@ -419,7 +431,7 @@ bool WebStatusService::refresh_versions_cache() {
int httpCode = http.GET();
if (httpCode != HTTP_CODE_OK) {
#if defined(EMSESP_DEBUG)
EMSESP::logger().debug("versions.json: HTTP %d", httpCode);
EMSESP::logger().debug("versions.json: HTTP error code %d", httpCode);
#endif
http.end();
return false;

View File

@@ -30,10 +30,11 @@ class WebStatusService {
return versions_cache_valid_;
}
// refresh the versions.json cache
void schedule_versions_refresh() {
versions_next_fetch_ms_ = 1;
}
// schedule a refresh of the versions.json cache. Defers the fetch by
// VERSIONS_INITIAL_FETCH_DELAY_MS so the network stack (DHCP, default netif, DNS server)
// has time to settle after the link first comes up — otherwise hostByName() can fail
// immediately on boot with a noisy "DNS Failed ... error '-54'".
void schedule_versions_refresh();
bool current_upgradeable() const; // true if a newer version is available
@@ -71,8 +72,9 @@ class WebStatusService {
bool refresh_versions_cache(); // does the actual HTTPS fetch + parse, returns true on success
static constexpr uint32_t VERSIONS_REFRESH_INTERVAL_MS = 60UL * 60UL * 1000UL; // 1 hour on success
static constexpr uint32_t VERSIONS_RETRY_INTERVAL_MS = 5UL * 60UL * 1000UL; // 5 min after failure
static constexpr uint32_t VERSIONS_REFRESH_INTERVAL_MS = 60UL * 60UL * 1000UL; // 1 hour on success
static constexpr uint32_t VERSIONS_RETRY_INTERVAL_MS = 5UL * 60UL * 1000UL; // 5 min after failure
static constexpr uint32_t VERSIONS_INITIAL_FETCH_DELAY_MS = 5UL * 1000UL; // 5 s after a link comes up
};
} // namespace emsesp