GithubHelp home page GithubHelp logo

khoih-prog / esp_doubleresetdetector Goto Github PK

View Code? Open in Web Editor NEW
48.0 3.0 16.0 147 KB

ESP_DoubleResetDetector is a library for the ESP32/ESP8266 Arduino platform to enable trigger configure mode by resetting twice.

License: MIT License

C++ 98.23% Shell 1.77%
spiffs eeprom arduino-platform spiffs-support esp-doubleresetdetector rtc-memory configuration config-portal esp8266 esp32-arduino

esp_doubleresetdetector's Introduction

ESP_DoubleResetDetector Library

arduino-library-badge GitHub release GitHub contributions welcome GitHub issues

Donate to my libraries using BuyMeACoffee



Table of Contents



Features

ESP_DoubleResetDetector is a library for the ESP8266 and ESP32 boards to detects a double reset, within configurable timeout (default 10s) seconds, so that an alternative start-up mode can be used. Example use cases are to allow re-configuration of a device's WiFi / MQTT / Blynk credentials.

This library is based on, modified, bug-fixed and improved from Stephen Denne's DoubleResetDetector to add support to ESP8266 and ESP32 using EEPROM, SPIFFS or LittleFS besides original RTC.

Currently, DoubleResetDetector only supports ESP8266 using RTC memory.

This library can be used to detect a double reset within a predetermined time to force the program to enter a special operation such as Config Portal, Clear Default Data, etc., using :

  1. EEPROM, SPIFFS or LittleFS for ESP8266 and ESP32 boards.
  2. RTC memory for ESP8266 boards (unadvised).

Currently supported Boards

This ESP_DoubleResetDetector library currently supports these following boards:

  1. ESP32, ESP32_C3, ESP32_S2 and ESP32_S3 boards, using EEPROM, SPIFFS or LittleFS.
  2. ESP8266 boards RTC memory, EEPROM, SPIFFS or LittleFS


Prerequisites

  1. Arduino IDE 1.8.19+ for Arduino. GitHub release
  2. ESP32 Core 2.0.5+ for ESP32-based boards. Latest release
  3. ESP8266 Core 3.0.2+ for ESP8266-based boards. Latest release. SPIFFS is deprecated from ESP8266 core 2.7.1+, to use LittleFS.
  4. LittleFS_esp32 v1.0.6+ for ESP32-based boards using LittleFS with ESP32 core v1.0.5-. To install, check arduino-library-badge. Notice: This LittleFS_esp32 library has been integrated to Arduino ESP32 core v1.0.6+ and you don't need to install it if using ESP32 core v1.0.6+


Installation

Use Arduino Library Manager

The best and easiest way is to use Arduino Library Manager. Search for ESP_DoubleResetDetector, then select / install the latest version. You can also use this link arduino-library-badge for more detailed instructions.

Manual Install

  1. Navigate to ESP_DoubleResetDetector page.
  2. Download the latest release ESP_DoubleResetDetector-master.zip.
  3. Extract the zip file to ESP_DoubleResetDetector-master directory
  4. Copy the whole ESP_DoubleResetDetector-master folder to Arduino libraries' directory such as ~/Arduino/libraries/.

VS Code & PlatformIO:

  1. Install VS Code
  2. Install PlatformIO
  3. Install ESP_DoubleResetDetector library by using Library Manager. Search for ESP_DoubleResetDetector in Platform.io Author's Libraries
  4. Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File


HOWTO Usage

How to use

// These defines must be put before #include <ESP_DoubleResetDetector.h>
// to select where to store DoubleResetDetector's variable.
// For ESP32, You must select one to be true (EEPROM or SPIFFS)
// For ESP8266, You must select one to be true (RTC, EEPROM, LITTLEFS or SPIFFS)
// Otherwise, library will use default EEPROM storage


#ifdef ESP8266
#define ESP8266_DRD_USE_RTC     false   //true
#define ESP_DRD_USE_LITTLEFS    true    //false
#endif

#define ESP_DRD_USE_EEPROM      false
#define ESP_DRD_USE_SPIFFS      true

#define DOUBLERESETDETECTOR_DEBUG       true  //false

