diff --git a/src/AutoConnectUpdate.cpp b/src/AutoConnectUpdate.cpp index 1a4fe36c..5bc34fff 100644 --- a/src/AutoConnectUpdate.cpp +++ b/src/AutoConnectUpdate.cpp @@ -2,8 +2,8 @@ * AutoConnectUpdate class implementation. * @file AutoConnectUpdate.cpp * @author hieromon@gmail.com - * @version 1.3.0 - * @date 2021-07-23 + * @version 1.3.4 + * @date 2022-02-03 * @copyright MIT license. */ @@ -82,6 +82,7 @@ #if defined(ARDUINO_ARCH_ESP8266) using UpdateVariedClass = UpdaterClass; #elif defined(ARDUINO_ARCH_ESP32) +#include using UpdateVariedClass = UpdateClass; #endif @@ -258,11 +259,23 @@ AC_UPDATESTATUS_t AutoConnectUpdateAct::update(void) { if (_binName.length()) { WiFiClient wifiClient; AC_DBG("%s:%d/%s update in progress...", host.c_str(), port, uriBin.c_str()); - t_httpUpdate_return ret = HTTPUpdateClass::update(wifiClient, host, port, uriBin); + t_httpUpdate_return ret; +#ifdef ARDUINO_ARCH_ESP32 + // Check if an available OTA partition exists. + const esp_partition_t* runningPartition = esp_ota_get_running_partition(); + const esp_partition_t* otaPartition = esp_ota_get_next_update_partition(NULL); + if (!strcmp(runningPartition->label, otaPartition->label)) { + _errString = String(F("No available OTA partition")); + ret = HTTP_UPDATE_FAILED; + } + else +#endif + if ((ret = HTTPUpdateClass::update(wifiClient, host, port, uriBin)) != HTTP_UPDATE_OK) + _errString = getLastErrorString(); switch (ret) { case HTTP_UPDATE_FAILED: _status = UPDATE_FAIL; - AC_DBG_DUMB(" %s\n", getLastErrorString().c_str()); + AC_DBG_DUMB(" %s\n", _errString.c_str()); AC_DBG("update returns HTTP_UPDATE_FAILED\n"); break; case HTTP_UPDATE_NO_UPDATES: @@ -493,7 +506,7 @@ String AutoConnectUpdateAct::_onResult(AutoConnectAux& result, PageArgument& arg break; case UPDATE_FAIL: resForm = String(F(" failed.")); - resForm += String(F("
")) + getLastErrorString(); + resForm += String(F("
")) + _errString; resColor = String(F("red")); break; default: @@ -505,6 +518,7 @@ String AutoConnectUpdateAct::_onResult(AutoConnectAux& result, PageArgument& arg resultElm.value = _binName + resForm; resultElm.style = String(F("font-size:120%;color:")) + resColor; result.getElement(F("restart")).enable = restart; + _errString.clear(); return String(""); } diff --git a/src/AutoConnectUpdate.h b/src/AutoConnectUpdate.h index 2d549fc7..47af337a 100644 --- a/src/AutoConnectUpdate.h +++ b/src/AutoConnectUpdate.h @@ -155,6 +155,7 @@ class AutoConnectUpdateAct : public AutoConnectUpdateVoid, public HTTPUpdateClas AC_UPDATEDIALOG_t _dialog; /**< The type of updating dialog displayed on the client */ AC_UPDATESTATUS_t _status; /**< Status of update processing during the cycle of receiving a request */ String _binName; /**< .bin name to update */ + String _errString; /**< error text reservation */ WebServerClass* _webServer; /**< Hosted WebServer for XMLHttpRequest */ static const AutoConnectAux::ACPage_t _pageCatalog PROGMEM;