This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathConfigOnDRD_ESP32_minimal.ino
91 lines (81 loc) · 2.36 KB
/
ConfigOnDRD_ESP32_minimal.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/****************************************************************************************************************************
Async_ConfigOnDoubleReset_minimal.ino
For ESP8266 / ESP32 boards
Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager
Licensed under MIT license
*****************************************************************************************************************************/
#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.
#endif
#include <ESP_WiFiManager.h> //https://github.com/khoih-prog/ESP_WiFiManager
#define DRD_TIMEOUT 10
#define DRD_ADDRESS 0
#include <ESP_DoubleResetDetector.h> //https://github.com/khoih-prog/ESP_DoubleResetDetector
DoubleResetDetector* drd;
const int PIN_LED = 2;
bool initialConfig = false;
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);
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
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"));
}
}
else
{
WiFi.mode(WIFI_STA);
WiFi.begin();
}
unsigned long startedAt = millis();
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());
}
}
void loop()
{
drd->loop();
}