diff --git a/src/Arduino_ESP32_OTA.cpp b/src/Arduino_ESP32_OTA.cpp index 9839e0a..b6335b4 100644 --- a/src/Arduino_ESP32_OTA.cpp +++ b/src/Arduino_ESP32_OTA.cpp @@ -71,6 +71,11 @@ Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin() /* ... initialize CRC ... */ _crc32 = 0xFFFFFFFF; + + if(!isCapable()) { + DEBUG_ERROR("%s: board is not capable to perform OTA", __FUNCTION__); + return Error::NoOtaStorage; + } if(!Update.begin(UPDATE_SIZE_UNKNOWN)) { DEBUG_ERROR("%s: failed to initialize flash update", __FUNCTION__); @@ -195,7 +200,7 @@ int Arduino_ESP32_OTA::download(const char * ota_url) return static_cast(Error::HttpResponse); } - /* Extract concent length from HTTP header. A typical entry looks like + /* Extract content length from HTTP header. A typical entry looks like * "Content-Length: 123456" */ char const * content_length_ptr = strstr(http_header.c_str(), "Content-Length"); @@ -279,3 +284,10 @@ void Arduino_ESP32_OTA::reset() { ESP.restart(); } + +bool Arduino_ESP32_OTA::isCapable() +{ + const esp_partition_t * ota_0 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL); + const esp_partition_t * ota_1 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL); + return ((ota_0 != nullptr) && (ota_1 != nullptr)); +} diff --git a/src/Arduino_ESP32_OTA.h b/src/Arduino_ESP32_OTA.h index 5062003..069d22b 100644 --- a/src/Arduino_ESP32_OTA.h +++ b/src/Arduino_ESP32_OTA.h @@ -87,6 +87,7 @@ class Arduino_ESP32_OTA void write_byte_to_flash(uint8_t data); Arduino_ESP32_OTA::Error update(); void reset(); + static bool isCapable(); private: