"Factory reset" feature

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
mrsnail
Posts: 5
Joined: Thu Apr 01, 2021 9:00 am
Location: Vienna, Austria

"Factory reset" feature

Post by mrsnail » Fri Apr 30, 2021 8:29 am

Hi

I'm curious if there is a way to "factory-reset" a board (ESP32 in my case) to the original state of a fresh Micropython installation, typically found in commercial hardware solutions. This often involves pressing a button for some time while restoring power, or other techniques.

What I want to achieve basically is that someone without deeper know-how in Micropython can reset their chip to the firmware state as it was when freshly flashed. So basically it would need to:
  • delete any WiFi credentials
  • delete files created beginning first boot
Is there a way to do this? I don't have much know-how about Micropython yet, but I thought of a custom filesystem that can be cleared when some buttons are pressed.

Second idea I've had would be to put some code in main.py at the beginning that checks for i.e. a reboot reason (don't know if I can somehow determine if i.e. a button was pressed during startup)

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: "Factory reset" feature

Post by karfas » Fri Apr 30, 2021 10:18 am

Use the source, Luke ;)

See https://github.com/micropython/micropyt ... nisetup.py how the initial filesystem (+some files) gets created.

I assume that a similar approach works for a "factory reset", given you have the required filesystem content somewhere (in frozen modules, another filesystem, tarfile, whereever).

Regards,
Thomas
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

mrsnail
Posts: 5
Joined: Thu Apr 01, 2021 9:00 am
Location: Vienna, Austria

Re: "Factory reset" feature

Post by mrsnail » Mon May 03, 2021 7:27 am

Thank you karfas

Yes, I have seen this and compile Micropython from scratch would be an option. But how do I reset it to this state? Or how can I delete i.e. the WiFi settings once it's set up? I can't seem to find using os.listdir() etc.

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: "Factory reset" feature

Post by karfas » Mon May 03, 2021 8:26 am

Then you should find out where your installation saves the WLAN credentials.
They might as well live in NVS storage (another "partition" in the EEPROM).
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

Post Reply