ESP_DoubleResetDetector
Releases v1.0.3
- Update to use the new LittleFS for ESP8266 core 2.7.1+
- Update minimal example
Releases v1.0.2
- Fix bug by left-over cpp file.
- Fix bug in example.
- Enhance README.md
This library is based on, modified, bug-fixed and improved from DataCute
to add support for ESP32.
Using this library to detect a double reset, using
- RTC Memory, EEPROM, LittleFS or SPIFFS for ESP8266
- EEPROM and SPIFFS for ESP32.
Prerequisite
Arduino IDE 1.8.12 or later
for ArduinoESP32 core 1.0.4 or later
for ESP32 (Use Arduino Board Manager)ESP8266 core 2.7.1 or later
for ES82662 (Use Arduino Board Manager) to use LittleFS or SPIFFS. SPIFFS is deprecated from ESP8266 core 2.7.1.
Quick Start
Installing use Arduino Library Manager
- The easiest way is to use
Arduino Library Manager
. Search forESP_DoubleResetDetector
, then select / install the latest version. - More detailed instructions at
Manual Install
- Navigate to ESP_DoubleResetDetector page.
- Download the latest release
ESP_DoubleResetDetector-master.zip
. - Extract the zip file to
ESP_DoubleResetDetector-master
directory - Copy whole
ESP_DoubleResetDetector-master
folder to Arduino libraries directory such as~/Arduino/libraries
.
Releases
Releases v1.0.3
- Update to use the new LittleFS for ESP8266 core 2.7.1+
- Update minimal example
Releases v1.0.2
- Fix bug by left-over cpp file.
- Fix bug in example.
- Enhance README.md
Releases v1.0.1
- Add EEPROM and SPIFFS support, besides RTC memory, for ESP8266
- Add SPIFFS support, besides EEPROM, for ESP32
PURPOSE:
Detects a double reset so that an alternative start-up mode can be used. One example use is to allow re-configuration of a device's wifi credentials.
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
// subseqent 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();
}
Also see examples:
TO DO
- Search for bug and improvement.
- Similar features for Arduino (UNO, Mega, etc...)
Contributions and thanks
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
Copyright
Copyright 2019- Khoi Hoang