From d5ba651dae529049a94007fb5b1d431ece9364de Mon Sep 17 00:00:00 2001 From: r-downing <26515643+r-downing@users.noreply.github.com> Date: Sun, 19 Nov 2017 18:22:22 -0500 Subject: [PATCH 01/10] new trial version, nonblock + handlers --- .gitignore | 4 ++- PersWiFiManager.cpp | 68 +++++++++++++++++++++++++++++++++------------ PersWiFiManager.h | 17 ++++++++++++ keywords.txt | 2 ++ 4 files changed, 73 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index d155341..1065d7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -PersWiFiManager.ino \ No newline at end of file +PersWiFiManager.ino +data/* +!data/wifi* \ No newline at end of file diff --git a/PersWiFiManager.cpp b/PersWiFiManager.cpp index 0ab4ce8..f048e5c 100644 --- a/PersWiFiManager.cpp +++ b/PersWiFiManager.cpp @@ -1,7 +1,7 @@ /* PersWiFiManager - * version 2.0.2 - * https://r-downing.github.io/PersWiFiManager/ - */ + version 2.0.2 - nonblock mod + https://r-downing.github.io/PersWiFiManager/ +*/ #include "PersWiFiManager.h" @@ -16,11 +16,6 @@ PersWiFiManager::PersWiFiManager(ESP8266WebServer& s, DNSServer& d) { } //PersWiFiManager bool PersWiFiManager::attemptConnection(const String& ssid, const String& pass) { - IPAddress apIP(192, 168, 1, 1); - //moved dns start to here - _dnsServer->setErrorReplyCode(DNSReplyCode::NoError); - _dnsServer->start((byte)53, "*", apIP); //used for captive portal in AP mode - //attempt to connect to wifi WiFi.mode(WIFI_STA); if (ssid.length()) { @@ -29,19 +24,49 @@ bool PersWiFiManager::attemptConnection(const String& ssid, const String& pass) } else { WiFi.begin(); } - unsigned long connectTime = millis(); - //while ((millis() - connectTime) < 1000 * WIFI_CONNECT_TIMEOUT && WiFi.status() != WL_CONNECTED) - while (WiFi.status() != WL_CONNECT_FAILED && WiFi.status() != WL_CONNECTED && (millis() - connectTime) < 1000 * WIFI_CONNECT_TIMEOUT) + + //if in nonblock mode, skip this loop + _connectStartTime = millis() + 1; + while (!_connectNonBlock && _connectStartTime) { + handleWiFi(); delay(10); - if (WiFi.status() == WL_CONNECTED) return true;// { //if timed out, switch to AP mode - WiFi.mode(WIFI_AP); - WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); - _apPass.length() ? WiFi.softAP(getApSsid().c_str(), _apPass.c_str()) : WiFi.softAP(getApSsid().c_str()); - return false;//} //if - //moved dns start from here + } + + return (WiFi.status() == WL_CONNECTED); + } //attemptConnection +void PersWiFiManager::handleWiFi() { + if (!_connectStartTime) return; + + if (WiFi.status() == WL_CONNECTED) { + _connectStartTime = 0; + if (_connectHandler) _connectHandler(); + return; + } + + //if failed or not connected and time is up + if ((WiFi.status() == WL_CONNECT_FAILED) || (WiFi.status() != WL_CONNECTED && (millis() - _connectStartTime) > 1000 * WIFI_CONNECT_TIMEOUT)) { + //start AP mode + IPAddress apIP(192, 168, 1, 1); + WiFi.mode(WIFI_AP); + WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); + _apPass.length() ? WiFi.softAP(getApSsid().c_str(), _apPass.c_str()) : WiFi.softAP(getApSsid().c_str()); + _connectStartTime = 0; //reset connect start time + if (_failHandler) _failHandler(); + } + +} //handleWiFi + +void PersWiFiManager::setConnectNonBlock(bool b) { + _connectNonBlock = b; +} //setConnectNonBlock + void PersWiFiManager::setupWiFiHandlers() { + IPAddress apIP(192, 168, 1, 1); + _dnsServer->setErrorReplyCode(DNSReplyCode::NoError); + _dnsServer->start((byte)53, "*", apIP); //used for captive portal in AP mode + _server->on("/wifi/list", [&] () { //scan for wifi networks int n = WiFi.scanNetworks(); @@ -113,3 +138,12 @@ void PersWiFiManager::setApCredentials(const String& apSsid, const String& apPas if (apPass.length() >= 8) _apPass = apPass; } //setApCredentials +void PersWiFiManager::onConnect(WiFiChangeHandlerFunction fn) { + _connectHandler = fn; +} + +void PersWiFiManager::onFail(WiFiChangeHandlerFunction fn) { + _failHandler = fn; +} + + diff --git a/PersWiFiManager.h b/PersWiFiManager.h index 42c3a93..b85ce93 100644 --- a/PersWiFiManager.h +++ b/PersWiFiManager.h @@ -10,6 +10,9 @@ class PersWiFiManager { public: + + typedef std::function WiFiChangeHandlerFunction; + //constructor - takes inputs for ESP8266WebServer and DNSServer, optional ap ssid PersWiFiManager(ESP8266WebServer& s, DNSServer& d); @@ -23,11 +26,25 @@ class PersWiFiManager { void setApCredentials(const String& apSsid, const String& apPass = ""); + void setConnectNonBlock(bool b); + + void handleWiFi(); + + void onConnect(WiFiChangeHandlerFunction fn); + + void onFail(WiFiChangeHandlerFunction fn); + private: ESP8266WebServer * _server; DNSServer * _dnsServer; String _apSsid, _apPass; + bool _connectNonBlock; + unsigned long _connectStartTime; + + WiFiChangeHandlerFunction _connectHandler; + WiFiChangeHandlerFunction _failHandler; + };//class #endif diff --git a/keywords.txt b/keywords.txt index 90040d8..d03975b 100644 --- a/keywords.txt +++ b/keywords.txt @@ -17,6 +17,8 @@ setupWiFiHandlers KEYWORD2 begin KEYWORD2 getApSsid KEYWORD2 setApCredentials KEYWORD2 +handleWiFi KEYWORD2 +setConnectNonBlock KEYWORD2 ####################################### # Constants (LITERAL1) From ebabeecaa3cd802203258128d1ed3376c1a0fb86 Mon Sep 17 00:00:00 2001 From: r-downing <26515643+r-downing@users.noreply.github.com> Date: Sun, 19 Nov 2017 19:42:48 -0500 Subject: [PATCH 02/10] added example --- PersWiFiManager.cpp | 2 +- PersWiFiManager.h | 1 - .../data/index.htm | 52 +++++++++ .../spiffs_rest_api_nonblocking/data/wifi.htm | 106 ++++++++++++++++++ .../data/wifi.min.htm | 1 + .../data/wifi.min.htm.gz | Bin 0 -> 1139 bytes .../spiffs_rest_api_nonblocking.ino | 102 +++++++++++++++++ 7 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 examples/spiffs_rest_api_nonblocking/data/index.htm create mode 100644 examples/spiffs_rest_api_nonblocking/data/wifi.htm create mode 100644 examples/spiffs_rest_api_nonblocking/data/wifi.min.htm create mode 100644 examples/spiffs_rest_api_nonblocking/data/wifi.min.htm.gz create mode 100644 examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino diff --git a/PersWiFiManager.cpp b/PersWiFiManager.cpp index f048e5c..b4cdacf 100644 --- a/PersWiFiManager.cpp +++ b/PersWiFiManager.cpp @@ -1,5 +1,5 @@ /* PersWiFiManager - version 2.0.2 - nonblock mod + version 3.0.0 https://r-downing.github.io/PersWiFiManager/ */ diff --git a/PersWiFiManager.h b/PersWiFiManager.h index b85ce93..2f1a264 100644 --- a/PersWiFiManager.h +++ b/PersWiFiManager.h @@ -13,7 +13,6 @@ class PersWiFiManager { typedef std::function WiFiChangeHandlerFunction; - //constructor - takes inputs for ESP8266WebServer and DNSServer, optional ap ssid PersWiFiManager(ESP8266WebServer& s, DNSServer& d); bool attemptConnection(const String& ssid = "", const String& pass = ""); diff --git a/examples/spiffs_rest_api_nonblocking/data/index.htm b/examples/spiffs_rest_api_nonblocking/data/index.htm new file mode 100644 index 0000000..c6f2be1 --- /dev/null +++ b/examples/spiffs_rest_api_nonblocking/data/index.htm @@ -0,0 +1,52 @@ +