#include <ESP_DoubleResetDetector.h>      //https://github.com/khoih-prog/ESP_DoubleResetDetector

// Number of seconds after reset during which a 
// subsequent reset will be considered a double reset.
#define DRD_TIMEOUT 10

// RTC Memory Address for the DoubleResetDetector to use
#define DRD_ADDRESS 0

DoubleResetDetector* drd;

#ifdef ESP32

// For ESP32
#ifndef LED_BUILTIN
#define LED_BUILTIN       2         // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
#endif

#define LED_OFF     LOW
#define LED_ON      HIGH

#else

// For ESP8266
#define LED_ON      LOW
#define LED_OFF     HIGH

#endif

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  
  Serial.begin(115200);
  Serial.println("\nStarting minimal example for ESP_DoubleResetDetector");
  
  drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);

  if (drd->detectDoubleReset()) 
  {
    Serial.println("Double Reset Detected");
    digitalWrite(LED_BUILTIN, LED_ON);
  } 
  else 
  {
    Serial.println("No Double Reset Detected");
    digitalWrite(LED_BUILTIN, LED_OFF);
  }
}

void loop()
{
  // Call the double reset detector loop method every so often,
  // so that it can recognise when the timeout expires.
  // You can also call drd.stop() when you wish to no longer
  // consider the next reset as a double reset.
  drd->loop();
}


Examples

  1. ConfigOnDoubleReset
  2. ConfigOnDRD_ESP32_minimal
  3. ConfigOnDRD_ESP8266_minimal
  4. minimal

Examples from other libraries

and there are many more.

Many other libraries are depending on this library's DRD feature

All examples of these following libraries are using DRD feature of this ESP_DoubleResetDetector Library



// These defines must be put before #include <ESP_DoubleResetDetector.h>
// to select where to store DoubleResetDetector's variable.
// For ESP32, You must select one to be true (EEPROM or SPIFFS)
// For ESP8266, You must select one to be true (RTC, EEPROM, LITTLEFS or SPIFFS)
// Otherwise, library will use default EEPROM storage
// This example demonstrates how to use new function waitingForDRD() to signal the stage of DRD
// waitingForDRD() returns true if in DRD_TIMEOUT, false when out of DRD_TIMEOUT
// In this example, LED_BUILTIN will blink in DRD_TIMEOUT period, ON when DR has been detected, OFF otherwise
#ifdef ESP8266
#define ESP8266_DRD_USE_RTC false //true
#endif
#define ESP_DRD_USE_LITTLEFS true
#define ESP_DRD_USE_SPIFFS false
#define ESP_DRD_USE_EEPROM false
// Uncomment to have debug
//#define DOUBLERESETDETECTOR_DEBUG true
#include <ESP_DoubleResetDetector.h> //https://github.com/khoih-prog/ESP_DoubleResetDetector
// Number of seconds after reset during which a
// subsequent reset will be considered a double reset.
#define DRD_TIMEOUT 10
// RTC Memory Address for the DoubleResetDetector to use
#define DRD_ADDRESS 0
DoubleResetDetector* drd;
#ifdef ESP32
// For ESP32
#ifndef LED_BUILTIN
#define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
#endif
#define LED_OFF LOW
#define LED_ON HIGH
#else
// For ESP8266
#define LED_ON LOW
#define LED_OFF HIGH
#endif
bool DRD_Detected = false;
void check_status()
{
static ulong checkstatus_timeout = 0;
static bool LEDState = LED_OFF;
static ulong current_millis;
#define DRD_CHECK_INTERVAL 500L
current_millis = millis();
// If DRD_Detected, don't need to blink, just keep LED_BUILTIN ON
if ( !DRD_Detected && ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) )
{
// If in DRD checking loop, blinking the LED_BUILTIN
if ( drd->waitingForDRD() )
{
digitalWrite(LED_BUILTIN, LEDState);
LEDState = !LEDState;
}
else
{
digitalWrite(LED_BUILTIN, LED_OFF);
}
checkstatus_timeout = current_millis + DRD_CHECK_INTERVAL;
}
}
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
while (!Serial);
delay(200);
Serial.print("\nStarting checkWaitingDRD on");
Serial.println(ARDUINO_BOARD);
Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION);
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
if (drd->detectDoubleReset())
{
Serial.println("Double Reset Detected");
digitalWrite(LED_BUILTIN, LED_ON);
DRD_Detected = true;
}
else
{
Serial.println("No Double Reset Detected");
digitalWrite(LED_BUILTIN, LED_OFF);
}
}
void loop()
{
// Call the double reset detector loop method every so often,
// so that it can recognise when the timeout expires.
// You can also call drd.stop() when you wish to no longer
// consider the next reset as a double reset.
drd->loop();
check_status();
}



