proddy
2026-04-26 16:10:30 +02:00
parent 74062bab57
commit 3a11327e7e
9 changed files with 290 additions and 168 deletions

View File

@@ -19,6 +19,17 @@ class WebStatusService {
return current_version_s;
}
// 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
void loop();
// true once we've had at least one successful versions.json fetch
bool versions_cache_valid() const {
return versions_cache_valid_;
}
bool current_upgradeable() const; // true if a newer version is available
// make action function public so we can test in the debug and standalone mode
#ifndef EMSESP_STANDALONE
protected:
@@ -30,7 +41,7 @@ class WebStatusService {
SecurityManager * _securityManager;
// actions
bool checkUpgrade(JsonObject root, std::string & latest_version);
void getVersions(JsonObject root);
bool exportData(JsonObject root, std::string & type);
bool getCustomSupport(JsonObject root);
bool uploadURL(const char * url);
@@ -39,6 +50,23 @@ class WebStatusService {
uint8_t upgradeImportantMessages(std::string & version);
std::string current_version_s = EMSESP_APP_VERSION;
// cached emsesp.org/versions.json. Refreshed from the main loop task, which has more stack.
struct VersionInfo {
std::string version;
std::string date;
bool upgradeable = false;
};
VersionInfo versions_stable_;
VersionInfo versions_dev_;
bool versions_cache_valid_ = false; // true once we've had at least one successful fetch
uint32_t versions_next_fetch_ms_ = 0; // uuid::get_uptime() of the next attempt; 0 = ASAP
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_INITIAL_DELAY_MS = 30UL * 1000UL; // wait 30s after boot
};
} // namespace emsesp