Current Data

+x: + +
y: + + +
Last updated + seconds ago. + +
+ +

Update Data

+
+ x: + + +
+
+ y: + + +
+ +WiFi settings + + diff --git a/examples/spiffs_rest_api_nonblocking/data/wifi.htm b/examples/spiffs_rest_api_nonblocking/data/wifi.htm new file mode 100644 index 0000000..c442573 --- /dev/null +++ b/examples/spiffs_rest_api_nonblocking/data/wifi.htm @@ -0,0 +1,106 @@ + + + + + + ESP WiFi + + + + + +
+ +

+
+ +
+ +
+
+ +
+
+
+ +
+ +
+ Back | + Home +
+ + + diff --git a/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm b/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm new file mode 100644 index 0000000..c3d39c3 --- /dev/null +++ b/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm @@ -0,0 +1 @@ +ESP WiFi








Back |Home
\ No newline at end of file diff --git a/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm.gz b/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm.gz new file mode 100644 index 0000000000000000000000000000000000000000..25cc191f7e5f09e25f27d710baaa600c877fbf53 GIT binary patch literal 1139 zcmV-(1dRJ1iwFoJHTzit3wLQ|X)bMPZZ2qaZ2)~$ZIjbB5dJHw7_dDg&dUMQ+E$n= zm-d)}mLWI8b&mU>*y~uJNJf%l(lr0QD?7=BGISFUo{H-EjGlgh2- zEIT}b7qe^)juXY#!01LmTWjMe$+dEz9HXr$T*V65h#ZF9Wk7@yPH;K2IhVjD1JYP9 z-Hk6%pfnxLGAEpb*?jSid=S5hY}DT~n;TKPS=p%E39ZN~6w%IrYm6d=&YLxQjaT62 z68!Pk?dt+H(tUces6#i9(N2^hk}QQ;hc1dpD^#J|Sn8a6Ehf)R=Ar%GNp65UIQT(@ zeY)X>EEu)mE}b)C**KtsOGbHJgDPHCLKbvz&8Scc%=OLNH*|12Xyt<+Oo0kJYPS*T z{iU}|K}&AmzPWa;eh*(7ur7?yjQuFwpp`+Cw({=!p3wzDDxp?!9MkkR)(Tk{TkDW| zUU9VocJ$skCZVf@jXR}3AINZrS+gfu;u&TWe+E2EMx3)>62T zepEDyOKs*nufkK5Aw)X~jyMKK#Q}{5#4l6ggS6qd|pkaG{Nii z#pRfGwLxHPOVXe6qv!|C6)a7F-uC#}`yygHh4lCN4d$&Cr5H(J9UVB+K!kr=Y_^Vm zHabj8X5AKtN2t1SyP6jTHbnBg{+gCJrb8?KhGYWkv>VUlm*MLLQGiOj z44s4^rKqj2X&3d-);xzq>DKT%-9KvO?wsu;evW{9tXo&FY}9X9pZHmZ?N2&63(krl zp>*m0P`sFqvCd~T4-l_QG&v3g?bi;SJ$dwXI$17L;+IA?>eXghO+>-`Qb9uXEW>$T z6I}Y0Mrp0B3kdH9iUp&t8*!~F$Q`P84cA%QpnpXKDj*Wn3f~DAQ-Y*(sI~SJNWGTXw<#D{{`CijSbQV F006-@Ii>&r literal 0 HcmV?d00001 diff --git a/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino b/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino new file mode 100644 index 0000000..8ab46dc --- /dev/null +++ b/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino @@ -0,0 +1,102 @@ +#define DEBUG_SERIAL //uncomment for Serial debugging statements + +#ifdef DEBUG_SERIAL +#define DEBUG_BEGIN Serial.begin(115200) +#define DEBUG_PRINT(x) Serial.println(x) +#else +#define DEBUG_PRINT(x) +#define DEBUG_BEGIN +#endif + +//includes +#include +#include +#include + +#include // http://ryandowning.net/EasySSDP/ + +//extension of ESP8266WebServer with SPIFFS handlers built in +#include // http://ryandowning.net/SPIFFSReadServer/ +// upload data folder to chip with Arduino ESP8266 filesystem uploader +// https://github.com/esp8266/arduino-esp8266fs-plugin + +#include +#include + +#define DEVICE_NAME "ESP8266 DEVICE" + + +//server objects +SPIFFSReadServer server(80); +DNSServer dnsServer; +PersWiFiManager persWM(server, dnsServer); + +////// Sample program data +int x; +String y; + +void setup() { + DEBUG_BEGIN; //for terminal debugging + DEBUG_PRINT(); + + persWM.onConnect([]() { + DEBUG_PRINT("wifi connected"); + DEBUG_PRINT(WiFi.localIP()); + EasySSDP::begin(server); + }); + + persWM.onFail([](){ + DEBUG_PRINT("AP MODE"); + DEBUG_PRINT(persWM.getApSsid()); + }); + + //allows serving of files from SPIFFS + SPIFFS.begin(); + //sets network name for AP mode + persWM.setApCredentials(DEVICE_NAME); + //persWM.setApCredentials(DEVICE_NAME, "password"); optional password + + persWM.setConnectNonBlock(true); + persWM.begin(); + + //handles commands from webpage, sends live data in JSON format + server.on("/api", []() { + DEBUG_PRINT("server.on /api"); + if (server.hasArg("x")) { + x = server.arg("x").toInt(); + DEBUG_PRINT(String("x: ") + x); + } //if + if (server.hasArg("y")) { + y = server.arg("y"); + DEBUG_PRINT("y: " + y); + } //if + + //build json object of program data + StaticJsonBuffer<200> jsonBuffer; + JsonObject &json = jsonBuffer.createObject(); + json["x"] = x; + json["y"] = y; + + char jsonchar[200]; + json.printTo(jsonchar); //print to char array, takes more memory but sends in one piece + server.send(200, "application/json", jsonchar); + + }); //server.on api + + + server.begin(); + DEBUG_PRINT("setup complete."); +} //void setup + +void loop() { + persWM.handleWiFi(); + //Serial.println(millis()); + dnsServer.processNextRequest(); + server.handleClient(); + + DEBUG_PRINT(millis()); + + // do stuff with x and y + +} //void loop + From 724fba32d218f2578f7e0abac9625f0b43062d77 Mon Sep 17 00:00:00 2001 From: Ryan Downing <26515643+r-downing@users.noreply.github.com> Date: Mon, 20 Nov 2017 13:43:32 -0500 Subject: [PATCH 03/10] Add files via upload --- PersWiFiManager.cpp | 23 ++++++++++++++++------- PersWiFiManager.h | 4 +++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/PersWiFiManager.cpp b/PersWiFiManager.cpp index b4cdacf..9ecf167 100644 --- a/PersWiFiManager.cpp +++ b/PersWiFiManager.cpp @@ -26,7 +26,7 @@ bool PersWiFiManager::attemptConnection(const String& ssid, const String& pass) } //if in nonblock mode, skip this loop - _connectStartTime = millis() + 1; + _connectStartTime = millis();// + 1; while (!_connectNonBlock && _connectStartTime) { handleWiFi(); delay(10); @@ -46,18 +46,22 @@ void PersWiFiManager::handleWiFi() { } //if failed or not connected and time is up - if ((WiFi.status() == WL_CONNECT_FAILED) || (WiFi.status() != WL_CONNECTED && (millis() - _connectStartTime) > 1000 * WIFI_CONNECT_TIMEOUT)) { - //start AP mode - IPAddress apIP(192, 168, 1, 1); - WiFi.mode(WIFI_AP); - WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); - _apPass.length() ? WiFi.softAP(getApSsid().c_str(), _apPass.c_str()) : WiFi.softAP(getApSsid().c_str()); + if ((WiFi.status() == WL_CONNECT_FAILED) || ((WiFi.status() != WL_CONNECTED) && ((millis() - _connectStartTime) > (1000 * WIFI_CONNECT_TIMEOUT)))) { + startApMode(); _connectStartTime = 0; //reset connect start time if (_failHandler) _failHandler(); } } //handleWiFi +void PersWiFiManager::startApMode(){ + //start AP mode + IPAddress apIP(192, 168, 1, 1); + WiFi.mode(WIFI_AP); + WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); + _apPass.length() ? WiFi.softAP(getApSsid().c_str(), _apPass.c_str()) : WiFi.softAP(getApSsid().c_str()); +}//startApMode + void PersWiFiManager::setConnectNonBlock(bool b) { _connectNonBlock = b; } //setConnectNonBlock @@ -110,6 +114,11 @@ void PersWiFiManager::setupWiFiHandlers() { attemptConnection(_server->arg("n"), _server->arg("p")); }); //_server->on /wifi/connect + _server->on("/wifi/ap", [&](){ + _server->send(200, "text/html", "access point: "+getApSsid()); + startApMode(); + }); //_server->on /wifi/ap + _server->on("/wifi/rst", [&]() { _server->send(200, "text/html", "Rebooting..."); delay(100); diff --git a/PersWiFiManager.h b/PersWiFiManager.h index 2f1a264..bae8e6c 100644 --- a/PersWiFiManager.h +++ b/PersWiFiManager.h @@ -29,6 +29,8 @@ class PersWiFiManager { void handleWiFi(); + void startApMode(); + void onConnect(WiFiChangeHandlerFunction fn); void onFail(WiFiChangeHandlerFunction fn); @@ -47,4 +49,4 @@ class PersWiFiManager { };//class #endif - + From 527efb87e09a10ce0e9ae968fb260a758350e5f6 Mon Sep 17 00:00:00 2001 From: Ryan Downing <26515643+r-downing@users.noreply.github.com> Date: Tue, 21 Nov 2017 00:37:53 -0500 Subject: [PATCH 04/10] added ap mode button, space in link bar --- data/wifi.htm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/wifi.htm b/data/wifi.htm index c442573..5d08372 100644 --- a/data/wifi.htm +++ b/data/wifi.htm @@ -96,9 +96,11 @@

