Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit da76548

Browse files
authored
v1.3.1 to add waitingForDRD()
### Releases v1.3.1 1. Add waitingForDRD() function to signal in DRD wating period. Check [DRD is waiting for a double reset? #14](#14) 2. Add example [checkWaitingDRD](https://github.com/khoih-prog/ESP_DoubleResetDetector/tree/master/examples/checkWaitingDRD) to demo how to use the new feature.
1 parent 101c1b5 commit da76548

File tree

2 files changed

+136
-4
lines changed

2 files changed

+136
-4
lines changed

examples/ConfigOnDoubleReset/ConfigOnDoubleReset.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ IPAddress APStaticSN = IPAddress(255, 255, 255, 0);
309309
#include <ESP_WiFiManager.h> //https://github.com/khoih-prog/ESP_WiFiManager
310310

311311
// Function Prototypes
312-
uint8_t connectMultiWiFi(void);
312+
uint8_t connectMultiWiFi();
313313

314314
///////////////////////////////////////////
315315
// New in v1.4.0
@@ -444,7 +444,7 @@ uint8_t connectMultiWiFi()
444444
return status;
445445
}
446446

447-
void heartBeatPrint(void)
447+
void heartBeatPrint()
448448
{
449449
static int num = 1;
450450

@@ -464,7 +464,7 @@ void heartBeatPrint(void)
464464
}
465465
}
466466

467-
void check_WiFi(void)
467+
void check_WiFi()
468468
{
469469
if ( (WiFi.status() != WL_CONNECTED) )
470470
{
@@ -473,7 +473,7 @@ void check_WiFi(void)
473473
}
474474
}
475475

476-
void check_status(void)
476+
void check_status()
477477
{
478478
static ulong checkstatus_timeout = 0;
479479
static ulong checkwifi_timeout = 0;
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/****************************************************************************************************************************
2+
checkWaitingDRD.ino
3+
For ESP8266 / ESP32 boards
4+
5+
ESP_DoubleResetDetector is a library for the ESP8266/Arduino platform
6+
to enable trigger configure mode by resetting ESP32 / ESP8266 twice.
7+
8+
Based on and modified from DataCute https://github.com/datacute/DoubleResetDetector
9+
10+
Built by Khoi Hoang https://github.com/khoih-prog/ESP_DoubleResetDetector
11+
Licensed under MIT license
12+
*****************************************************************************************************************************/
13+
14+
// These defines must be put before #include <ESP_DoubleResetDetector.h>
15+
// to select where to store DoubleResetDetector's variable.
16+
// For ESP32, You must select one to be true (EEPROM or SPIFFS)
17+
// For ESP8266, You must select one to be true (RTC, EEPROM, LITTLEFS or SPIFFS)
18+
// Otherwise, library will use default EEPROM storage
19+
20+
// This example demonstrate how to use new function waitingForDRD() to signal the stage of DRD
21+
// waitingForDRD() returns true if in DRD_TIMEOUT, false when out of DRD_TIMEOUT
22+
// In this example, LED_BUILTIN will blink in DRD_TIMEOUT period, ON when DR has been detected, OFF otherwise
23+
24+
#ifdef ESP8266
25+
#define ESP8266_DRD_USE_RTC false //true
26+
#endif
27+
28+
#define ESP_DRD_USE_LITTLEFS true
29+
#define ESP_DRD_USE_SPIFFS false
30+
#define ESP_DRD_USE_EEPROM false
31+
32+
// Uncomment to have debug
33+
//#define DOUBLERESETDETECTOR_DEBUG true
34+
35+
#include <ESP_DoubleResetDetector.h> //https://github.com/khoih-prog/ESP_DoubleResetDetector
36+
37+
// Number of seconds after reset during which a
38+
// subsequent reset will be considered a double reset.
39+
#define DRD_TIMEOUT 10
40+
41+
// RTC Memory Address for the DoubleResetDetector to use
42+
#define DRD_ADDRESS 0
43+
44+
DoubleResetDetector* drd;
45+
46+
#ifdef ESP32
47+
48+
// For ESP32
49+
#ifndef LED_BUILTIN
50+
#define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
51+
#endif
52+
53+
#define LED_OFF LOW
54+
#define LED_ON HIGH
55+
56+
#else
57+
58+
// For ESP8266
59+
#define LED_ON LOW
60+
#define LED_OFF HIGH
61+
62+
#endif
63+
64+
bool DRD_Detected = false;
65+
66+
void check_status()
67+
{
68+
static ulong checkstatus_timeout = 0;
69+
static bool LEDState = LED_OFF;
70+
71+
static ulong current_millis;
72+
73+
#define DRD_CHECK_INTERVAL 500L
74+
75+
current_millis = millis();
76+
77+
// If DRD_Detected, don't need to blink, just keep LED_BUILTIN ON
78+
if ( !DRD_Detected && ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) )
79+
{
80+
// If in DRD checking loop, blinking the LED_BUILTIN
81+
if ( drd->waitingForDRD() )
82+
{
83+
digitalWrite(LED_BUILTIN, LEDState);
84+
85+
LEDState = !LEDState;
86+
}
87+
else
88+
{
89+
digitalWrite(LED_BUILTIN, LED_OFF);
90+
}
91+
92+
checkstatus_timeout = current_millis + DRD_CHECK_INTERVAL;
93+
}
94+
}
95+
96+
void setup()
97+
{
98+
pinMode(LED_BUILTIN, OUTPUT);
99+
100+
Serial.begin(115200);
101+
while (!Serial);
102+
103+
delay(200);
104+
105+
Serial.print("\nStarting checkWaitingDRD on"); Serial.println(ARDUINO_BOARD);
106+
Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION);
107+
108+
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
109+
110+
if (drd->detectDoubleReset())
111+
{
112+
Serial.println("Double Reset Detected");
113+
digitalWrite(LED_BUILTIN, LED_ON);
114+
DRD_Detected = true;
115+
}
116+
else
117+
{
118+
Serial.println("No Double Reset Detected");
119+
digitalWrite(LED_BUILTIN, LED_OFF);
120+
}
121+
}
122+
123+
void loop()
124+
{
125+
// Call the double reset detector loop method every so often,
126+
// so that it can recognise when the timeout expires.
127+
// You can also call drd.stop() when you wish to no longer
128+
// consider the next reset as a double reset.
129+
drd->loop();
130+
131+
check_status();
132+
}

0 commit comments

Comments
 (0)