mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-10-28 11:14:58 +00:00
fix auto version fetch, make it non-blocking
This commit is contained in:
@@ -359,6 +359,8 @@ void WebStatusService::getVersions(JsonObject root) {
|
|||||||
dev = versions_dev_;
|
dev = versions_dev_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
versions_fetch_requested_ = true;
|
||||||
|
|
||||||
if (!cache_valid) {
|
if (!cache_valid) {
|
||||||
// no successful fetch yet (no network, fetch pending, or parse error)
|
// no successful fetch yet (no network, fetch pending, or parse error)
|
||||||
return;
|
return;
|
||||||
@@ -402,12 +404,12 @@ void WebStatusService::schedule_versions_refresh() {
|
|||||||
versions_next_fetch_ms_ = next;
|
versions_next_fetch_ms_ = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// periodic refresh (1 hour) of the cached versions.json, only when auto_fw_check is enabled
|
// refresh of the cached versions.json, at most once a day
|
||||||
// runs on the main loop task so the blocking fetch never happens in an AsyncTCP callback
|
|
||||||
void WebStatusService::loop() {
|
void WebStatusService::loop() {
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
// only reach out to emsesp.org if the user has asked us to
|
// with auto_fw_check off we only reach out to emsesp.org when the WebUI asks for version
|
||||||
if (!EMSESP::system_.auto_fw_check()) {
|
// information, so an unattended system never contacts it at all
|
||||||
|
if (!EMSESP::system_.auto_fw_check() && !versions_fetch_requested_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,6 +428,8 @@ void WebStatusService::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
versions_fetch_requested_ = false;
|
||||||
|
|
||||||
uint32_t interval;
|
uint32_t interval;
|
||||||
if (refresh_versions_cache()) {
|
if (refresh_versions_cache()) {
|
||||||
versions_failures_ = 0;
|
versions_failures_ = 0;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "../core/firmwareVersion.h"
|
#include "../core/firmwareVersion.h"
|
||||||
#include "../emsesp_version.h"
|
#include "../emsesp_version.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
@@ -23,6 +24,7 @@ class WebStatusService {
|
|||||||
|
|
||||||
// called from EMSESP::loop() to refresh the cached versions.json from emsesp.org
|
// called from EMSESP::loop() to refresh the cached versions.json from emsesp.org
|
||||||
// so that the web request handler never has to do blocking HTTPS on the small AsyncTCP stack
|
// so that the web request handler never has to do blocking HTTPS on the small AsyncTCP stack
|
||||||
|
// fetches on a daily schedule when auto_fw_check is on, otherwise only when getVersions asks
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
// true once we've had at least one successful versions.json fetch
|
// true once we've had at least one successful versions.json fetch
|
||||||
@@ -71,6 +73,10 @@ class WebStatusService {
|
|||||||
uint32_t versions_next_fetch_ms_ = 0; // uuid::get_uptime() of the next attempt; 0 = idle
|
uint32_t versions_next_fetch_ms_ = 0; // uuid::get_uptime() of the next attempt; 0 = idle
|
||||||
uint8_t versions_failures_ = 0; // consecutive failed fetches, drives the retry backoff
|
uint8_t versions_failures_ = 0; // consecutive failed fetches, drives the retry backoff
|
||||||
|
|
||||||
|
// set by getVersions() on the AsyncTCP task, consumed by the loop task, so that the WebUI still
|
||||||
|
// gets version information when auto_fw_check is off
|
||||||
|
std::atomic<bool> versions_fetch_requested_{false};
|
||||||
|
|
||||||
// the cache is written by the loop task in refresh_versions_cache() and read by the AsyncTCP
|
// the cache is written by the loop task in refresh_versions_cache() and read by the AsyncTCP
|
||||||
// task in getVersions()/current_upgradeable(), so the std::strings need guarding - without it a
|
// task in getVersions()/current_upgradeable(), so the std::strings need guarding - without it a
|
||||||
// request landing mid-update reads a buffer that has just been freed
|
// request landing mid-update reads a buffer that has just been freed
|
||||||
@@ -80,7 +86,7 @@ class WebStatusService {
|
|||||||
|
|
||||||
static constexpr const char * VERSIONS_URL = "http://emsesp.org/versions.json";
|
static constexpr const char * VERSIONS_URL = "http://emsesp.org/versions.json";
|
||||||
|
|
||||||
static constexpr uint32_t VERSIONS_REFRESH_INTERVAL_MS = 60UL * 60UL * 1000UL; // 1 hour on success
|
static constexpr uint32_t VERSIONS_REFRESH_INTERVAL_MS = 24UL * 60UL * 60UL * 1000UL; // once a day on success
|
||||||
static constexpr uint32_t VERSIONS_RETRY_INTERVAL_MS = 5UL * 60UL * 1000UL; // 5 min after the first failure
|
static constexpr uint32_t VERSIONS_RETRY_INTERVAL_MS = 5UL * 60UL * 1000UL; // 5 min after the first failure
|
||||||
static constexpr uint32_t VERSIONS_INITIAL_FETCH_DELAY_MS = 5UL * 1000UL; // 5 s after a link comes up
|
static constexpr uint32_t VERSIONS_INITIAL_FETCH_DELAY_MS = 5UL * 1000UL; // 5 s after a link comes up
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user