Skip to content

Commit

Permalink
Fix build with esp core greater than 3.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Nov 25, 2024
1 parent 5ed0df5 commit 79fd218
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/Arduino_ESP32_OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Arduino_ESP32_OTA::Arduino_ESP32_OTA()
, _http_client(nullptr)
,_ca_cert{amazon_root_ca}
,_ca_cert_bundle{nullptr}
,_ca_cert_bundle_size(0)
,_magic(0)
{

Expand Down Expand Up @@ -83,6 +84,14 @@ void Arduino_ESP32_OTA::setCACertBundle (const uint8_t * bundle)
}
}

void Arduino_ESP32_OTA::setCACertBundle (const uint8_t * bundle, size_t size)
{
if(bundle != nullptr && size != 0) {
_ca_cert_bundle = bundle;
_ca_cert_bundle_size = size;
}
}

void Arduino_ESP32_OTA::setMagic(uint32_t magic)
{
_magic = magic;
Expand Down Expand Up @@ -114,9 +123,17 @@ int Arduino_ESP32_OTA::startDownload(const char * ota_url)
_client = new WiFiClientSecure();
if (_ca_cert != nullptr) {
static_cast<WiFiClientSecure*>(_client)->setCACert(_ca_cert);
} else if (_ca_cert_bundle != nullptr) {
}
#if (ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(3, 0, 4))
else if (_ca_cert_bundle != nullptr) {
static_cast<WiFiClientSecure*>(_client)->setCACertBundle(_ca_cert_bundle);
} else {
}
#else
else if (_ca_cert_bundle != nullptr && _ca_cert_bundle_size != 0) {
static_cast<WiFiClientSecure*>(_client)->setCACertBundle(_ca_cert_bundle, _ca_cert_bundle_size);
}
#endif
else {
DEBUG_VERBOSE("%s: CA not configured for download client");
}
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/Arduino_ESP32_OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <Arduino_DebugUtils.h>
#include <WiFiClientSecure.h>
#include <WiFi.h>
#include "decompress/utility.h"
#include "decompress/lzss.h"
#include <ArduinoHttpClient.h>
Expand Down Expand Up @@ -87,7 +88,8 @@ class Arduino_ESP32_OTA
Arduino_ESP32_OTA::Error begin(uint32_t magic = ARDUINO_ESP32_OTA_MAGIC);
void setMagic(uint32_t magic);
void setCACert(const char *rootCA);
void setCACertBundle(const uint8_t * bundle);
void setCACertBundle(const uint8_t * bundle) __attribute__((deprecated));
void setCACertBundle (const uint8_t * bundle, size_t size);

// blocking version for the download
// returns the size of the downloaded binary
Expand Down Expand Up @@ -151,6 +153,7 @@ class Arduino_ESP32_OTA
HttpClient* _http_client;
const char * _ca_cert;
const uint8_t * _ca_cert_bundle;
size_t _ca_cert_bundle_size;
uint32_t _magic;

void clean();
Expand Down

0 comments on commit 79fd218

Please sign in to comment.