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

Commit 772c0e1

Browse files
authored
v.1.0.2
### Releases v1.0.2 1. Fix bug by left-over cpp file. 2. Fix bug in example. 3. Enhance README.md
1 parent 153ad61 commit 772c0e1

File tree

6 files changed

+163
-107
lines changed

6 files changed

+163
-107
lines changed

README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,48 @@
22

33
[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com/ESP_DoubleResetDetector)
44

5+
### Releases v1.0.2
6+
7+
1. Fix bug by left-over cpp file.
8+
2. Fix bug in example.
9+
3. Enhance README.md
10+
511
This library is based on, modified, bug-fixed and improved from [`DataCute`](https://github.com/datacute/DoubleResetDetector) to add support for ESP32.
612

713
Using this library to detect a double reset, using
814

915
1. RTC Memory, EEPROM or SPIFFS for ESP8266
1016
2. EEPROM and SPIFFS for ESP32.
1117

12-
It is tested and working with
13-
1. [`ESP8266 Core 2.6.2 or newer`](https://github.com/esp8266/Arduino)
14-
2. [`ESP32 Core 1.0.4 or newer`](https://github.com/espressif/arduino-esp32)
18+
## Prerequisite
19+
1. [`Arduino IDE 1.8.12 or later` for Arduino](https://www.arduino.cc/en/Main/Software)
20+
2. [`ESP32 core 1.0.4 or later`](https://github.com/espressif/arduino-esp32/releases) for ESP32 (Use Arduino Board Manager)
21+
3. [`ESP8266 core 2.6.3 or later`](https://github.com/esp8266/Arduino/releases) for ES82662 (Use Arduino Board Manager)
1522

1623
### Quick Start
1724

18-
#### Use Arduino Library Manager
25+
#### Installing use Arduino Library Manager
1926

20-
The easiest way is to use `Arduino Library Manager`. Search for `ESP_DoubleResetDetector`, then select / install the latest version.
27+
1. The easiest way is to use `Arduino Library Manager`. Search for `ESP_DoubleResetDetector`, then select / install the latest version.
28+
2. More detailed instructions at [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com/ESP_DoubleResetDetector)
2129

2230
#### Manual Install
2331

24-
The suggested way to install manually is to:
25-
2632
1. Navigate to [ESP_DoubleResetDetector](https://github.com/khoih-prog/ESP_DoubleResetDetector) page.
2733
2. Download the latest release `ESP_DoubleResetDetector-master.zip`.
2834
3. Extract the zip file to `ESP_DoubleResetDetector-master` directory
29-
4. Copy whole `ESP_DoubleResetDetector-master` folder to Arduino libraries' directory such as `~/Arduino/libraries`.
35+
4. Copy whole
36+
- `ESP_DoubleResetDetector-master` folder to Arduino libraries directory such as `~/Arduino/libraries`.
3037

3138
### Releases
32-
#### New in v1.0.1
39+
40+
#### Releases v1.0.2
41+
42+
1. Fix bug by left-over cpp file.
43+
2. Fix bug in example.
44+
3. Enhance README.md
45+
46+
#### Releases v1.0.1
3347

3448
1. Add EEPROM and SPIFFS support, besides RTC memory, for ESP8266
3549
2. Add SPIFFS support, besides EEPROM, for ESP32
@@ -98,19 +112,26 @@ void loop()
98112
drd->loop();
99113
}
100114
```
115+
116+
Also see examples:
117+
1. [ConfigOnDoubleReset](examples/ConfigOnDoubleReset)
118+
2. [minimal](examples/minimal)
119+
101120
### TO DO
102121

103122
1. Search for bug and improvement.
104123
2. Similar features for Arduino (UNO, Mega, etc...)
105124

106-
### Contributing
125+
### Contributions and thanks
107126

127+
1. Thanks to [zobix](https://github.com/zobix) for report the bug in [Isssue 2](https://github.com/khoih-prog/ESP_DoubleResetDetector/issues/2)
128+
129+
### Contributing
108130
If you want to contribute to this project:
109131
- Report bugs and errors
110132
- Ask for enhancements
111133
- Create issues and pull requests
112134
- Tell other people about this library
113135

114136
### Copyright
115-
116137
Copyright 2019- Khoi Hoang
Lines changed: 88 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,68 @@
11
/****************************************************************************************************************************
2-
* ConfigOnDoubleReset.ino
3-
* For ESP8266 / ESP32 boards
4-
*
5-
* ESP_WiFiManager is a library for the ESP8266/ESP32 platform (https://github.com/esp8266/Arduino) to enable easy
6-
* configuration and reconfiguration of WiFi credentials using a Captive Portal. Inspired by:
7-
* http://www.esp8266.com/viewtopic.php?f=29&t=2520
8-
* https://github.com/chriscook8/esp-arduino-apboot
9-
* https://github.com/esp8266/Arduino/blob/master/libraries/DNSServer/examples/CaptivePortalAdvanced/
10-
*
11-
* Forked from Tzapu https://github.com/tzapu/WiFiManager
12-
* and from Ken Taylor https://github.com/kentaylor
13-
*
14-
* Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager
15-
* Licensed under MIT license
16-
* Version: 1.0.1
17-
*
18-
* Version Modified By Date Comments
19-
* ------- ----------- ---------- -----------
20-
* 1.0.0 K Hoang 07/10/2019 Initial coding
21-
* 1.0.1 K Hoang 13/12/2019 Fix bug. Add features. Add support for ESP32
2+
ConfigOnDoubleReset.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+
Forked 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+
Version: 1.0.2
13+
14+
Version Modified By Date Comments
15+
------- ----------- ---------- -----------
16+
1.0.0 K Hoang 15/12/2019 Initial coding
17+
1.0.1 K Hoang 30/12/2019 Now can use EEPROM or SPIFFS for both ESP8266 and ESP32. RTC still OK for ESP8266
18+
1.0.2 K Hoang 10/04/2020 Fix bug by left-over cpp file and in example.
2219
*****************************************************************************************************************************/
2320
/****************************************************************************************************************************
24-
* This example will open a configuration portal when the reset button is pressed twice.
25-
* This method works well on Wemos boards which have a single reset button on board. It avoids using a pin for launching the configuration portal.
26-
*
27-
* How It Works
28-
* 1) ESP8266
29-
* Save data in RTC memory, EPPROM or SPIFFS
30-
* 2) ESP32
31-
* Save data in
32-
* a) EEPROM from address 256, size 512 bytes (both configurable)
33-
* b) SPIFFS, file name "/drd.dat"
34-
*
35-
* So when the device starts up it checks this region of ram for a flag to see if it has been recently reset.
36-
* If so it launches a configuration portal, if not it sets the reset flag. After running for a while this flag is cleared so that
37-
* it will only launch the configuration portal in response to closely spaced resets.
38-
*
39-
* Settings
40-
* There are two values to be set in the sketch.
41-
*
42-
* DRD_TIMEOUT - Number of seconds to wait for the second reset. Set to 10 in the example.
43-
* DRD_ADDRESS - The address in ESP8266 RTC RAM to store the flag. This memory must not be used for other purposes in the same sketch. Set to 0 in the example.
44-
*
45-
* This example, originally relied on the Double Reset Detector library from https://github.com/datacute/DoubleResetDetector
46-
* To support ESP32, use ESP_DoubleResetDetector library from //https://github.com/khoih-prog/ESP_DoubleResetDetector
21+
This example will open a configuration portal when the reset button is pressed twice.
22+
This method works well on Wemos boards which have a single reset button on board. It avoids using a pin for launching the configuration portal.
23+
24+
How It Works
25+
1) ESP8266
26+
Save data in RTC memory, EPPROM or SPIFFS
27+
2) ESP32
28+
Save data in
29+
a) EEPROM from address 256, size 512 bytes (both configurable)
30+
b) SPIFFS, file name "/drd.dat"
31+
32+
So when the device starts up it checks this region of ram for a flag to see if it has been recently reset.
33+
If so it launches a configuration portal, if not it sets the reset flag. After running for a while this flag is cleared so that
34+
it will only launch the configuration portal in response to closely spaced resets.
35+
36+
Settings
37+
There are two values to be set in the sketch.
38+
39+
DRD_TIMEOUT - Number of seconds to wait for the second reset. Set to 10 in the example.
40+
DRD_ADDRESS - The address in ESP8266 RTC RAM to store the flag. This memory must not be used for other purposes in the same sketch. Set to 0 in the example.
41+
42+
This example, originally relied on the Double Reset Detector library from https://github.com/datacute/DoubleResetDetector
43+
To support ESP32, use ESP_DoubleResetDetector library from //https://github.com/khoih-prog/ESP_DoubleResetDetector
4744
*****************************************************************************************************************************/
4845

4946
//Ported to ESP32
5047
#ifdef ESP32
51-
#include <esp_wifi.h>
52-
#include <WiFi.h>
53-
#include <WiFiClient.h>
48+
#include <esp_wifi.h>
49+
#include <WiFi.h>
50+
#include <WiFiClient.h>
5451

55-
#define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())
52+
#define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())
5653

57-
#define LED_ON HIGH
58-
#define LED_OFF LOW
54+
#define LED_ON HIGH
55+
#define LED_OFF LOW
5956
#else
60-
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
61-
//needed for library
62-
#include <DNSServer.h>
63-
#include <ESP8266WebServer.h>
57+
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
58+
//needed for library
59+
#include <DNSServer.h>
60+
#include <ESP8266WebServer.h>
6461

65-
#define ESP_getChipId() (ESP.getChipId())
62+
#define ESP_getChipId() (ESP.getChipId())
6663

67-
#define LED_ON LOW
68-
#define LED_OFF HIGH
64+
#define LED_ON LOW
65+
#define LED_OFF HIGH
6966
#endif
7067

7168
// SSID and PW for Config Portal
@@ -87,14 +84,14 @@ String Router_Pass;
8784
#define ESP_DRD_USE_SPIFFS true //false
8885

8986
#ifdef ESP8266
90-
#define ESP8266_DRD_USE_RTC false //true
87+
#define ESP8266_DRD_USE_RTC false //true
9188
#endif
9289

9390
#define DOUBLERESETDETECTOR_DEBUG true //false
9491

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

97-
// Number of seconds after reset during which a
94+
// Number of seconds after reset during which a
9895
// subseqent reset will be considered a double reset.
9996
#define DRD_TIMEOUT 10
10097

@@ -118,23 +115,23 @@ void heartBeatPrint(void)
118115
Serial.print("H"); // H means connected to WiFi
119116
else
120117
Serial.print("F"); // F means not connected to WiFi
121-
122-
if (num == 80)
118+
119+
if (num == 80)
123120
{
124121
Serial.println();
125122
num = 1;
126123
}
127-
else if (num++ % 10 == 0)
124+
else if (num++ % 10 == 0)
128125
{
129126
Serial.print(" ");
130127
}
131-
}
128+
}
132129

133130
void check_status()
134131
{
135132
static ulong checkstatus_timeout = 0;
136133

137-
#define HEARTBEAT_INTERVAL 10000L
134+
#define HEARTBEAT_INTERVAL 10000L
138135
// Print hearbeat every HEARTBEAT_INTERVAL (10) seconds.
139136
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
140137
{
@@ -143,7 +140,7 @@ void check_status()
143140
}
144141
}
145142

146-
void setup()
143+
void setup()
147144
{
148145
// put your setup code here, to run once:
149146
// initialize the LED digital pin as an output.
@@ -153,21 +150,21 @@ void setup()
153150

154151
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
155152

156-
//Local intialization. Once its business is done, there is no need to keep it around
153+
//Local intialization. Once its business is done, there is no need to keep it around
157154
ESP_WiFiManager ESP_wifiManager;
158155

159-
// We can't use WiFi.SSID() in ESP32 as it's only valid after connected.
156+
// We can't use WiFi.SSID() in ESP32 as it's only valid after connected.
160157
// SSID and Password stored in ESP32 wifi_ap_record_t and wifi_config_t are also cleared in reboot
161158
// Have to create a new function to store in EEPROM/SPIFFS for this purpose
162159
Router_SSID = ESP_wifiManager.WiFi_SSID();
163160
Router_Pass = ESP_wifiManager.WiFi_Pass();
164-
161+
165162
//Remove this line if you do not want to see WiFi password printed
166163
Serial.println("Stored: SSID = " + Router_SSID + ", Pass = " + Router_Pass);
167164

168-
// SSID to uppercase
165+
// SSID to uppercase
169166
ssid.toUpperCase();
170-
167+
171168
if (Router_SSID != "")
172169
{
173170
ESP_wifiManager.setConfigPortalTimeout(60); //If no access point name has been previously entered disable timeout.
@@ -178,14 +175,14 @@ void setup()
178175
Serial.println("No stored Credentials. No timeout");
179176
initialConfig = true;
180177
}
181-
182-
if (drd->detectDoubleReset())
178+
179+
if (drd->detectDoubleReset())
183180
{
184181
Serial.println("Double Reset Detected");
185182
initialConfig = true;
186183
}
187-
188-
if (initialConfig)
184+
185+
if (initialConfig)
189186
{
190187
Serial.println("Starting configuration portal.");
191188
digitalWrite(PIN_LED, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode.
@@ -195,42 +192,42 @@ void setup()
195192
//switched off via webserver or device is restarted.
196193
//ESP_wifiManager.setConfigPortalTimeout(600);
197194

198-
//it starts an access point
195+
//it starts an access point
199196
//and goes into a blocking loop awaiting configuration
200-
if (!ESP_wifiManager.startConfigPortal((const char *) ssid.c_str(), password))
197+
if (!ESP_wifiManager.startConfigPortal((const char *) ssid.c_str(), password))
201198
Serial.println("Not connected to WiFi but continuing anyway.");
202-
else
203-
Serial.println("WiFi connected...yeey :)");
199+
else
200+
Serial.println("WiFi connected...yeey :)");
204201
}
205202

206203
digitalWrite(PIN_LED, LED_OFF); // Turn led off as we are not in configuration mode.
207-
208-
#define WIFI_CONNECT_TIMEOUT 30000L
209-
#define WHILE_LOOP_DELAY 200L
210-
#define WHILE_LOOP_STEPS (WIFI_CONNECT_TIMEOUT / ( 3 * WHILE_LOOP_DELAY ))
211-
204+
205+
#define WIFI_CONNECT_TIMEOUT 30000L
206+
#define WHILE_LOOP_DELAY 200L
207+
#define WHILE_LOOP_STEPS (WIFI_CONNECT_TIMEOUT / ( 3 * WHILE_LOOP_DELAY ))
208+
212209
unsigned long startedAt = millis();
213-
210+
214211
while ( (WiFi.status() != WL_CONNECTED) && (millis() - startedAt < WIFI_CONNECT_TIMEOUT ) )
215-
{
212+
{
216213
WiFi.mode(WIFI_STA);
217214
WiFi.persistent (true);
218215
// We start by connecting to a WiFi network
219-
216+
220217
Serial.print("Connecting to ");
221218
Serial.println(Router_SSID);
222-
219+
223220
WiFi.begin(Router_SSID.c_str(), Router_Pass.c_str());
224221

225222
int i = 0;
226-
while((!WiFi.status() || WiFi.status() >= WL_DISCONNECTED) && i++ < WHILE_LOOP_STEPS)
223+
while ((!WiFi.status() || WiFi.status() >= WL_DISCONNECTED) && i++ < WHILE_LOOP_STEPS)
227224
{
228225
delay(WHILE_LOOP_DELAY);
229-
}
226+
}
230227
}
231228

232229
Serial.print("After waiting ");
233-
Serial.print((millis()- startedAt) / 1000);
230+
Serial.print((millis() - startedAt) / 1000);
234231
Serial.print(" secs more in setup(), connection result is ");
235232

236233
if (WiFi.status() == WL_CONNECTED)
@@ -242,7 +239,7 @@ void setup()
242239
Serial.println(ESP_wifiManager.getStatus(WiFi.status()));
243240
}
244241

245-
void loop()
242+
void loop()
246243
{
247244
// Call the double reset detector loop method every so often,
248245
// so that it can recognise when the timeout expires.
@@ -252,5 +249,5 @@ void loop()
252249

253250
// put your main code here, to run repeatedly
254251
check_status();
255-
252+
256253
}

0 commit comments

Comments
 (0)