You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
3.9 KiB
156 lines
3.9 KiB
/**************************************************************************************************************************** |
|
ESP_WiFi.ino |
|
For ESP8266 / ESP32 boards |
|
|
|
ESP_WiFiManager_Lite (https://github.com/khoih-prog/ESP_WiFiManager_Lite) is a library |
|
for the ESP32/ESP8266 boards to enable store Credentials in EEPROM/SPIFFS/LittleFS for easy |
|
configuration/reconfiguration and autoconnect/autoreconnect of WiFi and other services without Hardcoding. |
|
|
|
Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager_Lite |
|
Licensed under MIT license |
|
*****************************************************************************************************************************/ |
|
|
|
#include "defines.h" |
|
#include "Credentials.h" |
|
#include "dynamicParams.h" |
|
|
|
ESP_WiFiManager_Lite* ESP_WiFiManager; |
|
|
|
void heartBeatPrint() |
|
{ |
|
static int num = 1; |
|
|
|
if (WiFi.status() == WL_CONNECTED) |
|
Serial.print("H"); // H means connected to WiFi |
|
else |
|
{ |
|
if (ESP_WiFiManager->isConfigMode()) |
|
Serial.print("C"); // C means in Config Mode |
|
else |
|
Serial.print("F"); // F means not connected to WiFi |
|
} |
|
|
|
if (num == 80) |
|
{ |
|
Serial.println(); |
|
num = 1; |
|
} |
|
else if (num++ % 10 == 0) |
|
{ |
|
Serial.print(F(" ")); |
|
} |
|
} |
|
|
|
void check_status() |
|
{ |
|
static unsigned long checkstatus_timeout = 0; |
|
|
|
//KH |
|
#define HEARTBEAT_INTERVAL 20000L |
|
// Print hearbeat every HEARTBEAT_INTERVAL (20) seconds. |
|
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) |
|
{ |
|
heartBeatPrint(); |
|
checkstatus_timeout = millis() + HEARTBEAT_INTERVAL; |
|
} |
|
} |
|
|
|
#if USING_CUSTOMS_STYLE |
|
const char NewCustomsStyle[] PROGMEM = "<style>div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}"\ |
|
"button{background-color:blue;color:white;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}</style>"; |
|
#endif |
|
|
|
void setup() |
|
{ |
|
// Debug console |
|
Serial.begin(115200); |
|
while (!Serial); |
|
|
|
delay(200); |
|
|
|
Serial.print(F("\nStarting ESP_WiFi using ")); Serial.print(FS_Name); |
|
Serial.print(F(" on ")); Serial.println(ARDUINO_BOARD); |
|
Serial.println(ESP_WIFI_MANAGER_LITE_VERSION); |
|
|
|
#if USING_MRD |
|
Serial.println(ESP_MULTI_RESET_DETECTOR_VERSION); |
|
#else |
|
Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); |
|
#endif |
|
|
|
ESP_WiFiManager = new ESP_WiFiManager_Lite(); |
|
|
|
String AP_SSID = "12345678"; |
|
String AP_PWD = "12345678"; |
|
|
|
// Set customized AP SSID and PWD |
|
ESP_WiFiManager->setConfigPortal(AP_SSID, AP_PWD); |
|
|
|
// Optional to change default AP IP(192.168.4.1) and channel(10) |
|
//ESP_WiFiManager->setConfigPortalIP(IPAddress(192, 168, 120, 1)); |
|
ESP_WiFiManager->setConfigPortalChannel(0); |
|
|
|
#if USING_CUSTOMS_STYLE |
|
ESP_WiFiManager->setCustomsStyle(NewCustomsStyle); |
|
#endif |
|
|
|
#if USING_CUSTOMS_HEAD_ELEMENT |
|
ESP_WiFiManager->setCustomsHeadElement(PSTR("<style>html{filter: invert(10%);}</style>")); |
|
#endif |
|
|
|
#if USING_CORS_FEATURE |
|
ESP_WiFiManager->setCORSHeader(PSTR("Your Access-Control-Allow-Origin")); |
|
#endif |
|
|
|
// Set customized DHCP HostName |
|
ESP_WiFiManager->begin(HOST_NAME); |
|
//Or use default Hostname "ESP32-WIFI-XXXXXX" |
|
//ESP_WiFiManager->begin(); |
|
} |
|
|
|
#if USE_DYNAMIC_PARAMETERS |
|
void displayCredentials() |
|
{ |
|
Serial.println(F("\nYour stored Credentials :")); |
|
|
|
for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++) |
|
{ |
|
Serial.print(myMenuItems[i].displayName); |
|
Serial.print(F(" = ")); |
|
Serial.println(myMenuItems[i].pdata); |
|
} |
|
} |
|
|
|
void displayCredentialsInLoop() |
|
{ |
|
static bool displayedCredentials = false; |
|
|
|
if (!displayedCredentials) |
|
{ |
|
for (int i = 0; i < NUM_MENU_ITEMS; i++) |
|
{ |
|
if (!strlen(myMenuItems[i].pdata)) |
|
{ |
|
break; |
|
} |
|
|
|
if ( i == (NUM_MENU_ITEMS - 1) ) |
|
{ |
|
displayedCredentials = true; |
|
displayCredentials(); |
|
} |
|
} |
|
} |
|
} |
|
|
|
#endif |
|
|
|
void loop() |
|
{ |
|
ESP_WiFiManager->run(); |
|
check_status(); |
|
|
|
#if USE_DYNAMIC_PARAMETERS |
|
displayCredentialsInLoop(); |
|
#endif |
|
}
|
|
|