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

@@ -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;