+ +

- Back | + Back | Home From 3ea7142430952cff6986f6c24ba638ccfef93c45 Mon Sep 17 00:00:00 2001 From: r-downing <26515643+r-downing@users.noreply.github.com> Date: Tue, 28 Nov 2017 21:07:29 -0500 Subject: [PATCH 05/10] updated wifi pages to include ap mode button --- data/wifi.min.htm | 2 +- data/wifi.min.htm.gz | Bin 1139 -> 1159 bytes examples/basic_rest_api/data/wifi.min.htm.gz | Bin 1139 -> 1159 bytes examples/spiffs_rest_api/data/wifi.min.htm.gz | Bin 1139 -> 1159 bytes .../spiffs_rest_api_nonblocking/data/wifi.htm | 4 +++- .../data/wifi.min.htm | 2 +- .../data/wifi.min.htm.gz | Bin 1139 -> 1159 bytes 7 files changed, 5 insertions(+), 3 deletions(-) diff --git a/data/wifi.min.htm b/data/wifi.min.htm index c3d39c3..49a4a55 100644 --- a/data/wifi.min.htm +++ b/data/wifi.min.htm @@ -1 +1 @@ -ESP WiFi








Back |Home
\ No newline at end of file +ESP WiFi









Back | Home
\ No newline at end of file diff --git a/data/wifi.min.htm.gz b/data/wifi.min.htm.gz index 25cc191f7e5f09e25f27d710baaa600c877fbf53..c8b0d2fbde7b60a8324c9c2e79b8a98a8363c2c3 100644 GIT binary patch literal 1159 zcmV;21bF)&iwFp66CPRu3wLQ|X)bMPZZ2qaZ2*NnW<- zQcSYllhI<5Et#W8(j_B!#aW}3aTw)FIwl>#4KG|p3bx`o>$gG=amgL0qHl957#a0Y zZJB8$ItPVRcreKvcY;l(vupH;zvJ1UlQWweuHB@pW$w6=Xc6*gW0xpQ?%MeJG+$=*EMX2GjP)#gUPQ4Wo$1c;*J`Iu^MjhM5 z0fTM2q6Ws6?B8U8{J25@aOvC*OLo)UW~># z0df5LY>3<105G&A>Q4Dy^@HXL<|cq>Tlj2!5uu$z{QL9UvTU)Pe&}~?M@skYNAGLZC z92G&Z(xpG4crqSBosViB0A731Xg?6RTRV92;@QJ^G@qx)FO6)_nN2c{ctQM90YZ9` z!8|V!Ed5G>Rx9fQMB9NP!JzF%SgVrd4$RwzYrSpIy&?h`Ai?AU-U%mT1f+9TDFJ0B z!EAPQ;mMg}KfU+U2fx>^kXvi7g6VFcM}qHh4(bl8{dNg=ZnmB;Ij}qLXg=mS@R>bv zI^2>D1K5bhp-LZAOVgO3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a6Ehf)R=Ar%GNp65UIQT(@ zeY)X>EEu)mE}b)C**KtsOGbHJgDPHCLKbvz&8Scc%=OLNH*|12Xyt<+Oo0kJYPS*T z{iU}|K}&AmzPWa;eh*(7ur7?yjQuFwpp`+Cw({=!p3wzDDxp?!9MkkR)(Tk{TkDW| zUU9VocJ$skCZVf@jXR}3AINZrS+gfu;u&TWe+E2EMx3)>62T zepEDyOKs*nufkK5Aw)X~jyMKK#Q}{5#4l6ggS6qd|pkaG{Nii z#pRfGwLxHPOVXe6qv!|C6)a7F-uC#}`yygHh4lCN4d$&Cr5H(J9UVB+K!kr=Y_^Vm zHabj8X5AKtN2t1SyP6jTHbnBg{+gCJrb8?KhGYWkv>VUlm*MLLQGiOj z44s4^rKqj2X&3d-);xzq>DKT%-9KvO?wsu;evW{9tXo&FY}9X9pZHmZ?N2&63(krl zp>*m0P`sFqvCd~T4-l_QG&v3g?bi;SJ$dwXI$17L;+IA?>eXghO+>-`Qb9uXEW>$T z6I}Y0Mrp0B3kdH9iUp&t8*!~F$Q`P84cA%QpnpXKDj*Wn3f~DAQ-Y*(sI~SJNWGTXw<#D{{`CijSbQV F006-@Ii>&r diff --git a/examples/spiffs_rest_api/data/wifi.min.htm.gz b/examples/spiffs_rest_api/data/wifi.min.htm.gz index 25cc191f7e5f09e25f27d710baaa600c877fbf53..c8b0d2fbde7b60a8324c9c2e79b8a98a8363c2c3 100644 GIT binary patch literal 1159 zcmV;21bF)&iwFp66CPRu3wLQ|X)bMPZZ2qaZ2*NnW<- zQcSYllhI<5Et#W8(j_B!#aW}3aTw)FIwl>#4KG|p3bx`o>$gG=amgL0qHl957#a0Y zZJB8$ItPVRcreKvcY;l(vupH;zvJ1UlQWweuHB@pW$w6=Xc6*gW0xpQ?%MeJG+$=*EMX2GjP)#gUPQ4Wo$1c;*J`Iu^MjhM5 z0fTM2q6Ws6?B8U8{J25@aOvC*OLo)UW~># z0df5LY>3<105G&A>Q4Dy^@HXL<|cq>Tlj2!5uu$z{QL9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3d-);xzq>DKT%-9KvO?wsu;evW{9tXo&FY}9X9pZHmZ?N2&63(krl zp>*m0P`sFqvCd~T4-l_QG&v3g?bi;SJ$dwXI$17L;+IA?>eXghO+>-`Qb9uXEW>$T z6I}Y0Mrp0B3kdH9iUp&t8*!~F$Q`P84cA%QpnpXKDj*Wn3f~DAQ-Y*(sI~SJNWGTXw<#D{{`CijSbQV F006-@Ii>&r diff --git a/examples/spiffs_rest_api_nonblocking/data/wifi.htm b/examples/spiffs_rest_api_nonblocking/data/wifi.htm index c442573..5d08372 100644 --- a/examples/spiffs_rest_api_nonblocking/data/wifi.htm +++ b/examples/spiffs_rest_api_nonblocking/data/wifi.htm @@ -96,9 +96,11 @@

