jenscski / DoubleResetDetect

Arduino library to check for double reset on ESP8266
MIT License
18 stars 5 forks source link

Overcoming power cuts #3

Open guysoft opened 4 years ago

guysoft commented 4 years ago

Hey, I have an issue that when there is a power cut in the building, my device detects a double reset. I am not sure if there is a way to overcome this - but was wondering if there might be some workaround (for example, making something detect the power cut and preform a shutdown, or perhaps assume that power cuts have a different timming than double-reset.

Sketch used is here: https://github.com/guysoft/Mqtt_Wifi_manager/blob/master/mqtt_wifi_manager_temp_sensor/mqtt_wifi_manager_temp_sensor.ino

Related: https://github.com/guysoft/Mqtt_Wifi_manager/issues/1

jenscski commented 4 years ago

I have not tested this (yet). But you could try testing for the boot reason, using int reason = ESP.getResetInfoPtr()->reason;

I think if reason is 6, the reset button is pushed, else some other values.

So maybe changing your code to if (drd.detect() && ESP.getResetInfoPtr()->reason == 6) will work

guysoft commented 4 years ago

Thanks, will try that and update.

jwill370 commented 3 years ago

For me ESP.getResetInfoPtr()->reason returns 6 for the reset button or cutting and restoring its power. Also ESP.getResetReason() returns "External System" for both. So this doesn't help distinguish which condition caused the reset.

ESP.restart() will result in Reset Code 4 when it reboots so maybe calling ESP.restart() with DoubleResetDetect could help decide on the next boot if a double reset was issued.

I'm using DoubleResetDetect for a ntp based clock application on a wemos d1 mini. Double reset will put it in AP mode if I would want to change the wifi settings. What I found is my clock will end up in AP mode after mains power loss but not because of DoubleResetDetect. My router took longer to reboot than the esp and wifi manager was giving up and entering AP mode until I added delay to account for this.