mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-17 16:41:31 +10:00
Merge branch 'development' into esp32
Merge branch 'development' into esp32 # Conflicts: # README.md # WiFiManager.cpp # WiFiManager.h # examples/OnDemandConfigPortal/OnDemandConfigPortal.ino
This commit is contained in:
@@ -352,6 +352,8 @@ __THANK YOU__
|
||||
|
||||
[bbx10](https://github.com/bbx10)
|
||||
|
||||
[kentaylor](https://github.com/kentaylor)
|
||||
|
||||
[Maximiliano Duarte](https://github.com/domonetic)
|
||||
|
||||
[alltheblinkythings](https://github.com/alltheblinkythings)
|
||||
@@ -376,7 +378,7 @@ __THANK YOU__
|
||||
|
||||
[walthercarsten](https://github.com/walthercarsten)
|
||||
|
||||
Sorry if i have missed anyone.
|
||||
And countless others
|
||||
|
||||
#### Inspiration
|
||||
- http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
||||
|
||||
+231
-167
@@ -46,7 +46,7 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c
|
||||
_value[i] = 0;
|
||||
}
|
||||
if (defaultValue != NULL) {
|
||||
strncpy(_value, defaultValue, length+1); // length+1 due to null terminated string
|
||||
strncpy(_value, defaultValue, length + 1); // length+1 due to null terminated string
|
||||
}
|
||||
|
||||
_customHTML = custom;
|
||||
@@ -163,7 +163,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
|
||||
// CONFIG PORTAL
|
||||
bool WiFiManager::startAP(){
|
||||
DEBUG_WM(F("StartAP with SSID of"),_apName);
|
||||
DEBUG_WM(F("StartAP with SSID: "),_apName);
|
||||
|
||||
// setup optional soft AP static ip config
|
||||
if (_ap_static_ip) {
|
||||
@@ -177,7 +177,7 @@ bool WiFiManager::startAP(){
|
||||
if (_apPassword != "") {
|
||||
ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option
|
||||
} else {
|
||||
DEBUG_WM(F("AP has anonymous access"));
|
||||
DEBUG_WM(F("AP has anonymous access!"));
|
||||
ret = WiFi.softAP(_apName.c_str());
|
||||
}
|
||||
|
||||
@@ -210,7 +210,8 @@ void WiFiManager::stopWebPortal() {
|
||||
}
|
||||
|
||||
boolean WiFiManager::configPortalHasTimeout(){
|
||||
if(_configPortalTimeout == 0 || WiFi_softap_num_stations() > 0){
|
||||
|
||||
if(_configPortalTimeout == 0 || (_cpClientCheck && (WiFi_softap_num_stations() > 0))){
|
||||
if(millis() - timer > 30000){
|
||||
timer = millis();
|
||||
DEBUG_WM("NUM CLIENTS: " + (String)WiFi_softap_num_stations());
|
||||
@@ -219,6 +220,8 @@ boolean WiFiManager::configPortalHasTimeout(){
|
||||
return false;
|
||||
}
|
||||
// handle timeout
|
||||
if(_webClientCheck && _webPortalAccessed>_configPortalStart>0) _configPortalStart = _webPortalAccessed;
|
||||
|
||||
if(millis() > _configPortalStart + _configPortalTimeout){
|
||||
DEBUG_WM(F("config portal has timed out"));
|
||||
return true;
|
||||
@@ -261,6 +264,7 @@ void WiFiManager::setupConfigPortal() {
|
||||
server->on("/r", std::bind(&WiFiManager::handleReset, this));
|
||||
server->on("/exit", std::bind(&WiFiManager::handleExit, this));
|
||||
server->on("/erase", std::bind(&WiFiManager::handleErase, this));
|
||||
server->on("/status", std::bind(&WiFiManager::handleWiFiStatus, this));
|
||||
//server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
|
||||
server->onNotFound (std::bind(&WiFiManager::handleNotFound, this));
|
||||
|
||||
@@ -572,15 +576,21 @@ String WiFiManager::getHTTPHead(String title){
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD handler for page requests
|
||||
*/
|
||||
void WiFiManager::handleRequest() {
|
||||
_webPortalAccessed = millis();
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK root or redirect to captive portal
|
||||
*/
|
||||
void WiFiManager::handleRoot() {
|
||||
DEBUG_WM(F("<- HTTP Root"));
|
||||
|
||||
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
||||
|
||||
String page = getHTTPHead("options"); // @token options
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_options)); // @token options
|
||||
String str = FPSTR(HTTP_ROOT_MAIN);
|
||||
str.replace("{v}",configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading
|
||||
page += str;
|
||||
@@ -597,9 +607,9 @@ void WiFiManager::handleRoot() {
|
||||
* HTTPD CALLBACK Wifi config page handler
|
||||
*/
|
||||
void WiFiManager::handleWifi(boolean scan) {
|
||||
|
||||
DEBUG_WM("<- HTTP Wifi");
|
||||
String page = getHTTPHead("Config ESP"); // @token titlewifi
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi
|
||||
if (scan) {
|
||||
page += getScanItemOut();
|
||||
}
|
||||
@@ -631,7 +641,7 @@ String WiFiManager::getScanItemOut(){
|
||||
DEBUG_WM(F("Scan done"));
|
||||
if (n == 0) {
|
||||
DEBUG_WM(F("No networks found"));
|
||||
page += F("No networks found. Refresh to scan again."); // @token scannotfound
|
||||
page += FPSTR(S_nonetworks); // @token nonetworks
|
||||
} else {
|
||||
|
||||
//sort networks
|
||||
@@ -718,7 +728,7 @@ String WiFiManager::getScanItemOut(){
|
||||
|
||||
String WiFiManager::getStaticOut(){
|
||||
String page;
|
||||
if (_sta_show_static_fields || _sta_static_ip) {
|
||||
if (_staShowStaticFields || _sta_static_ip) {
|
||||
|
||||
// @todo how can we get these settings from memory , wifi_get_ip_info does not seem to reveal if struct ip_info is static or not
|
||||
// @todo move titles to params for i18n
|
||||
@@ -728,7 +738,7 @@ String WiFiManager::getStaticOut(){
|
||||
item.replace("{i}", "ip");
|
||||
item.replace("{n}", "ip");
|
||||
item.replace("{p}", "{t}");
|
||||
item.replace("{t}", "Static IP"); // @token staticip
|
||||
item.replace("{t}", FPSTR(S_staticip)); // @token staticip
|
||||
item.replace("{l}", "15");
|
||||
item.replace("{v}", (_sta_static_ip ? _sta_static_ip.toString() : ""));
|
||||
item.replace("{c}", "");
|
||||
@@ -744,7 +754,7 @@ String WiFiManager::getStaticOut(){
|
||||
item.replace("{i}", "gw");
|
||||
item.replace("{n}", "gw");
|
||||
item.replace("{p}", "{t}");
|
||||
item.replace("{t}", "Static Gateway"); // @token staticgateway
|
||||
item.replace("{t}", FPSTR(S_staticgw)); // @token staticgw
|
||||
item.replace("{l}", "15");
|
||||
item.replace("{v}", (_sta_static_gw ? _sta_static_gw.toString() : ""));
|
||||
item.replace("{c}", "");
|
||||
@@ -760,7 +770,7 @@ String WiFiManager::getStaticOut(){
|
||||
item.replace("{i}", "sn");
|
||||
item.replace("{n}", "sn");
|
||||
item.replace("{p}", "{t}");
|
||||
item.replace("{t}", "Subnet"); // @token subnet
|
||||
item.replace("{t}", FPSTR(S_subnet)); // @token subnet
|
||||
item.replace("{l}", "15");
|
||||
item.replace("{v}", (_sta_static_sn ? _sta_static_sn.toString() : ""));
|
||||
item.replace("{c}", "");
|
||||
@@ -841,13 +851,23 @@ String WiFiManager::getParamOut(){
|
||||
return page;
|
||||
}
|
||||
|
||||
void WiFiManager::handleWiFiStatus(){
|
||||
DEBUG_WM(F("<- HTTP WiFi status "));
|
||||
handleRequest();
|
||||
String page;
|
||||
// String page = "{\"result\":true,\"count\":1}";
|
||||
page = FPSTR(HTTP_JS);
|
||||
server->sendHeader("Content-Length", String(page.length()));
|
||||
server->send(200, "text/html", page);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK save form and redirect to WLAN config page again
|
||||
*/
|
||||
void WiFiManager::handleWifiSave() {
|
||||
DEBUG_WM(F("<- HTTP WiFi save "));
|
||||
|
||||
DEBUG_WM(F("Method:"),server->method() == HTTP_GET ? "GET" : "POST");
|
||||
handleRequest();
|
||||
|
||||
//SAVE/connect here
|
||||
_ssid = server->arg("s").c_str();
|
||||
@@ -890,7 +910,7 @@ void WiFiManager::handleWifiSave() {
|
||||
DEBUG_WM(F("static netmask:"),sn);
|
||||
}
|
||||
|
||||
String page = getHTTPHead("Credentials Saved"); // @token titlewifisaved
|
||||
String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
|
||||
page += FPSTR(HTTP_SAVED);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
@@ -907,127 +927,45 @@ void WiFiManager::handleWifiSave() {
|
||||
*/
|
||||
void WiFiManager::handleInfo() {
|
||||
DEBUG_WM(F("<- HTTP Info"));
|
||||
String page = getHTTPHead("Info"); // @token titleinfo
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo
|
||||
reportStatus(page);
|
||||
|
||||
// @todo add versioning here
|
||||
|
||||
#ifdef ESP8266
|
||||
page += F("<h3>esp8266</h3><hr><dl>");
|
||||
|
||||
// subject to rollover!
|
||||
page += F("<dt>Uptime</dt><dd>"); // @token uptime
|
||||
page += (String)(millis() / 1000 / 60) + " mins ";
|
||||
page += (String)((millis() / 1000) % 60) + " secs";
|
||||
#ifdef ESP8266
|
||||
String infoids[] = {
|
||||
"esphead",
|
||||
"uptime",
|
||||
"chipid",
|
||||
"fchipid",
|
||||
"idesize",
|
||||
"flashsize",
|
||||
"sdkver",
|
||||
"corever",
|
||||
"bootver",
|
||||
"cpufreq",
|
||||
"freeheap",
|
||||
"memsketch",
|
||||
"memsmeter",
|
||||
"lastreset",
|
||||
"wifihead",
|
||||
"apip",
|
||||
"apmac",
|
||||
"apssid",
|
||||
"apbssid",
|
||||
"staip",
|
||||
"stagw",
|
||||
"stasub",
|
||||
"dnss",
|
||||
"host",
|
||||
"stamac",
|
||||
"conx",
|
||||
"autoconx"
|
||||
};
|
||||
|
||||
page += F("<dt>Chip ID</dt><dd>"); // @token chipid
|
||||
page += WIFI_getChipId();
|
||||
page += F("</dd>");
|
||||
for(int i=0; i<25;i++){
|
||||
page += getInfoData(infoids[i]);
|
||||
}
|
||||
|
||||
page += F("<dt>Flash Chip ID</dt><dd>"); // @token flashid
|
||||
page += ESP.getFlashChipId();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>IDE Flash Size</dt><dd>"); // @token flashsize
|
||||
page += ESP.getFlashChipSize();
|
||||
page += F(" bytes</dd>");
|
||||
|
||||
page += F("<dt>Actual Flash Size</dt><dd>"); // @token actualflashsize
|
||||
page += ESP.getFlashChipRealSize();
|
||||
page += F(" bytes</dd>");
|
||||
|
||||
page += F("<dt>SDK Version</dt><dd>"); // @token sdkver
|
||||
page += system_get_sdk_version();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>Core Version</dt><dd>"); // @token corever
|
||||
page += ESP.getCoreVersion();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>Boot Version</dt><dd>"); // @token boot ver
|
||||
page += system_get_boot_version();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>CPU Frequency</dt><dd>"); // @token cpufreq
|
||||
page += ESP.getCpuFreqMHz();
|
||||
page += F("MHz</dd>");
|
||||
|
||||
// heap is dynamic, would have to have a known starting for graph
|
||||
// uint32_t heapstart = 47000;
|
||||
// page += F("<dt>Memory Heap</dt><dd>");
|
||||
// page += F("Used/Total bytes<br/>");
|
||||
// page += (heapstart)-ESP.getFreeHeap();
|
||||
// page += "/";
|
||||
// page += (heapstart);
|
||||
// page += "<br/><progress value='" + (String)((heapstart)-ESP.getFreeHeap()) + "' max='" + (String)(heapstart) + "'></progress>";
|
||||
// page += F("</dd>");
|
||||
|
||||
page += F("<dt>Memory - Free Heap</dt><dd>"); // @token freeheap
|
||||
page += ESP.getFreeHeap();
|
||||
page += F(" bytes available</dd>"); // @token bytesavail
|
||||
|
||||
page += F("<dt>Memory - Sketch Size</dt><dd>"); // @token sketchsize
|
||||
page += F("Used/Total bytes<br/>"); // @token usedtotal
|
||||
page += (ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace();
|
||||
page += "/";
|
||||
page += (ESP.getSketchSize()+ESP.getFreeSketchSpace());
|
||||
page += F("<br/><progress value='");
|
||||
page += (String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace());
|
||||
page += F("' max='");
|
||||
page += (String)(ESP.getSketchSize()+ESP.getFreeSketchSpace());
|
||||
page += F("'></progress></dd>");
|
||||
|
||||
page += F("<dt>Last reset reason</dt><dd>"); // @token resetreason
|
||||
page += ESP.getResetReason();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<br/><h3>WiFi</h3><hr><dt>Access Point IP</dt><dd>"); // @token apip
|
||||
page += WiFi.softAPIP().toString();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>Access Point MAC</dt><dd>"); // @token apmac
|
||||
page += WiFi.softAPmacAddress();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>SSID</dt><dd>");
|
||||
page += WiFi_SSID();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>BSSID</dt><dd>");
|
||||
page += WiFi.BSSIDstr();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>Station IP</dt><dd>"); // @token staip
|
||||
page += WiFi.localIP().toString();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>Station Gateway</dt><dd>"); // @token stagw
|
||||
page += WiFi.gatewayIP().toString();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>Station Subnet</dt><dd>"); // @token stasub
|
||||
page += WiFi.subnetMask().toString();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>DNS Server</dt><dd>"); // @token dnss
|
||||
page += WiFi.dnsIP().toString();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>Hostname</dt><dd>"); // @token hostname
|
||||
page += WiFi.hostname();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>Station MAC</dt><dd>"); // @stamac
|
||||
page += WiFi.macAddress();
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>Connected</dt><dd>"); // @token connected
|
||||
page += WiFi.isConnected() ? "Yes" : "No"; //@token Y,N
|
||||
page += F("</dd>");
|
||||
|
||||
page += F("<dt>Autoconnect</dt><dd>");
|
||||
page += WiFi.getAutoConnect() ? "Enabled" : "Disabled"; // @token enabled,disabled
|
||||
page += F("</dd>");
|
||||
page += F("</dl>");
|
||||
#endif
|
||||
|
||||
@@ -1127,46 +1065,141 @@ void WiFiManager::handleInfo() {
|
||||
DEBUG_WM(F("Sent info page"));
|
||||
}
|
||||
|
||||
String WiFiManager::getInfoData(String id){
|
||||
|
||||
String p;
|
||||
// @todo add versioning
|
||||
if(id=="esphead")p = FPSTR(HTTP_INFO_esphead);
|
||||
else if(id=="wifihead")p = FPSTR(HTTP_INFO_wifihead);
|
||||
else if(id=="uptime"){
|
||||
// subject to rollover!
|
||||
p = FPSTR(HTTP_INFO_uptime);
|
||||
p.replace("{1}",(String)(system_get_time() / 1000000 / 60));
|
||||
p.replace("{2}",(String)((system_get_time() / 1000000)%60));
|
||||
}
|
||||
else if(id=="chipid"){
|
||||
p = FPSTR(HTTP_INFO_chipid);
|
||||
p.replace("{1}",(String)WIFI_getChipId());
|
||||
}
|
||||
else if(id=="fchipid"){
|
||||
p = FPSTR(HTTP_INFO_fchipid);
|
||||
p.replace("{1}",(String)ESP.getFlashChipId());
|
||||
}
|
||||
else if(id=="idesize"){
|
||||
p = FPSTR(HTTP_INFO_idesize);
|
||||
p.replace("{1}",(String)ESP.getFlashChipSize());
|
||||
}
|
||||
else if(id=="flashsize"){
|
||||
p = FPSTR(HTTP_INFO_flashsize);
|
||||
p.replace("{1}",(String)ESP.getFlashChipRealSize());
|
||||
}
|
||||
else if(id=="sdkver"){
|
||||
p = FPSTR(HTTP_INFO_sdkver);
|
||||
p.replace("{1}",(String)system_get_sdk_version());
|
||||
}
|
||||
else if(id=="corever"){
|
||||
p = FPSTR(HTTP_INFO_corever);
|
||||
p.replace("{1}",(String)ESP.getCoreVersion());
|
||||
}
|
||||
else if(id=="bootver"){
|
||||
p = FPSTR(HTTP_INFO_bootver);
|
||||
p.replace("{1}",(String)system_get_boot_version());
|
||||
}
|
||||
else if(id=="cpufreq"){
|
||||
p = FPSTR(HTTP_INFO_cpufreq);
|
||||
p.replace("{1}",(String)ESP.getCpuFreqMHz());
|
||||
}
|
||||
else if(id=="freeheap"){
|
||||
p = FPSTR(HTTP_INFO_freeheap);
|
||||
p.replace("{1}",(String)ESP.getFreeHeap());
|
||||
}
|
||||
else if(id=="memsketch"){
|
||||
p = FPSTR(HTTP_INFO_memsketch);
|
||||
p.replace("{1}",(String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace()));
|
||||
p.replace("{2}",(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace()));
|
||||
}
|
||||
else if(id=="memsmeter"){
|
||||
p = FPSTR(HTTP_INFO_memsmeter);
|
||||
p.replace("{1}",(String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace()));
|
||||
p.replace("{2}",(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace()));
|
||||
}
|
||||
else if(id=="lastreset"){
|
||||
p = FPSTR(HTTP_INFO_lastreset);
|
||||
p.replace("{1}",(String)ESP.getResetReason());
|
||||
}
|
||||
else if(id=="apip"){
|
||||
p = FPSTR(HTTP_INFO_apip);
|
||||
p.replace("{1}",WiFi.softAPIP().toString());
|
||||
}
|
||||
else if(id=="apmac"){
|
||||
p = FPSTR(HTTP_INFO_apmac);
|
||||
p.replace("{1}",(String)WiFi.softAPmacAddress());
|
||||
}
|
||||
else if(id=="apssid"){
|
||||
p = FPSTR(HTTP_INFO_apssid);
|
||||
p.replace("{1}",(String)WiFi.SSID());
|
||||
}
|
||||
else if(id=="apbssid"){
|
||||
p = FPSTR(HTTP_INFO_apbssid);
|
||||
p.replace("{1}",(String)WiFi.BSSIDstr());
|
||||
}
|
||||
else if(id=="staip"){
|
||||
p = FPSTR(HTTP_INFO_staip);
|
||||
p.replace("{1}",WiFi.localIP().toString());
|
||||
}
|
||||
else if(id=="stagw"){
|
||||
p = FPSTR(HTTP_INFO_stagw);
|
||||
p.replace("{1}",WiFi.gatewayIP().toString());
|
||||
}
|
||||
else if(id=="stasub"){
|
||||
p = FPSTR(HTTP_INFO_stasub);
|
||||
p.replace("{1}",WiFi.subnetMask().toString());
|
||||
}
|
||||
else if(id=="dnss"){
|
||||
p = FPSTR(HTTP_INFO_dnss);
|
||||
p.replace("{1}",WiFi.dnsIP().toString());
|
||||
}
|
||||
else if(id=="host"){
|
||||
p = FPSTR(HTTP_INFO_host);
|
||||
p.replace("{1}",WiFi.hostname());
|
||||
}
|
||||
else if(id=="stamac)"){
|
||||
p = FPSTR(HTTP_INFO_stamac);
|
||||
p.replace("{1}",WiFi.macAddress());
|
||||
}
|
||||
else if(id=="conx"){
|
||||
p = FPSTR(HTTP_INFO_conx);
|
||||
p.replace("{1}",WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n));
|
||||
}
|
||||
else if(id=="autoconx"){
|
||||
p = FPSTR(HTTP_INFO_autoconx);
|
||||
p.replace("{1}",WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable));
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK root or redirect to captive portal
|
||||
*/
|
||||
void WiFiManager::handleExit() {
|
||||
DEBUG_WM(F("<- HTTP Exit"));
|
||||
String page = getHTTPHead("Exit"); // @token titleexit
|
||||
page += "Exiting"; // @token exiting
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit
|
||||
page += FPSTR(S_exiting); // @token exiting
|
||||
server->sendHeader("Content-Length", String(page.length()));
|
||||
server->send(200, "text/html", page);
|
||||
abort = true;
|
||||
}
|
||||
|
||||
void WiFiManager::reportStatus(String &page){
|
||||
String str;
|
||||
if (WiFi_SSID() != ""){
|
||||
if (WiFi.status()==WL_CONNECTED){
|
||||
str = FPSTR(HTTP_STATUS_ON);
|
||||
str.replace("{u}",WiFi.localIP().toString());
|
||||
str.replace("{s}",WiFi_SSID());
|
||||
}
|
||||
else {
|
||||
str = FPSTR(HTTP_STATUS_OFF);
|
||||
str.replace("{s}",WiFi_SSID());
|
||||
}
|
||||
}
|
||||
else {
|
||||
str = FPSTR(HTTP_STATUS_NONE);
|
||||
}
|
||||
page += str;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK reset page
|
||||
*/
|
||||
void WiFiManager::handleReset() {
|
||||
DEBUG_WM(F("<- HTTP Reset"));
|
||||
|
||||
String page = getHTTPHead("Reset"); //@token titlereset
|
||||
page += F("Module will reset in a few seconds.");
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset
|
||||
page += FPSTR(S_resetting); //@token resetting
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader("Content-Length", String(page.length()));
|
||||
@@ -1182,14 +1215,15 @@ void WiFiManager::handleReset() {
|
||||
*/
|
||||
void WiFiManager::handleErase() {
|
||||
DEBUG_WM(F("<- HTTP Erase"));
|
||||
|
||||
String page = getHTTPHead("Erase"); // @token titleerase
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase
|
||||
page += FPSTR(HTTP_HEAD_END);
|
||||
|
||||
bool ret = WiFi_eraseConfig();
|
||||
|
||||
if(ret) page += F("Module will reset in a few seconds."); // @token resetting
|
||||
if(ret) page += FPSTR(S_resetting); // @token resetting
|
||||
else {
|
||||
page += F("An Error Occured"); // @token erroroccur
|
||||
page += FPSTR(S_error); // @token erroroccur
|
||||
DEBUG_WM(F("[ERROR] WiFi EraseConfig failed"));
|
||||
}
|
||||
|
||||
@@ -1204,15 +1238,18 @@ void WiFiManager::handleErase() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK 404
|
||||
*/
|
||||
void WiFiManager::handleNotFound() {
|
||||
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
||||
|
||||
String message = "File Not Found\n\n"; // @token notfound
|
||||
message += "URI: "; // @token uri
|
||||
handleRequest();
|
||||
String message = FPSTR(S_notfound); // @token notfound
|
||||
message += FPSTR(S_uri); // @token uri
|
||||
message += server->uri();
|
||||
message += "\nMethod: "; // @token method
|
||||
message += FPSTR(S_method); // @token method
|
||||
message += ( server->method() == HTTP_GET ) ? "GET" : "POST";
|
||||
message += "\nArguments: "; // @token args
|
||||
message += FPSTR(S_args); // @token args
|
||||
message += server->args();
|
||||
message += "\n";
|
||||
|
||||
@@ -1246,6 +1283,25 @@ boolean WiFiManager::captivePortal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void WiFiManager::reportStatus(String &page){
|
||||
String str;
|
||||
if (WiFi_SSID() != ""){
|
||||
if (WiFi.status()==WL_CONNECTED){
|
||||
str = FPSTR(HTTP_STATUS_ON);
|
||||
str.replace("{u}",WiFi.localIP().toString());
|
||||
str.replace("{s}",WiFi_SSID());
|
||||
}
|
||||
else {
|
||||
str = FPSTR(HTTP_STATUS_OFF);
|
||||
str.replace("{s}",WiFi_SSID());
|
||||
}
|
||||
}
|
||||
else {
|
||||
str = FPSTR(HTTP_STATUS_NONE);
|
||||
}
|
||||
page += str;
|
||||
}
|
||||
|
||||
// MORE SETTERS
|
||||
|
||||
//start up config portal callback
|
||||
@@ -1280,7 +1336,7 @@ void WiFiManager::setRestorePersistent(boolean persistent) {
|
||||
}
|
||||
|
||||
void WiFiManager::setShowStaticFields(boolean alwaysShow){
|
||||
_sta_show_static_fields = alwaysShow;
|
||||
_staShowStaticFields = alwaysShow;
|
||||
}
|
||||
|
||||
void WiFiManager::setCaptivePortalEnable(boolean enabled){
|
||||
@@ -1291,6 +1347,14 @@ void WiFiManager::setWiFiAutoReconnect(boolean enabled){
|
||||
_wifiAutoReconnect = enabled;
|
||||
}
|
||||
|
||||
void WiFiManager::setCaptivePortalClientCheck(boolean enabled){
|
||||
_cpClientCheck = enabled;
|
||||
}
|
||||
|
||||
void WiFiManager::setWebPortalClientCheck(boolean enabled){
|
||||
_webClientCheck = enabled;
|
||||
}
|
||||
|
||||
// HELPERS
|
||||
|
||||
template <typename Generic>
|
||||
|
||||
+12
-1
@@ -150,8 +150,13 @@ class WiFiManager
|
||||
void setShowStaticFields(boolean alwaysShow);
|
||||
//if true disable captive portal redirection
|
||||
void setCaptivePortalEnable(boolean enabled);
|
||||
//if true, timeout captive portal even if a STA client connected (true), suggest disabling if captiveportal is open
|
||||
void setCaptivePortalClientCheck(boolean enabled);
|
||||
//if true, reset timeout when webclient connects (true), suggest disabling if captiveportal is open
|
||||
void setWebPortalClientCheck(boolean enabled);
|
||||
// if true enable autoreconnecting
|
||||
void setWiFiAutoReconnect(boolean enabled);
|
||||
|
||||
void debugPlatformInfo();
|
||||
void debugSoftAPConfig();
|
||||
|
||||
@@ -185,6 +190,7 @@ class WiFiManager
|
||||
unsigned long _configPortalTimeout = 0;
|
||||
unsigned long _connectTimeout = 0;
|
||||
unsigned long _configPortalStart = 0;
|
||||
unsigned long _webPortalAccessed = 0;
|
||||
WiFiMode_t _usermode = WIFI_OFF;
|
||||
|
||||
#ifdef ESP8266
|
||||
@@ -201,10 +207,12 @@ class WiFiManager
|
||||
boolean _shouldBreakAfterConfig = false;
|
||||
boolean _tryWPS = false;
|
||||
boolean _configPortalIsBlocking = true;
|
||||
boolean _sta_show_static_fields = false;
|
||||
boolean _staShowStaticFields = false;
|
||||
boolean _enableCaptivePortal = true;
|
||||
boolean _userpersistent = true;
|
||||
boolean _wifiAutoReconnect = false;
|
||||
boolean _cpClientCheck = false; // keep cp alive if cp have station
|
||||
boolean _webClientCheck = true; // keep cp alive if web have client
|
||||
|
||||
const char* _customHeadElement = "";
|
||||
|
||||
@@ -226,6 +234,8 @@ class WiFiManager
|
||||
void handleNotFound();
|
||||
void handleExit();
|
||||
void handleErase();
|
||||
void handleWiFiStatus();
|
||||
void handleRequest();
|
||||
|
||||
boolean captivePortal();
|
||||
boolean configPortalHasTimeout();
|
||||
@@ -261,6 +271,7 @@ class WiFiManager
|
||||
boolean validApPassword();
|
||||
String encryptionTypeStr(uint8_t authmode);
|
||||
void reportStatus(String &page);
|
||||
String getInfoData(String id);
|
||||
|
||||
// flags
|
||||
boolean connect;
|
||||
|
||||
@@ -51,7 +51,7 @@ void loop() {
|
||||
//sets timeout until configuration portal gets turned off
|
||||
//useful to make it all retry or go to sleep
|
||||
//in seconds
|
||||
//wifiManager.setConfigPortalTimeout(120);
|
||||
wifiManager.setConfigPortalTimeout(120);
|
||||
|
||||
//it starts an access point with the specified name
|
||||
//here "AutoConnectAP"
|
||||
@@ -66,16 +66,11 @@ void loop() {
|
||||
if (!wifiManager.startConfigPortal("OnDemandAP")) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
delay(3000);
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
ESP.restart();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
//if you get here you have connected to the WiFi
|
||||
Serial.println("connected...yeey :)");
|
||||
} else {
|
||||
//if you get here you have connected to the WiFi
|
||||
Serial.println("connected...yeey :)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
}
|
||||
|
||||
+80
-1
@@ -68,4 +68,83 @@ const char HTTP_HELP[] PROGMEM =
|
||||
"</table>"
|
||||
"<p/>More information about WiFiManager at <a href='https://github.com/tzapu/WiFiManager'>https://github.com/tzapu/WiFiManager</a>.";
|
||||
|
||||
#endif
|
||||
const char HTTP_JS[] PROGMEM =
|
||||
"<script>function postAjax(url, data, success) {"
|
||||
" var params = typeof data == 'string' ? data : Object.keys(data).map("
|
||||
" function(k){ return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) }"
|
||||
" ).join('&');"
|
||||
""
|
||||
" var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject(\"Microsoft.XMLHTTP\");"
|
||||
" xhr.open('POST', url);"
|
||||
" xhr.onreadystatechange = function() {"
|
||||
" if (xhr.readyState>3 && xhr.status==200) { success(xhr.responseText); }"
|
||||
" };"
|
||||
" xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');"
|
||||
" xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');"
|
||||
" xhr.send(params);"
|
||||
" return xhr;"
|
||||
"}"
|
||||
""
|
||||
"// example request\n"
|
||||
"postAjax('/status', 'p1=1&p2=Hello+World', function(data){ console.log(data); });"
|
||||
""
|
||||
"// example request with data object\n"
|
||||
"postAjax('/status', { p1: 1, p2: 'Hello World' }, function(data){ console.log(data); });"
|
||||
"</script>";
|
||||
|
||||
const char HTTP_INFO_esphead[] PROGMEM = "<h3>esp8266</h3><hr><dl>";
|
||||
const char HTTP_INFO_wifihead[] PROGMEM = "<br/><h3>WiFi</h3><hr>";
|
||||
|
||||
const char HTTP_INFO_uptime[] PROGMEM = "<dt>Uptime</dt>{1} Mins {2} Secs<dd></dd>";
|
||||
const char HTTP_INFO_chipid[] PROGMEM = "<dt>Chip ID</dt>{1}<dd></dd>";
|
||||
const char HTTP_INFO_fchipid[] PROGMEM = "<dt>Flash Chip ID</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_idesize[] PROGMEM = "<dt>IDE Flash Size</dt><dd>{1} bytes</dd>";
|
||||
const char HTTP_INFO_flashsize[] PROGMEM = "<dt>Actual Flash Size</dt><dd>{1} bytes</dd>";
|
||||
const char HTTP_INFO_sdkver[] PROGMEM = "<dt>SDK Version</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_corever[] PROGMEM = "<dt>Core Version</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_bootver[] PROGMEM = "<dt>Boot Version</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_cpufreq[] PROGMEM = "<dt>CPU Frequency</dt><dd>{1}MHz</dd>";
|
||||
const char HTTP_INFO_freeheap[] PROGMEM = "<dt>Memory - Free Heap</dt><dd>{1} bytes available</dd>";
|
||||
const char HTTP_INFO_memsketch[] PROGMEM = "<dt>Memory - Sketch Size</dt><dd>{1}";
|
||||
const char HTTP_INFO_memstbytes[] PROGMEM = "Used/Total bytes<br/>{1}/{2}";
|
||||
const char HTTP_INFO_memsmeter[] PROGMEM = "<br/><progress value='{1}' max='{2}'></progress></dd>";
|
||||
const char HTTP_INFO_lastreset[] PROGMEM = "<dt>Last reset reason</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_apip[] PROGMEM = "<dt>Access Point IP</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_apmac[] PROGMEM = "<dt>Access Point MAC</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_apssid[] PROGMEM = "<dt>SSID</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_apbssid[] PROGMEM = "<dt>BSSID</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_staip[] PROGMEM = "<dt>Station IP</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_stagw[] PROGMEM = "<dt>Station Gateway</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_stasub[] PROGMEM = "<dt>Station Subnet</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_dnss[] PROGMEM = "<dt>DNS Server</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_host[] PROGMEM = "<dt>Hostname</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_stamac[] PROGMEM = "<dt>Station MAC</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_conx[] PROGMEM = "<dt>Connected</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_autoconx[] PROGMEM = "<dt>Autoconnect</dt><dd>{1}</dd>";
|
||||
|
||||
const char S_y[] PROGMEM = "Yes";
|
||||
const char S_n[] PROGMEM = "No";
|
||||
const char S_enable[] PROGMEM = "Enabled";
|
||||
const char S_disable[] PROGMEM = "Disabled";
|
||||
|
||||
const char S_titlewifisaved[] PROGMEM = "Credentials Saved"; // @token titlewifisaved
|
||||
const char S_titlewifi[] PROGMEM = "Config ESP"; // @token titlewifi
|
||||
const char S_titleinfo[] PROGMEM = "Info"; // @token titleinfo
|
||||
const char S_titleexit[] PROGMEM = "Exit"; // @token titleexit
|
||||
const char S_titlereset[] PROGMEM = "Reset"; //@token titlereset
|
||||
const char S_titleerase[] PROGMEM = "Erase"; // @token titleerase
|
||||
const char S_options[] PROGMEM = "options"; // @token options
|
||||
const char S_nonetworks[] PROGMEM = "No networks found. Refresh to scan again."; // @token nonetworks
|
||||
const char S_staticip[] PROGMEM = "Static IP"; // @token staticip
|
||||
const char S_staticgw[] PROGMEM = "Static Gateway"; // @token staticgw
|
||||
const char S_subnet[] PROGMEM = "Subnet"; // @token subnet
|
||||
const char S_exiting[] PROGMEM = "Exiting"; // @token exiting
|
||||
const char S_resetting[] PROGMEM = "Module will reset in a few seconds."; //@token resetting
|
||||
const char S_error[] PROGMEM = "An Error Occured"; // @token erroroccur
|
||||
const char S_notfound[] PROGMEM = "File Not Found\n\n"; // @token notfound
|
||||
const char S_uri[] PROGMEM = "URI: "; // @token uri
|
||||
const char S_method[] PROGMEM = "\nMethod: "; // @token method
|
||||
const char S_args[] PROGMEM = "\nArguments: "; // @token args
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user