Skip to content

Commit

Permalink
Fixed AutoConnectUpdate crashing if there is no OTA partition
Browse files Browse the repository at this point in the history
  • Loading branch information
Hieromon committed Feb 4, 2022
1 parent 394767a commit 4bef741
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/AutoConnectUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* AutoConnectUpdate class implementation.
* @file AutoConnectUpdate.cpp
* @author [email protected]
* @version 1.3.0
* @date 2021-07-23
* @version 1.3.4
* @date 2022-02-03
* @copyright MIT license.
*/

Expand Down Expand Up @@ -82,6 +82,7 @@
#if defined(ARDUINO_ARCH_ESP8266)
using UpdateVariedClass = UpdaterClass;
#elif defined(ARDUINO_ARCH_ESP32)
#include <esp_ota_ops.h>
using UpdateVariedClass = UpdateClass;
#endif

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -493,7 +506,7 @@ String AutoConnectUpdateAct::_onResult(AutoConnectAux& result, PageArgument& arg
break;
case UPDATE_FAIL:
resForm = String(F(" failed."));
resForm += String(F("<br>")) + getLastErrorString();
resForm += String(F("<br>")) + _errString;
resColor = String(F("red"));
break;
default:
Expand All @@ -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<AutoConnectElement>(F("restart")).enable = restart;
_errString.clear();

return String("");
}
Expand Down
1 change: 1 addition & 0 deletions src/AutoConnectUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4bef741

Please sign in to comment.