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

Commit

Permalink
Update README.md and use allman astyle
Browse files Browse the repository at this point in the history
  • Loading branch information
khoih-prog authored Nov 25, 2022
1 parent e0ab895 commit d990bbb
Show file tree
Hide file tree
Showing 12 changed files with 430 additions and 211 deletions.
23 changes: 21 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,44 @@ Please ensure to specify the following:
Arduino IDE version: 1.8.19
ESP8266 Core Version 3.0.2
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a non-response while trying to press the reset button twice.
I encountered a crash while using this library
Steps to reproduce:
1. ...
2. ...
3. ...
4. ...
```

---

### Sending Feature Requests

Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.

There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/ESP_DoubleResetDetector/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.

---

### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!

Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)

1. Change directory to the library GitHub

```
xy@xy-Inspiron-3593:~$ cd Arduino/xy/ESP_DoubleResetDetector_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/ESP_DoubleResetDetector_GitHub$
```

2. Issue astyle command

```
xy@xy-Inspiron-3593:~/Arduino/xy/ESP_DoubleResetDetector_GitHub$ bash utils/restyle.sh
```

31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
## ESP_DoubleResetDetector
## ESP_DoubleResetDetector Library

[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com/ESP_DoubleResetDetector)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/ESP_DoubleResetDetector.svg)](https://github.com/khoih-prog/ESP_DoubleResetDetector/releases)
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/ESP_DoubleResetDetector/blob/master/LICENSE)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ESP_DoubleResetDetector.svg)](http://github.com/khoih-prog/ESP_DoubleResetDetector/issues)


<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
<a href="https://profile-counter.glitch.me/khoih-prog-ESP_DoubleResetDetector/count.svg" title="ESP_DoubleResetDetector Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-ESP_DoubleResetDetector/count.svg" style="height: 30px;width: 200px;"></a>

---
---
Expand Down Expand Up @@ -81,16 +84,16 @@

#### Features

[**ESP_DoubleResetDetector**](https://github.com/khoih-prog/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.
[**ESP_DoubleResetDetector**](https://github.com/khoih-prog/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`](https://github.com/datacute/DoubleResetDetector) to add support to ESP8266 and ESP32 using EEPROM, SPIFFS and LittleFS besides original RTC.
This library is based on, modified, bug-fixed and improved from [`Stephen Denne's DoubleResetDetector`](https://github.com/datacute/DoubleResetDetector) to add support to ESP8266 and ESP32 using `EEPROM`, `SPIFFS` or `LittleFS` besides original `RTC`.

Currently, [`DoubleResetDetector`](https://github.com/datacute/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 :
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).
1. `EEPROM`, `SPIFFS` or `LittleFS` for ESP8266 and ESP32 boards.
2. `RTC` memory for ESP8266 boards (unadvised).

#### Currently supported Boards

Expand All @@ -105,7 +108,7 @@ This [**ESP_DoubleResetDetector** library](https://github.com/khoih-prog/ESP_Dou
## Prerequisites

1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest)
2. [`ESP32 Core 2.0.4+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/)
2. [`ESP32 Core 2.0.5+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/)
3. [`ESP8266 Core 3.0.2+`](https://github.com/esp8266/Arduino) for ESP8266-based boards. [![Latest release](https://img.shields.io/github/release/esp8266/Arduino.svg)](https://github.com/esp8266/Arduino/releases/latest/). SPIFFS is deprecated from ESP8266 core 2.7.1+, to use LittleFS.
4. [`LittleFS_esp32 v1.0.6+`](https://github.com/lorol/LITTLEFS) for ESP32-based boards using LittleFS with ESP32 core **v1.0.5-**. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/LittleFS_esp32.svg?)](https://www.ardu-badge.com/LittleFS_esp32). **Notice**: This [`LittleFS_esp32 library`](https://github.com/lorol/LITTLEFS) has been integrated to Arduino [ESP32 core v1.0.6+](https://github.com/espressif/arduino-esp32/tree/master/libraries/LITTLEFS) and **you don't need to install it if using ESP32 core v1.0.6+**

Expand Down Expand Up @@ -287,7 +290,7 @@ This is terminal debug output when running [ESP32_FSWebServer_DRD](https://githu

```cpp
Starting ESP32_FSWebServer_DRD with DoubleResetDetect using SPIFFS on ESP32_DEV
ESP_WiFiManager v1.11.0
ESP_WiFiManager v1.12.1
ESP_DoubleResetDetector v1.3.2
FS File: /ConfigSW.json, size: 150B
FS File: /CanadaFlag_1.png, size: 40.25KB
Expand Down Expand Up @@ -351,9 +354,9 @@ HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH
This is terminal debug output when running [ConfigOnDoubleReset](https://github.com/khoih-prog/ESP_WiFiManager/tree/master/examples/ConfigOnDoubleReset) on **ESP32 ESP32_DEV.**. Config Portal was requested by DRD to input and save Credentials.


```
```cpp
Starting ConfigOnDoubleReset with DoubleResetDetect using LittleFS on ESP32_DEV
ESP_WiFiManager v1.11.0
ESP_WiFiManager v1.12.1
ESP_DoubleResetDetector v1.3.2
[WM] RFC925 Hostname = ConfigOnDoubleReset
[WM] Set CORS Header to : Your Access-Control-Allow-Origin
Expand Down Expand Up @@ -397,7 +400,7 @@ load:0x40080400,len:6352
entry 0x400806b8

Starting ConfigOnDoubleReset with DoubleResetDetect using LittleFS on ESP32_DEV
ESP_WiFiManager v1.11.0
ESP_WiFiManager v1.12.1
ESP_DoubleResetDetector v1.3.2
[WM] RFC925 Hostname = ConfigOnDoubleReset
[WM] Set CORS Header to : Your Access-Control-Allow-Origin
Expand Down Expand Up @@ -428,7 +431,7 @@ Starting configuration portal.
This is terminal debug output when running [ESPAsync_WiFi](https://github.com/khoih-prog/ESPAsync_WiFiManager_Lite/tree/master/examples/ESPAsync_WiFi) on **ESP32 ESP32S3_DEV.**. Config Portal was requested by DRD to input and save Credentials.
```
```cpp
Starting ESPAsync_WiFi using LittleFS on ESP32S3_DEV
ESPAsync_WiFiManager_Lite v1.9.0
ESP_DoubleResetDetector v1.3.2
Expand Down Expand Up @@ -542,7 +545,7 @@ Submit issues to: [ESP_DoubleResetDetector issues](https://github.com/khoih-prog
5. Add waitingForDRD() function to signal in DRD waiting period
6. Fix ESP32 chipID for example`ConfigOnDoubleReset`
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

---
---
Expand Down Expand Up @@ -580,6 +583,6 @@ If you want to contribute to this project:

### Copyright

Copyright 2019- Khoi Hoang
Copyright (c) 2019- Khoi Hoang


8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
## ESP_DoubleResetDetector
## ESP_DoubleResetDetector Library

[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com/ESP_DoubleResetDetector)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/ESP_DoubleResetDetector.svg)](https://github.com/khoih-prog/ESP_DoubleResetDetector/releases)
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/ESP_DoubleResetDetector/blob/master/LICENSE)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ESP_DoubleResetDetector.svg)](http://github.com/khoih-prog/ESP_DoubleResetDetector/issues)


<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
<a href="https://profile-counter.glitch.me/khoih-prog-ESP_DoubleResetDetector/count.svg" title="ESP_DoubleResetDetector Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-ESP_DoubleResetDetector/count.svg" style="height: 30px;width: 200px;"></a>

---
---

Expand Down
83 changes: 65 additions & 18 deletions examples/ConfigOnDRD_ESP32_minimal/ConfigOnDRD_ESP32_minimal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#if defined(ESP32)
#define USE_SPIFFS true
#define ESP_DRD_USE_EEPROM true
#else
#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
#else
#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
#endif
#include <ESP_WiFiManager.h> //https://github.com/khoih-prog/ESP_WiFiManager
#define DRD_TIMEOUT 10
Expand All @@ -18,27 +18,74 @@ DoubleResetDetector* drd;
const int PIN_LED = 2;
bool initialConfig = false;

void setup() {
void setup()
{
pinMode(PIN_LED, OUTPUT);
Serial.begin(115200); while (!Serial); delay(200);
Serial.print(F("\nStarting ConfigOnDoubleReset_minimal on ")); Serial.println(ARDUINO_BOARD);
Serial.println(ESP_WIFIMANAGER_VERSION);
Serial.begin(115200);

while (!Serial)
;

delay(200);
Serial.print(F("\nStarting ConfigOnDoubleReset_minimal on "));
Serial.println(ARDUINO_BOARD);
Serial.println(ESP_WIFIMANAGER_VERSION);
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
if (drd->detectDoubleReset()) { Serial.println(F("DRD")); initialConfig = true; }

if (drd->detectDoubleReset())
{
Serial.println(F("DRD"));
initialConfig = true;
}

ESP_WiFiManager ESP_wifiManager("ConfigOnDoubleReset");
if (ESP_wifiManager.WiFi_SSID() == "") { Serial.println(F("No AP credentials")); initialConfig = true; }
if (initialConfig) {
Serial.println(F("Starting Config Portal")); digitalWrite(PIN_LED, HIGH);
if (!ESP_wifiManager.startConfigPortal()) { Serial.println(F("Not connected to WiFi")); }
else { Serial.println(F("connected")); }

if (ESP_wifiManager.WiFi_SSID() == "")
{
Serial.println(F("No AP credentials"));
initialConfig = true;
}
else { WiFi.mode(WIFI_STA); WiFi.begin(); }

if (initialConfig)
{
Serial.println(F("Starting Config Portal"));
digitalWrite(PIN_LED, HIGH);

if (!ESP_wifiManager.startConfigPortal())
{
Serial.println(F("Not connected to WiFi"));
}
else
{
Serial.println(F("connected"));
}
}
else
{
WiFi.mode(WIFI_STA);
WiFi.begin();
}

unsigned long startedAt = millis();
digitalWrite(PIN_LED, LOW); Serial.print(F("After waiting "));
digitalWrite(PIN_LED, LOW);
Serial.print(F("After waiting "));
int connRes = WiFi.waitForConnectResult();
float waited = (millis() - startedAt);
Serial.print(waited / 1000); Serial.print(F(" secs , Connection result is ")); Serial.println(connRes);
if (WiFi.status() != WL_CONNECTED) { Serial.println(F("Failed to connect")); }
else { Serial.print(F("Local IP: ")); Serial.println(WiFi.localIP()); }
Serial.print(waited / 1000);
Serial.print(F(" secs , Connection result is "));
Serial.println(connRes);

if (WiFi.status() != WL_CONNECTED)
{
Serial.println(F("Failed to connect"));
}
else
{
Serial.print(F("Local IP: "));
Serial.println(WiFi.localIP());
}
}
void loop()
{
drd->loop();
}
void loop() { drd->loop(); }
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#if defined(ESP8266)
#define USE_LITTLEFS true
#define ESP_DRD_USE_LITTLEFS true
#else
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
#else
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
#endif
#include <ESP_WiFiManager.h> //https://github.com/khoih-prog/ESP_WiFiManager
#define DRD_TIMEOUT 10
Expand All @@ -18,27 +18,70 @@ DoubleResetDetector* drd;
const int PIN_LED = 2;
bool initialConfig = false;

void setup() {
void setup()
{
pinMode(PIN_LED, OUTPUT);
Serial.begin(115200); while (!Serial); delay(200);
Serial.print(F("\nStarting ConfigOnDoubleReset_minimal on ")); Serial.println(ARDUINO_BOARD);
Serial.println(ESP_WIFIMANAGER_VERSION);
if (WiFi.SSID() == "") { Serial.println(F("No AP credentials")); initialConfig = true; }
Serial.begin(115200);

while (!Serial)
;

delay(200);
Serial.print(F("\nStarting ConfigOnDoubleReset_minimal on "));
Serial.println(ARDUINO_BOARD);
Serial.println(ESP_WIFIMANAGER_VERSION);

if (WiFi.SSID() == "")
{
Serial.println(F("No AP credentials"));
initialConfig = true;
}

drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
if (drd->detectDoubleReset()) { Serial.println(F("DRD")); initialConfig = true; }
if (initialConfig) {
Serial.println(F("Starting Config Portal")); digitalWrite(PIN_LED, LOW);

if (drd->detectDoubleReset())
{
Serial.println(F("DRD"));
initialConfig = true;
}

if (initialConfig)
{
Serial.println(F("Starting Config Portal"));
digitalWrite(PIN_LED, LOW);
ESP_WiFiManager ESP_wifiManager("ConfigOnDoubleReset");
ESP_wifiManager.setConfigPortalTimeout(0);
if (!ESP_wifiManager.startConfigPortal()) { Serial.println(F("Not connected to WiFi")); }
else { Serial.println(F("connected")); }

if (!ESP_wifiManager.startConfigPortal())
{
Serial.println(F("Not connected to WiFi"));
}
else
{
Serial.println(F("connected"));
}
}
digitalWrite(PIN_LED, HIGH); Serial.print(F("After waiting ")); //WiFi.mode(WIFI_STA);

digitalWrite(PIN_LED, HIGH);
Serial.print(F("After waiting ")); //WiFi.mode(WIFI_STA);
unsigned long startedAt = millis();
int connRes = WiFi.waitForConnectResult();
float waited = (millis() - startedAt);
Serial.print(waited / 1000); Serial.print(F(" secs , Connection result is ")); Serial.println(connRes);
if (WiFi.status() != WL_CONNECTED) { Serial.println(F("Failed to connect")); }
else { Serial.print(F("Local IP: ")); Serial.println(WiFi.localIP()); }
Serial.print(waited / 1000);
Serial.print(F(" secs , Connection result is "));
Serial.println(connRes);

if (WiFi.status() != WL_CONNECTED)
{
Serial.println(F("Failed to connect"));
}
else
{
Serial.print(F("Local IP: "));
Serial.println(WiFi.localIP());
}
}
void loop()
{
drd->loop();
}
void loop() { drd->loop(); }
Loading

0 comments on commit d990bbb

Please sign in to comment.