Skip to content

Commit f8a8251

Browse files
committed
Requested changes.
1 parent c952ffc commit f8a8251

File tree

5 files changed

+40
-33
lines changed

5 files changed

+40
-33
lines changed

cores/esp8266/Esp.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ struct rst_info * EspClass::getResetInfoPtr(void) {
519519
return &resetInfo;
520520
}
521521

522-
bool EspClass::eraseConfig(bool reset) {
522+
bool EspClass::eraseConfig(void) {
523523
const size_t cfgSize = 0x4000; // Sectors: RF_CAL + SYSTEMPARAM[3]
524524
size_t cfgAddr = ESP.getFlashChipSize() - cfgSize;
525525

@@ -529,12 +529,16 @@ bool EspClass::eraseConfig(bool reset) {
529529
}
530530
}
531531

532+
return true;
533+
}
534+
535+
bool EspClass::eraseConfigAndReset(void) {
536+
bool reset = eraseConfig();
532537
if (reset) {
533538
// Must be called in WiFi.mode(WIFI_OFF) state.
534539
hardware_reset();
535540
}
536-
537-
return true;
541+
return reset;
538542
}
539543

540544
uint8_t *EspClass::random(uint8_t *resultArray, const size_t outputSizeBytes)

cores/esp8266/Esp.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,22 @@ class EspClass {
210210
static String getResetInfo();
211211
static struct rst_info * getResetInfoPtr();
212212

213+
static bool eraseConfig();
214+
213215
/*
214-
Erases 4 sectors at the end of flash, 1 - RF_CAL and 3 - SYSTEMPARM.
215-
These are the same additional sectors that are erase when you select
216-
Erase Flash: "Sketch + WiFi Settings" from the Arduino IDE Tools menu.
216+
Erases 4 sectors at the end of flash, 1 - RF_CAL and 3 - SYSTEMPARM.
217+
These are the same additional sectors that are erase when you select
218+
Erase Flash: "Sketch + WiFi Settings" from the Arduino IDE Tools menu.
217219
218-
As a precaution, since this operation erases the running SDKs flash
219-
configuration space, use reset flag "true" with eraseConfig. Also, for
220-
additional protection, call "WiFi.mode(WIFI_OFF)" before calling.
220+
As a precaution, since this operation erases the running SDKs flash
221+
configuration space, use reset flag "true" with eraseConfig. Also, for
222+
additional protection, call "WiFi.mode(WIFI_OFF)" before calling.
221223
222-
If you need to erase "WiFi Settings" and reboot consider using
223-
"ArduinoOTA.eraseConfigAndReset()" it handles shutting down WiFi
224-
before the erase.
224+
If you need to erase "WiFi Settings" and reboot consider using
225+
"ArduinoOTA.eraseConfigAndReset()" it handles shutting down WiFi
226+
before the erase.
225227
*/
226-
static bool eraseConfig(bool reset = false);
228+
static bool eraseConfigAndReset();
227229

228230
static uint8_t *random(uint8_t *resultArray, const size_t outputSizeBytes);
229231
static uint32_t random();

libraries/ArduinoOTA/ArduinoOTA.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ void ArduinoOTAClass::setPasswordHash(const char * password) {
9191
}
9292
}
9393

