Browse Source
Merge pull request #1294 from liquidraver/factorynvsreset
Add NVS partition reset to ESP factory reset
pull/1313/head
ripplebiz
5 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
8 additions and
1 deletions
-
examples/companion_radio/DataStore.cpp
-
examples/companion_radio/MyMesh.cpp
|
|
|
@ -65,6 +65,7 @@ void DataStore::begin() { |
|
|
|
|
|
|
|
#if defined(ESP32) |
|
|
|
#include <SPIFFS.h> |
|
|
|
#include <nvs_flash.h> |
|
|
|
#elif defined(RP2040_PLATFORM) |
|
|
|
#include <LittleFS.h> |
|
|
|
#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) |
|
|
|
@ -172,7 +173,9 @@ bool DataStore::formatFileSystem() { |
|
|
|
#elif defined(RP2040_PLATFORM) |
|
|
|
return LittleFS.format(); |
|
|
|
#elif defined(ESP32) |
|
|
|
return ((fs::SPIFFSFS *)_fs)->format(); |
|
|
|
bool fs_success = ((fs::SPIFFSFS *)_fs)->format(); |
|
|
|
esp_err_t nvs_err = nvs_flash_erase(); // no need to reinit, will be done by reboot
|
|
|
|
return fs_success && (nvs_err == ESP_OK); |
|
|
|
#else |
|
|
|
#error "need to implement format()" |
|
|
|
#endif |
|
|
|
|
|
|
|
@ -1614,6 +1614,10 @@ void MyMesh::handleCmdFrame(size_t len) { |
|
|
|
writeErrFrame(ERR_CODE_ILLEGAL_ARG); // invalid stats sub-type
|
|
|
|
} |
|
|
|
} else if (cmd_frame[0] == CMD_FACTORY_RESET && memcmp(&cmd_frame[1], "reset", 5) == 0) { |
|
|
|
if (_serial) { |
|
|
|
MESH_DEBUG_PRINTLN("Factory reset: disabling serial interface to prevent reconnects (BLE/WiFi)"); |
|
|
|
_serial->disable(); // Phone app disconnects before we can send OK frame so it's safe here
|
|
|
|
} |
|
|
|
bool success = _store->formatFileSystem(); |
|
|
|
if (success) { |
|
|
|
writeOKFrame(); |
|
|
|
|