Debug Terminal Output Samples

1. ESP32_FSWebServer_DRD on ESP32_DEV

This is terminal debug output when running ESP32_FSWebServer_DRD on ESP32 ESP32_DEV.. Config Portal was requested by DRD to input and save Credentials. The boards then connected to WiFi AP HueNet1 using new Static IP successfully. WiFi AP HueNet1 is then lost, and board autoreconnects itself to backup WiFi AP HueNet2.

Starting ESP32_FSWebServer_DRD with DoubleResetDetect using SPIFFS on ESP32_DEV
ESP_WiFiManager v1.12.1
ESP_DoubleResetDetector v1.3.2
FS File: /ConfigSW.json, size: 150B
FS File: /CanadaFlag_1.png, size: 40.25KB
FS File: /CanadaFlag_2.png, size: 8.12KB
FS File: /CanadaFlag_3.jpg, size: 10.89KB
FS File: /edit.htm.gz, size: 4.02KB
FS File: /favicon.ico, size: 1.12KB
FS File: /graphs.js.gz, size: 1.92KB
FS File: /index.htm, size: 3.63KB
FS File: /drd.dat, size: 4B
FS File: /wifi_cred.dat, size: 192B

[WM] RFC925 Hostname = ESP32-FSWebServerDRD
[WM] setAPStaticIPConfig
[WM] setSTAStaticIPConfig for USE_CONFIGURABLE_DNS
[WM] Set CORS Header to :  Your Access-Control-Allow-Origin
Stored: SSID = HueNet2, Pass = 12345678
[WM] * Add SSID =  HueNet2 , PW =  12345678
Got stored Credentials. Timeout 120s for Config Portal
SPIFFS Flag read = 0xd0d04321
No doubleResetDetected
Saving config file...
Saving config file OK
[WM] LoadWiFiCfgFile 
[WM] OK
[WM] * Add SSID =  HueNet1 , PW =  12345678
[WM] * Add SSID =  HueNet2 , PW =  12345678
ConnectMultiWiFi in setup
[WM] ConnectMultiWiFi with :
[WM] * Flash-stored Router_SSID =  HueNet2 , Router_Pass =  12345678
[WM] * Additional SSID =  HueNet1 , PW =  12345678
[WM] * Additional SSID =  HueNet2 , PW =  12345678
[WM] Connecting MultiWifi...
[WM] WiFi connected after time:  1
[WM] SSID: HueNet1 ,RSSI= -27
[WM] Channel: 2 ,IP address: 192.168.2.232
After waiting 3.16 secs more in setup(), connection result is connected. Local IP: 192.168.2.232
HTTP server started @ 192.168.2.232
Open http://esp32-fs-browser.local/edit to see the file browser
[WM] freeing allocated params!
Stop doubleResetDetecting
Saving config file...
Saving config file OK

WiFi lost. Call connectMultiWiFi in loop
[WM] ConnectMultiWiFi with :
[WM] * Flash-stored Router_SSID =  HueNet2 , Router_Pass =  12345678
[WM] * Additional SSID =  HueNet1 , PW =  12345678
[WM] * Additional SSID =  HueNet2 , PW =  12345678
[WM] Connecting MultiWifi...
[WM] WiFi connected after time:  3
[WM] SSID: HueNet2 ,RSSI= -59
[WM] Channel: 4 ,IP address: 192.168.2.232
HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH

2. ConfigOnDoubleReset on ESP32_DEV

This is terminal debug output when running ConfigOnDoubleReset on ESP32 ESP32_DEV.. Config Portal was requested by DRD to input and save Credentials.