94-
void ArduinoOTAClass::setRebootOnSuccess(bool reboot, ota_erase_cfg_t eraseConfig){
94+
void ArduinoOTAClass::setRebootOnSuccess(bool reboot){
9595
_rebootOnSuccess = reboot;
96+
}
97+
98+
void ArduinoOTAClass::setEraseConfig(ota_erase_cfg_t eraseConfig){
9699
_eraseConfig = eraseConfig;
97100
}
98101

@@ -371,8 +374,8 @@ void ArduinoOTAClass::end() {
371374
void ArduinoOTAClass::eraseConfigAndReset() {
372375
OTA_DEBUG_PRINTF("Erase Config and Hard Reset ...\n");
373376
if (WiFi.mode(WIFI_OFF)) {
374-
ESP.eraseConfig(true); // No return testing - Only returns on failure
375-
OTA_DEBUG_PRINTF(" ESP.eraseConfig(true) failed!\n");
377+
ESP.eraseConfigAndReset(); // No return testing - Only returns on failure
378+
OTA_DEBUG_PRINTF(" ESP.eraseConfigAndReset() failed!\n");
376379
} else {
377380
OTA_DEBUG_PRINTF(" WiFi.mode(WIFI_OFF) Timeout!\n");
378381
}

libraries/ArduinoOTA/ArduinoOTA.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ class ArduinoOTAClass
5252
void setPasswordHash(const char *password);
5353

5454
//Sets if the device should be rebooted after successful update. Default true
55-
//"eraseConfig" selects to erase WiFi Settings in conjunction with a reboot
56-
//after a successful update. Default OTA_ERASE_CFG_NO - Legacy behavior
57-
void setRebootOnSuccess(bool reboot, ota_erase_cfg_t eraseConfig = OTA_ERASE_CFG_NO);
55+
void setRebootOnSuccess(bool reboot);
5856

59-
//Sets flag to erase WiFi Settings at reboot/reset.
60-
void setEraseConfig(bool eraseConfig = true);
57+
//Sets flag to erase WiFi Settings at reboot/reset. "eraseConfig" selects to
58+
//abort erase on failure or ignore error and erase.
59+
void setEraseConfig(ota_erase_cfg_t eraseConfig = OTA_ERASE_CFG_ABORT_ON_ERROR);
6160

6261
//This callback will be called when OTA connection has begun
6362
void onStart(THandlerFunction fn);

libraries/ArduinoOTA/examples/OTAEraseConfig/OTAEraseConfig.ino

+11-12
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,24 @@ void setup() {
5757
ArduinoOTA.onEnd([]() {
5858
Serial.println("\nEnd");
5959
/*
60-
By calling "ArduinoOTA.setRebootOnSuccess(true,
61-
ArduinoOTA::OTA_ERASE_CFG_ABORT_ON_ERROR)," this example will erase the
62-
"WiFi Settings" as part of an OTA update. When erasing WiFi Settings
63-
fails, the OTA Update aborts, and eboot will not copy the new ".bin" in
64-
place.
60+
By calling "ArduinoOTA.setEraseConfig(ArduinoOTA::OTA_ERASE_CFG_ABORT_ON_ERROR),"
61+
this example will erase the "WiFi Settings" as part of an OTA update. When
62+
erasing WiFi Settings fails, the OTA Update aborts, and eboot will not
63+
copy the new ".bin" in place.
6564
66-
Without the call to "ArduinoOTA.setRebootOnSuccess," the system restarts
67-
without touching the WiFi Settings legacy behavior.
65+
Without the call to "ArduinoOTA.setEraseConfig" legacy behavior, the
66+
system restarts without touching the WiFi Settings.
6867
69-
Options for "eraseConfig" and how to handle failures:
68+
Options for "setEraseConfig" to handle eraseConfig failures:
7069
OTA_ERASE_CFG_NO - Do not erase WiFi Settings
7170
OTA_ERASE_CFG_IGNORE_ERROR - Ignore the error and continue with update ".bin" copy
7271
OTA_ERASE_CFG_ABORT_ON_ERROR - Cancel flash update copy at reboot
7372
74-
Update the conditional below to meet your requirements.
73+
To meet unique requirements, you can make the call below conditional.
74+
Also, this call could be enabled before ArduinoOTA.onEnd() and canceled
75+
here with "ArduinoOTA.setEraseConfig(OTA_ERASE_CFG_NO)."
7576
*/
76-
if (true) {
77-
ArduinoOTA.setRebootOnSuccess(true, OTA_ERASE_CFG_ABORT_ON_ERROR);
78-
}
77+
ArduinoOTA.setEraseConfig(OTA_ERASE_CFG_ABORT_ON_ERROR);
7978
});
8079
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
8180
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));

0 commit comments

Comments
 (0)