Skip to content

Commit

Permalink
Fix/update esp8266 (#12)
Browse files Browse the repository at this point in the history
* fix changelog

* tweaks for esp8266

* fix esp8266

---------

Co-authored-by: Matteo Crippa <[email protected]>
  • Loading branch information
matteocrippa and Matteo Crippa authored Jan 27, 2024
1 parent fe7260b commit 6d23b43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 15 additions & 2 deletions src/network/autoupdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <ESP8266WiFi.h>
#include <Updater.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#else
#include <WiFi.h>
#include <Update.h>
Expand All @@ -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";
Expand All @@ -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<BearSSL::WiFiClientSecure> 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)
{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6d23b43

Please sign in to comment.