+ +

- Back | + Back | Home diff --git a/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm b/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm index c3d39c3..49a4a55 100644 --- a/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm +++ b/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm @@ -1 +1 @@ -ESP WiFi








Back |Home
\ No newline at end of file +ESP WiFi









Back | Home
\ No newline at end of file diff --git a/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm.gz b/examples/spiffs_rest_api_nonblocking/data/wifi.min.htm.gz index 25cc191f7e5f09e25f27d710baaa600c877fbf53..c8b0d2fbde7b60a8324c9c2e79b8a98a8363c2c3 100644 GIT binary patch literal 1159 zcmV;21bF)&iwFp66CPRu3wLQ|X)bMPZZ2qaZ2*NnW<- zQcSYllhI<5Et#W8(j_B!#aW}3aTw)FIwl>#4KG|p3bx`o>$gG=amgL0qHl957#a0Y zZJB8$ItPVRcreKvcY;l(vupH;zvJ1UlQWweuHB@pW$w6=Xc6*gW0xpQ?%MeJG+$=*EMX2GjP)#gUPQ4Wo$1c;*J`Iu^MjhM5 z0fTM2q6Ws6?B8U8{J25@aOvC*OLo)UW~># z0df5LY>3<105G&A>Q4Dy^@HXL<|cq>Tlj2!5uu$z{Q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X&3d-);xzq>DKT%-9KvO?wsu;evW{9tXo&FY}9X9pZHmZ?N2&63(krl zp>*m0P`sFqvCd~T4-l_QG&v3g?bi;SJ$dwXI$17L;+IA?>eXghO+>-`Qb9uXEW>$T z6I}Y0Mrp0B3kdH9iUp&t8*!~F$Q`P84cA%QpnpXKDj*Wn3f~DAQ-Y*(sI~SJNWGTXw<#D{{`CijSbQV F006-@Ii>&r From ff51cd7668a2af0025676aa088e3ad0504a9735e Mon Sep 17 00:00:00 2001 From: r-downing <26515643+r-downing@users.noreply.github.com> Date: Tue, 28 Nov 2017 21:19:19 -0500 Subject: [PATCH 06/10] changed fail to AP --- PersWiFiManager.cpp | 6 +++--- PersWiFiManager.h | 4 ++-- .../spiffs_rest_api_nonblocking.ino | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/PersWiFiManager.cpp b/PersWiFiManager.cpp index 9ecf167..d4898b6 100644 --- a/PersWiFiManager.cpp +++ b/PersWiFiManager.cpp @@ -49,7 +49,6 @@ void PersWiFiManager::handleWiFi() { if ((WiFi.status() == WL_CONNECT_FAILED) || ((WiFi.status() != WL_CONNECTED) && ((millis() - _connectStartTime) > (1000 * WIFI_CONNECT_TIMEOUT)))) { startApMode(); _connectStartTime = 0; //reset connect start time - if (_failHandler) _failHandler(); } } //handleWiFi @@ -60,6 +59,7 @@ void PersWiFiManager::startApMode(){ WiFi.mode(WIFI_AP); WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); _apPass.length() ? WiFi.softAP(getApSsid().c_str(), _apPass.c_str()) : WiFi.softAP(getApSsid().c_str()); + if (_apHandler) _apHandler(); }//startApMode void PersWiFiManager::setConnectNonBlock(bool b) { @@ -151,8 +151,8 @@ void PersWiFiManager::onConnect(WiFiChangeHandlerFunction fn) { _connectHandler = fn; } -void PersWiFiManager::onFail(WiFiChangeHandlerFunction fn) { - _failHandler = fn; +void PersWiFiManager::onAp(WiFiChangeHandlerFunction fn) { + _apHandler = fn; } diff --git a/PersWiFiManager.h b/PersWiFiManager.h index bae8e6c..80fcf03 100644 --- a/PersWiFiManager.h +++ b/PersWiFiManager.h @@ -33,7 +33,7 @@ class PersWiFiManager { void onConnect(WiFiChangeHandlerFunction fn); - void onFail(WiFiChangeHandlerFunction fn); + void onAp(WiFiChangeHandlerFunction fn); private: ESP8266WebServer * _server; @@ -44,7 +44,7 @@ class PersWiFiManager { unsigned long _connectStartTime; WiFiChangeHandlerFunction _connectHandler; - WiFiChangeHandlerFunction _failHandler; + WiFiChangeHandlerFunction _apHandler; };//class diff --git a/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino b/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino index 8ab46dc..8989821 100644 --- a/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino +++ b/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino @@ -45,7 +45,7 @@ void setup() { EasySSDP::begin(server); }); - persWM.onFail([](){ + persWM.onAp([](){ DEBUG_PRINT("AP MODE"); DEBUG_PRINT(persWM.getApSsid()); }); @@ -90,11 +90,10 @@ void setup() { void loop() { persWM.handleWiFi(); - //Serial.println(millis()); dnsServer.processNextRequest(); server.handleClient(); - DEBUG_PRINT(millis()); + //DEBUG_PRINT(millis()); // do stuff with x and y From c52df5c2525738251f619b21000045d7786a49b3 Mon Sep 17 00:00:00 2001 From: r-downing <26515643+r-downing@users.noreply.github.com> Date: Tue, 28 Nov 2017 21:28:13 -0500 Subject: [PATCH 07/10] added more comments --- .../spiffs_rest_api_nonblocking.ino | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino b/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino index 8989821..18e1faf 100644 --- a/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino +++ b/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino @@ -1,3 +1,7 @@ +/* +SPIFFS-served REST API example for PersWiFiManager v3.0 +*/ + #define DEBUG_SERIAL //uncomment for Serial debugging statements #ifdef DEBUG_SERIAL @@ -39,12 +43,13 @@ void setup() { DEBUG_BEGIN; //for terminal debugging DEBUG_PRINT(); + //optional code handlers to run everytime wifi is connected... persWM.onConnect([]() { DEBUG_PRINT("wifi connected"); DEBUG_PRINT(WiFi.localIP()); EasySSDP::begin(server); }); - + //...or AP mode is started persWM.onAp([](){ DEBUG_PRINT("AP MODE"); DEBUG_PRINT(persWM.getApSsid()); @@ -89,7 +94,9 @@ void setup() { } //void setup void loop() { + //in non-blocking mode, handleWiFi must be called in the main loop persWM.handleWiFi(); + dnsServer.processNextRequest(); server.handleClient(); From bbc89ed2382c5c31256a40cb388e7e5a64dd39c7 Mon Sep 17 00:00:00 2001 From: r-downing <26515643+r-downing@users.noreply.github.com> Date: Tue, 28 Nov 2017 21:30:19 -0500 Subject: [PATCH 08/10] more comments --- .../spiffs_rest_api_nonblocking.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino b/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino index 18e1faf..bab08e5 100644 --- a/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino +++ b/examples/spiffs_rest_api_nonblocking/spiffs_rest_api_nonblocking.ino @@ -61,7 +61,10 @@ void setup() { persWM.setApCredentials(DEVICE_NAME); //persWM.setApCredentials(DEVICE_NAME, "password"); optional password + //make connecting/disconnecting non-blocking persWM.setConnectNonBlock(true); + + //in non-blocking mode, program will continue past this point without waiting persWM.begin(); //handles commands from webpage, sends live data in JSON format From 1210c84a5e9e45b35ef4097ece8595b0963d896f Mon Sep 17 00:00:00 2001 From: r-downing <26515643+r-downing@users.noreply.github.com> Date: Tue, 28 Nov 2017 21:32:17 -0500 Subject: [PATCH 09/10] update version # --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 9437d6f..81dce8b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PersWiFiManager -version=2.0.2 +version=3.0.0 author=Ryan Downing maintainer=Ryan Downing sentence=Persistent WiFi Manager From 6f3054973b8e4675f9f2bc96e5614b253071d787 Mon Sep 17 00:00:00 2001 From: r-downing <26515643+r-downing@users.noreply.github.com> Date: Tue, 28 Nov 2017 21:34:04 -0500 Subject: [PATCH 10/10] updated website url --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 81dce8b..3b29653 100644 --- a/library.properties +++ b/library.properties @@ -5,5 +5,5 @@ maintainer=Ryan Downing sentence=Persistent WiFi Manager paragraph=A non-blocking, persistant wifi manager for ESP8266 that allows network changes at any time category=Communication -url=https://r-downing.github.io/PersWiFiManager/ +url=https://ryandowning.net/PersWiFiManager/ architectures=esp8266