Add Update button (#533) (#612)

This commit is contained in:
Darrell 2022-08-25 08:23:57 -04:00 committed by GitHub
parent 3a4f9a09d0
commit 06905b4d30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 7 deletions

View File

@ -4,23 +4,26 @@
#include <esp_ota_ops.h>
#include <esp_partition.h>
bool isSameVersion(WiFiClientSecure& client, const String& url, const String& version) {
bool hasNewVersion(WiFiClientSecure& client, const String& url, const String& version) {
HTTPClient http;
if (!http.begin(client, url))
return false;
bool ret = false;
int httpCode = http.sendRequest("HEAD");
bool ret = httpCode > 300 && httpCode < 400 && http.getLocation().indexOf(version) <= 0;
if (ret) Serial.printf("Updating from (sc=%d): %s\n", httpCode, http.getLocation().c_str());
else Serial.printf("Not updating from (sc=%d): %s\n", httpCode, http.getLocation().c_str());
bool isRedirect = httpCode > 300 && httpCode < 400;
if (isRedirect) {
if (http.getLocation().indexOf(version) < 0){
Serial.printf("Found new version: %s\n", http.getLocation().c_str());
ret = true;
}
} else Serial.printf("Error on checking for update (sc=%d)\n", httpCode);
http.end();
return ret;
}
HttpUpdateResult HttpReleaseUpdate::update(WiFiClientSecure& client, const String& url, const String& version) {
if (version.length() > 0 && isSameVersion(client, url, version))
if (version.length() > 0 && !hasNewVersion(client, url, version))
return HTTP_UPDATE_NO_UPDATES;
HTTPClient http;