Starting ConfigOnDoubleReset with DoubleResetDetect using LittleFS on ESP32_DEV
ESP_WiFiManager v1.12.1
ESP_DoubleResetDetector v1.3.2
[WM] RFC925 Hostname = ConfigOnDoubleReset
[WM] Set CORS Header to :  Your Access-Control-Allow-Origin
Stored: SSID = HueNet1, Pass = 12345678
[WM] * Add SSID =  HueNet1 , PW =  87654321
Got stored Credentials. Timeout 120s for Config Portal
LittleFS Flag read = 0xd0d04321
No doubleResetDetected
Saving config file...
Saving config file OK
[WM] LoadWiFiCfgFile 
[WM] OK
[WM] * Add SSID =  HueNet1 , PW =  jenniqqs
[WM] * Add SSID =  HueNet2 , PW =  jenniqqs
ConnectMultiWiFi in setup
[WM] ConnectMultiWiFi with :
[WM] * Flash-stored Router_SSID =  HueNet1 , Router_Pass =  jenniqqs
[WM] * Additional SSID =  HueNet1 , PW =  12345678
[WM] * Additional SSID =  HueNet2 , PW =  87654321
[WM] Connecting MultiWifi...
[WM] WiFi connected after time:  1
[WM] SSID: HueNet1 ,RSSI= -32
[WM] Channel: 2 ,IP address: 192.168.2.101
After waiting 4.43 secs more in setup(), connection result is connected. Local IP: 192.168.2.101
[WM] freeing allocated params!
HStop doubleResetDetecting
Saving config file...
Saving config file OK
HHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8

Starting ConfigOnDoubleReset with DoubleResetDetect using LittleFS on ESP32_DEV
ESP_WiFiManager v1.12.1
ESP_DoubleResetDetector v1.3.2
[WM] RFC925 Hostname = ConfigOnDoubleReset
[WM] Set CORS Header to :  Your Access-Control-Allow-Origin
Stored: SSID = HueNet1, Pass = jenniqqs
[WM] * Add SSID =  HueNet1 , PW =  jenniqqs
Got stored Credentials. Timeout 120s for Config Portal
LittleFS Flag read = 0xd0d01234
doubleResetDetected
Saving config file...
Saving config file OK
Open Config Portal without Timeout: Double Reset Detected
Starting configuration portal.
[WM] WiFi.waitForConnectResult Done
[WM] SET AP
[WM] Configuring AP SSID = ESP_9ABF498
[WM] AP PWD = your_password
[WM] AP Channel = 3
[WM] AP IP address = 192.168.4.1
[WM] HTTP server started
[WM] ESP_WiFiManager::startConfigPortal : Enter loop

3. ESPAsync_WiFi using LittleFS on ESP32S3_DEV

This is terminal debug output when running ESPAsync_WiFi on ESP32 ESP32S3_DEV.. Config Portal was requested by DRD to input and save Credentials.

Starting ESPAsync_WiFi using LittleFS on ESP32S3_DEV
ESPAsync_WiFiManager_Lite v1.9.0
ESP_DoubleResetDetector v1.3.2
LittleFS Flag read = 0xD0D01234
doubleResetDetected
Saving config file...
Saving config file OK
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP32_S3
[WML] Hdr=ESP_WM_LITE,SSID=HueNet1,PW=12345678
[WML] SSID1=HueNet2,PW1=12345678
[WML] BName=ESP32_S3
[WML] WiFi networks found:
[WML] 1: HueNet, -20dB
[WML] 2: HueNetTek, -32dB
[WML] 3: HueNet1, -39dB
[WML] 4: HueNet2, -54dB
[WML] 5: DECO-5655, -72dB
[WML] 6: Guest5655, -72dB
[WML] 7: rogers786, -76dB
[WML] 8: AT_301_WLREL6325F_f66d, -76dB
[WML] 10: Rogers 786, -78dB
[WML] 11: BELL042, -80dB
[WML] 12: WirelessMississauga, -82dB
[WML] 13: SmartRG-02a2, -87dB
[WML] 14: Jasmine, -87dB
[WML] 15: Access, -89dB
[WML] 16: Jessie, -90dB
[WML] 
stConf:SSID=ESP_E1A1DF7C,PW=MyESP_E1A1DF7C
[WML] IP=192.168.4.1,ch=10
F
Your stored Credentials :
Blynk Server1 = account.duckdns.org
Token1 = token1
Blynk Server2 = account.ddns.net
Token2 = token2
Port = 8080
MQTT Server = mqtt.duckdns.org

