Skip to content

Commit 6d23b43

Browse files
matteocrippaMatteo Crippa
andauthored
Fix/update esp8266 (#12)
* fix changelog * tweaks for esp8266 * fix esp8266 --------- Co-authored-by: Matteo Crippa <matteocrippa@github.users.com>
1 parent fe7260b commit 6d23b43

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
- Add Github action to check version
66
- Add version.json file
77
- Add device value in platform
8-
98
- Add auto OTA update check on start

src/network/autoupdate.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <ESP8266WiFi.h>
33
#include <Updater.h>
44
#include <ESP8266HTTPClient.h>
5+
#include <WiFiClientSecureBearSSL.h>
56
#else
67
#include <WiFi.h>
78
#include <Update.h>
@@ -16,7 +17,7 @@
1617
#include "utils/log.h"
1718

1819
const std::string AUTOUPDATE_URL = "https://raw.githubusercontent.com/matteocrippa/leafminer/main/version.json";
19-
const char TAG_AUTOUPDATE[] = "autoupdate";
20+
const char TAG_AUTOUPDATE[] = "AutoUpdate";
2021

2122
#if defined(ESP8266_D)
2223
std::string DEVICE = "esp8266";
@@ -42,11 +43,19 @@ void autoupdate()
4243
while (WiFi.waitForConnectResult() != WL_CONNECTED)
4344
{
4445
WiFi.begin(configuration.wifi_ssid.c_str(), configuration.wifi_password.c_str());
45-
delay(800);
46+
delay(500);
4647
}
4748

4849
HTTPClient http;
50+
#if defined(ESP8266)
51+
std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);
52+
client->setInsecure();
53+
http.begin(*client, AUTOUPDATE_URL.c_str());
54+
#else
4955
http.begin(AUTOUPDATE_URL.c_str());
56+
#endif
57+
http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
58+
5059
int httpCode = http.GET();
5160
if (httpCode == HTTP_CODE_OK)
5261
{
@@ -110,7 +119,11 @@ void autoupdate()
110119

111120
l_debug(TAG_AUTOUPDATE, "Downloading: %s", downloadUrl.c_str());
112121

122+
#if defined(ESP8266)
123+
http.begin(*client, downloadUrl.c_str());
124+
#else
113125
http.begin(downloadUrl.c_str());
126+
#endif
114127
http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
115128

116129
int httpCode = http.GET();

0 commit comments

Comments
 (0)