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 00f06d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 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_budle_size(0)
,_magic(0)
{

Expand Down Expand Up @@ -76,12 +77,22 @@ void Arduino_ESP32_OTA::setCACert (const char *rootCA)
}
}

#if (ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(3, 0, 4))
void Arduino_ESP32_OTA::setCACertBundle (const uint8_t * bundle)
{
if(bundle != nullptr) {
_ca_cert_bundle = bundle;
}
}
#else
void Arduino_ESP32_OTA::setCACertBundle (const uint8_t * bundle, size_t size)
{
if(bundle != nullptr && size != 0) {
_ca_cert_bundle = bundle;
_ca_cert_budle_size = size;
}
}
#endif

void Arduino_ESP32_OTA::setMagic(uint32_t magic)
{
Expand Down Expand Up @@ -115,7 +126,11 @@ int Arduino_ESP32_OTA::startDownload(const char * ota_url)
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))
static_cast<WiFiClientSecure*>(_client)->setCACertBundle(_ca_cert_bundle);
#else
static_cast<WiFiClientSecure*>(_client)->setCACertBundle(_ca_cert_bundle, _ca_cert_budle_size);
#endif
} else {
DEBUG_VERBOSE("%s: CA not configured for download client");
}
Expand Down
6 changes: 6 additions & 0 deletions 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,11 @@ 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);
#if (ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(3, 0, 4))
void setCACertBundle(const uint8_t * bundle);
#else
void setCACertBundle (const uint8_t * bundle, size_t size);
#endif

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

void clean();
Expand Down

0 comments on commit 00f06d5

Please sign in to comment.