Libraries using ESP_DoubleResetDetector or DoubleResetDetector_Generic library

You can also see how ESP_DoubleResetDetector and DoubleResetDetector_Generic are applied in many other libraries, such as:

  1. Blynk_WM
  2. BlynkEthernet_WM
  3. WiFiManager_NINA_Lite
  4. BlynkESP32_BT_WF,
  5. Blynk_GSM_Manager,
  6. Blynk_Esp8266AT_WM,
  7. Blynk_WiFiNINA_WM,
  8. Blynk_Async_WM,
  9. Blynk_Async_ESP32_BT_WF,
  10. Blynk_Async_GSM_Manager,
  11. ESP_WiFiManager
  12. ESPAsync_WiFiManager
  13. WiFiManager_NINA_Lite
  14. BlynkEthernet_STM32_WM,
  15. ESP_AT_WM_Lite
  16. WIOTerminal_WiFiManager
  17. Ethernet_Manager
  18. Ethernet_Manager_STM32

and the list is growing fast.



Debug

Debug is disabled by default. To enable debug:

// Use this to output debug msgs to Serial
#define DOUBLERESETDETECTOR_DEBUG       true

Troubleshooting

If you get compilation errors, more often than not, you may need to install a newer version of the ESP32 / ESP8266 core for Arduino.

Sometimes, the library will only work if you update the ESP32 / ESP8266 core to the latest version because I am using some newly added function.



Issues

Submit issues to: ESP_DoubleResetDetector issues



TO DO

  1. Search for bug and improvement.

DONE

  1. For ESP32 and ESP8266 (EEPROM, SPIFFS and LittleFS).
  2. Similar features for Arduino (UNO, Mega, SAM DUE, SAMD21/SAMD51, nRF52, STM32, Teensy, etc.). Look at DoubleResetDetector_Generic
  3. Add support to ESP32_C3, ESP32_S2
  4. Add support to ESP32_S3 using ESP32 core v2.0.2+
  5. Add waitingForDRD() function to signal in DRD waiting period
  6. Fix ESP32 chipID for exampleConfigOnDoubleReset
  7. Remove dependency on LittleFS_esp32 library to prevent PIO error when using new ESP32 core v1.0.6+
  8. Add astyle using allman style. Restyle the library


Contributions and thanks

  1. Thanks to zobix for report the bug in Issue 2
  2. Thanks to Tochi Moreno for enhancement request in DRD is waiting for a double reset? #14 leading to v1.3.1 to add waitingForDRD() function to signal in DRD waiting period
zobix
Zobix

tochimoreno
Tochi Moreno


Contributing

If you want to contribute to this project:

  • Report bugs and errors
  • Ask for enhancements
  • Create issues and pull requests
  • Tell other people about this library

License

  • The library is licensed under MIT

Copyright

Copyright (c) 2019- Khoi Hoang

esp_doubleresetdetector's People

Contributors

khoih-prog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

esp_doubleresetdetector's Issues

Sign compare warning

ESP_DoubleResetDetector 1.1.0
PlatformIO version 5.0.3
Espressif 8266 2.6.2

In file included from include/reset.h:16:0,
                 from src/reset.cpp:1:
.pio/libdeps/d1_mini/ESP_DoubleResetDetector/src/ESP_DoubleResetDetector.h: In member function 'void DoubleResetDetector::loop()':
.pio/libdeps/d1_mini/ESP_DoubleResetDetector/src/ESP_DoubleResetDetector.h:184:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       if (waitingForDoubleReset && millis() > timeout)
                                               ^

Changing the private int timeout in ESP_DoubleResetDetector.h to e.g. an uint solves the warning.

Double reset detected when powering up

This is more a question than a clear bug report.

Im using Lolin wemos d1 mini pro. I upload the example sketch minimum for esp8266. It works nicely otherwise but when I disconnect power supply and then reconnect it, double reset is detected. Im wondering can this be avoided somehow or why does this happen. I wouldn't want eg my wifi credentials to be erased if there is power outage. Any idea?

