1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-28 05:01:28 +03:00

A new approach for erasing WiFi Settings (#8828)

* A new approach for erasing WiFi Settings

Add support for hardware reset function call - simulates EXT_RST via HWDT.

Add reset selection to `ESP.eraseConfig()` for calling hardware reset
after erasing the WiFi Settings.

Update ArduinoOTA to use `ESP.eraseConfig(true)`

Externalized `ArduinoOTA.eraseConfigAndReset()`

Add OTA examples to illustrate using erase config changes.

* style
fixed confused example

* improve wording

* Add new state to retry eraseConfigAndReset

* Removed unreachable error test from examples.

Removed continuous retry of "eraseConfig" and allow the script to
assign an error handling option for "eraseConfig" failure.

Update example to use error handling option.

* In eboot for function ets_wdt_enable() added missing arguments

* Update comments and example

* Wording

* Rebuilt eboot.elf with current tools from ./get.py

* Requested changes.

* cleanup comments

* Update hardware_reset

Avoid using "[[noreturn]]" - not accepted for a .c file function
Updated to use __attribute__((noreturn)) to handle both .cpp and .c
file functions.
This commit is contained in:
M Hightower
2023-08-29 08:24:07 -07:00
committed by GitHub
parent 1a4663fbe8
commit a348833a81
10 changed files with 531 additions and 34 deletions

View File

@ -18,9 +18,16 @@ typedef enum {
OTA_BEGIN_ERROR,
OTA_CONNECT_ERROR,
OTA_RECEIVE_ERROR,
OTA_END_ERROR
OTA_END_ERROR,
OTA_ERASE_SETTINGS_ERROR
} ota_error_t;
typedef enum {
OTA_ERASE_CFG_NO = 0,
OTA_ERASE_CFG_IGNORE_ERROR,
OTA_ERASE_CFG_ABORT_ON_ERROR
} ota_erase_cfg_t;
class ArduinoOTAClass
{
public:
@ -47,6 +54,10 @@ class ArduinoOTAClass
//Sets if the device should be rebooted after successful update. Default true
void setRebootOnSuccess(bool reboot);
//Sets flag to erase WiFi Settings at reboot/reset. "eraseConfig" selects to
//abort erase on failure or ignore error and erase.
void setEraseConfig(ota_erase_cfg_t eraseConfig = OTA_ERASE_CFG_ABORT_ON_ERROR);
//This callback will be called when OTA connection has begun
void onStart(THandlerFunction fn);
@ -64,6 +75,11 @@ class ArduinoOTAClass
//Ends the ArduinoOTA service
void end();
//Has the effect of the "+ WiFi Settings" in the Arduino IDE Tools "Erase
//Flash" selection. Only returns on erase flash failure.
void eraseConfigAndReset();
//Call this in loop() to run the service. Also calls MDNS.update() when begin() or begin(true) is used.
void handle();
@ -84,6 +100,7 @@ class ArduinoOTAClass
bool _initialized = false;
bool _rebootOnSuccess = true;
bool _useMDNS = true;
ota_erase_cfg_t _eraseConfig = OTA_ERASE_CFG_NO;
ota_state_t _state = OTA_IDLE;
int _size = 0;
int _cmd = 0;