diff --git a/CHANGELOG.md b/CHANGELOG.md index 421284e..12f5270 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,5 +5,4 @@ - Add Github action to check version - Add version.json file - Add device value in platform - - Add auto OTA update check on start \ No newline at end of file diff --git a/src/network/autoupdate.cpp b/src/network/autoupdate.cpp index 1021e6d..3aa1f95 100644 --- a/src/network/autoupdate.cpp +++ b/src/network/autoupdate.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #else #include #include @@ -16,7 +17,7 @@ #include "utils/log.h" const std::string AUTOUPDATE_URL = "https://raw.githubusercontent.com/matteocrippa/leafminer/main/version.json"; -const char TAG_AUTOUPDATE[] = "autoupdate"; +const char TAG_AUTOUPDATE[] = "AutoUpdate"; #if defined(ESP8266_D) std::string DEVICE = "esp8266"; @@ -42,11 +43,19 @@ void autoupdate() while (WiFi.waitForConnectResult() != WL_CONNECTED) { WiFi.begin(configuration.wifi_ssid.c_str(), configuration.wifi_password.c_str()); - delay(800); + delay(500); } HTTPClient http; + #if defined(ESP8266) + std::unique_ptr client(new BearSSL::WiFiClientSecure); + client->setInsecure(); + http.begin(*client, AUTOUPDATE_URL.c_str()); + #else http.begin(AUTOUPDATE_URL.c_str()); + #endif + http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS); + int httpCode = http.GET(); if (httpCode == HTTP_CODE_OK) { @@ -110,7 +119,11 @@ void autoupdate() l_debug(TAG_AUTOUPDATE, "Downloading: %s", downloadUrl.c_str()); + #if defined(ESP8266) + http.begin(*client, downloadUrl.c_str()); + #else http.begin(downloadUrl.c_str()); + #endif http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS); int httpCode = http.GET();