'LittleFS' was not declared in this scope

ESP_DoubleResetDetector.h

#define FileFS        LittleFS
Error: 'LittleFS' was not declared in this scope C/C++(20)...
Espressif 32 framework v.4.0.0 / 4.4.0 / 5.0.0 / 5.1.1

library.json has a missing comma

last lines of library.json should be:

...
"frameworks": "arduino",
"platforms": "espressif",
"examples": "examples/*/*/*.ino"
}

with a comma after "expressif"

Minimal example Not working on ESP32

Minimal from examples does nothing on ESP32

Using the sketch from Readme works
Not sure whats different, but might have to add that as Example (:

With minimal, these lines arent present in debug

Saving config file...
Saving config file OK

Strange Incompatibility when DRD is in a xTask

Hi, to start thanks for your good good lib.

I need to delegate the DRD in a task to completly separate from loop(),
I tried with a xTask but when DEBUG is enabled, the board crash:

Connecting.......Stop doubleResetDetecting
Guru Meditation Error: Core  0 panic'ed (Unhandled debug exception)
Debug exception reason: Stack canary watchpoint triggered (DbleRstCheckr) 
Core 0 register dump:
PC      : 0x400893b3  PS      : 0x00060e36  A0      : 0x80089558  A1      : 0x3ffb2080  
A2      : 0x3ffbac0c  A3      : 0x00000000  A4      : 0xffffffff  A5      : 0x00000000  
A6      : 0x000000ff  A7      : 0x3ffb22bc  A8      : 0x8008a565  A9      : 0x3ffb2090  
A10     : 0x00000003  A11     : 0x00060e23  A12     : 0x00060e20  A13     : 0x0000007e  
A14     : 0x00000002  A15     : 0x3ffb22bc  SAR     : 0x00000010  EXCCAUSE: 0x00000001  
EXCVADDR: 0x00000000  LBEG    : 0x40001609  LEND    : 0x4000160d  LCOUNT  : 0x00000000  

Backtrace: 0x400893b3:0x3ffb2080 0x40089555:0x3ffb20c0 0x4014c9e1:0x3ffb20e0 0x40087622:0x3ffb2100 0x40087bea:0x3ffb2120 0x400ffffd:0x3ffb2190 0x400fe8c5:0x3ffb21b0 0x400fed13:0x3ffb21d0 0x400fd659:0x3ffb2240 0x400fdc3d:0x3ffb2290 0x400fd0e9:0x3ffb2300 0x400e63d6:0x3ffb2340 0x400d29c3:0x3ffb2360 0x400d2a94:0x3ffb23a0 0x400896e5:0x3ffb23c0

If you want to keep debug mode enabled: Just add more space for it with 1500 byte of stack size to the default stack size of a new task.
here is my code if you want to publish an example:

Define:

//------------------------------------------------------------Double Reset Detector
#define ESP_DRD_USE_EEPROM      true
#define DOUBLERESETDETECTOR_DEBUG       true  //false
#include <ESP_DoubleResetDetector.h>      //https://github.com/khoih-prog/ESP_DoubleResetDetector

// Number of seconds after reset during which a 
// subseqent reset will be considered a double reset.
#define DRD_TIMEOUT 5

// RTC Memory Address for the DoubleResetDetector to use
#define DRD_ADDRESS 0

DoubleResetDetector* drd;

// For ESP32 LED Builtin
#ifndef LED_BUILTIN
#define LED_BUILTIN       2         // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
#endif

#define LED_OFF     LOW
#define LED_ON      HIGH
//------------------------------------------------------------Double Reset Detector

Func to declare before setup:

void DoubleResetCheck(void * parameter){
  for(;;){ // infinite loop

drd->loop(); // Double Reset Detector

    // Pause the task for 5ms
    vTaskDelay(5 / portTICK_PERIOD_MS);
  }
}

In Setup():

//------------------------------------------------------------Double Reset Detector
  drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
  if (drd->detectDoubleReset()) 
  {
    Serial.println("");Serial.println("Double Reset Detected");Serial.println("");
    digitalWrite(LED_BUILTIN, LED_ON);
  } 
  else 
  {
    Serial.println("");Serial.println("No Double Reset Detected");Serial.println("");
    digitalWrite(LED_BUILTIN, LED_OFF);
  }

    xTaskCreate(DoubleResetCheck,    // Function that should be called
    "DbleRstCheckr",   // Name of the task (for debugging)
    1500,            // Stack size (bytes)
    NULL,            // Parameter to pass
    1,               // Task priority
    NULL             // Task handle
  );
//------------------------------------------------------------Double Reset Detector

Feature Request: Ability to clear timeout with a call, instead of time

In my application, there is a process indicated on the LCD.

I want to allow something along the lines of "You can press reset twice, while the logo is on screen, to enter the ... mode"
That logo is displayed for a variable amount of time - so would like to be able to do something like

setup() {
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
if (drd->detectDoubleReset()) {
enterConfigMode()
}
doOneThing()
doAnotherThing()
doThirdThing()
drd->clearFlag(); // if you press reset after this, it resets, doesnt count as a doublereset anymore
}

ie instead of the loop counting down the timeout and clearing it when time is over

Error compilation for ESP32

Hello!

I get an Error compilation for ESP32. Arduino IDE 1.8.12, ESP32 core 1.0.4. Many redifinitions errors. How to fix it?

Log of compilator:

In file included from C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:19:0:

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.h:35:2: warning: #warning Neither EEPROM nor SPIFFS selected. Default to EEPROM [-Wcpp]

#warning Neither EEPROM nor SPIFFS selected. Default to EEPROM

^

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:44:1: error: redefinition of 'DoubleResetDetector::DoubleResetDetector(int, int)'

DoubleResetDetector::DoubleResetDetector(int timeout, int address)

^

In file included from C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:19:0:

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.h:88:5: note: 'DoubleResetDetector::DoubleResetDetector(int, int)' previously defined here

 DoubleResetDetector(int timeout, int address)

 ^

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:60:6: error: redefinition of 'bool DoubleResetDetector::detectDoubleReset()'

bool DoubleResetDetector::detectDoubleReset()

  ^

In file included from C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:19:0:

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.h:116:10: note: 'bool DoubleResetDetector::detectDoubleReset()' previously defined here

 bool detectDoubleReset()

      ^

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:84:6: error: redefinition of 'void DoubleResetDetector::loop()'

void DoubleResetDetector::loop()

  ^

In file included from C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:19:0:

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.h:142:10: note: 'void DoubleResetDetector::loop()' previously defined here

 void loop()

      ^

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:96:6: error: redefinition of 'void DoubleResetDetector::stop()'

void DoubleResetDetector::stop()

  ^

In file included from C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:19:0:

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.h:154:10: note: 'void DoubleResetDetector::stop()' previously defined here

 void stop()

      ^

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:102:6: error: redefinition of 'bool DoubleResetDetector::detectRecentlyResetFlag()'

bool DoubleResetDetector::detectRecentlyResetFlag()

  ^

In file included from C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:19:0:

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.h:169:10: note: 'bool DoubleResetDetector::detectRecentlyResetFlag()' previously defined here

 bool detectRecentlyResetFlag()

      ^

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:121:6: error: redefinition of 'void DoubleResetDetector::setRecentlyResetFlag()'

void DoubleResetDetector::setRecentlyResetFlag() {

  ^

In file included from C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:19:0:

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.h:212:10: note: 'void DoubleResetDetector::setRecentlyResetFlag()' previously defined here

 void setRecentlyResetFlag()

      ^

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:139:6: error: redefinition of 'void DoubleResetDetector::clearRecentlyResetFlag()'

void DoubleResetDetector::clearRecentlyResetFlag() {

  ^

In file included from C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:19:0:

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.h:257:10: note: 'void DoubleResetDetector::clearRecentlyResetFlag()' previously defined here

 void clearRecentlyResetFlag()

      ^

C:\Users\User\Documents\Arduino\libraries\ESP_DoubleResetDetector-master\src\ESP_DoubleResetDetector.cpp:23:17: warning: 'DOUBLERESETDETECTOR_FLAG' defined but not used [-Wunused-variable]

static uint32_t DOUBLERESETDETECTOR_FLAG;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.