emsesp / EMS-ESP

ESP8266 firmware to read and control EMS and Heatronic compatible equipment such as boilers, thermostats, solar modules, and heat pumps
https://emsesp.github.io/docs
GNU Lesser General Public License v3.0
302 stars 96 forks source link

reset function to revert to factory settings #708

Closed proddy closed 3 years ago

proddy commented 3 years ago

New feature for both v2 (ESP8266) and v3 (ESP32), holding a specific button doing for 5-10 seconds will erase the filesystem and force EMS-ESP to load the factory settings. This can be used in a panic situation when you can't get to the Serial or Web interface.

I'm looking at using the Reset button that comes standard on the ESP8266 and ESP32 dev boards and using either EEPROM/RTC of FS to store the state.

MichaelDvP commented 3 years ago

Some first thoughts to this:

proddy commented 3 years ago

It seems possible to detect the times between hard resets. I've been looking at this library https://github.com/khoih-prog/ESP_DoubleResetDetector. Also on the ESP32 been playing with the NVM (https://github.com/espressif/arduino-esp32/tree/master/libraries/Preferences) as an alternative to persisting in the FS.

Good point about only re-enabling the AP. There have been some people that change the admin password and can't get back in so would also be useful to reset the admin and su passwords.

bbqkees commented 3 years ago

I get questions about lost passwords etc. quite regularly. Now the only way to restore it is to reupload the firmware. Not an easy task if you never did something like that before and if you are not that good with computers. Just enabling the AP does not solve the problem if you can't remember the password, so a full factory reset is more useful. After a factory reset the Gateway is setup again pretty quickly anyway. A reset button connected to a GPIO would be a great feature that everybody understands. Press it on boot or f.i. for 10 seconds and then restore to factory mode so people can start over without having to dig into esptool etc. For boards that do not yet have a button you could use a piece of wire to connect the GPIO to ground. Detecting how long the boot button is pressed is also a good option if that is possible at all.

For the ESP32 serial fallback may indeed be there but a reset button is still the most friendly option. Also I'm working on some new board ideas and those may not all have an on-board USB connector anymore.

proddy commented 3 years ago

started working on this today. I created a new button library which is a bit over-engineered. You can assign any pin and it will detect button pushes from short, long, very long and a sequence. The idea is that a long press will reset the EMS-ESP to factory settings. We can use sequence and double-tap to fire off special commands. Probably not. But it was fun to program. I'll check it in shortly.

proddy commented 3 years ago

Committed first version of the button implementation. After consulting BBQKees it's a pull-up button (with a 10k resistor to 3.3v) so GPIO is HIGH when the switch is open and LOW (GND) when pushed. The pin is configurable, called External Button in the WebUI. On boot EMS-ESP will detect for an attached button.

Button does some tricks

MichaelDvP commented 3 years ago

Some remarks/questions to this function: Why not use the internal weak-pullups if the gpio have one also on esp32? Gpio 0 is not selectable (0 = off). On the NodeMCU-32s (that bbqkees uses in new design) there is the boot button on gpio 0 with internal pullup, see here Should be nice to use it. But then you should trigger the vLongButtonPress on button release to make sure the button is not pressed on reboot. The syslog should be started before button function to get the starting message (system.cpp, line 195..)

proddy commented 3 years ago

thanks Michael for the quick feedback

bbqkees commented 3 years ago

Just to clarify things:

There is a difference between a reboot and an reset button. The reboot button is connected to the EN/RST pin of the ESP chip. Pressing it will reboot the ESP.

The Reset button is linked to a GPIO pin, and it can have the function we give it.

proddy commented 3 years ago

right, I'll add the s/w pullup.

Also - should I port this to v2.x (ESP8266) too? The only advantage I see is for people using older gateways boards that are bricked and who are brave enough to unscrew the box and use a fiddly piece of bare wire on a pin for 10 seconds without breathing ;-)

bbqkees commented 3 years ago

As currently 95% of users will still be on the ESP8266 backporting would be nice.

MichaelDvP commented 3 years ago

Suggestion for the esp8266: D3 (gpio0) have an external pullup (10k), D2 (gpio4) is beside and both are also on J18 on the Gateway. Use gpio0 fixed for the PButton and set gpio4 to output-low, Then the user can shorten these pins with a small screwdriver or pincers and don't have to fiddle with bare wire. Also on8266 gpio0 is used for bootmode, it has to be high on esp-start. The PButton has to trigger the erase/reboot on button release: Remove PButton.cpp line 162 and insert in 146:

    if (state_ == pullMode_ && vLongPressHappened_) {
        resultEvent         = 4;
        vLongPressHappened_ = false;
        longPressHappened_  = false;
    }
proddy commented 3 years ago

I couldn't find J18 on my ESP8266 Gateway v1.6 but I love the idea! And happy if you want to go ahead and implement this if you have time. The tasks related to this were:

I'll work on the Web UI because I'm there anyway with #690 adding Board Profiles

MichaelDvP commented 3 years ago

J18 is only on Gateways <1.6, here, but the side-by-side pins can be accessed on the soldering on the wemos with a pen. I've tried this: IMG_20210302_171436_2 Result (i can confirm that your PButton works on 8266). IMG_20210302_171736_1

I'll merge in esp8266_dev later.

proddy commented 3 years ago

awesome! love quick hacks like this.

MichaelDvP commented 3 years ago

I see that there is PR#719. Can you please check/merge this first.

proddy commented 3 years ago

I see that there is PR#719. Can you please check/merge this first.

done.

bbqkees commented 3 years ago

Nice work. thanks.

proddy commented 3 years ago

Michael cleaned up my code and ported to ESP8266 (thanks!) so I think we can close this now. If anyone has any good ideas of what functions to put in the button let me know. Right now, double-click will just reset the wifi