Răsfoiți Sursa

Merge pull request #1 from alanswx/master

update
Debashish Sahu 6 ani în urmă
părinte
comite
27cc54a36c
5 a modificat fișierele cu 75 adăugiri și 128 ștergeri
  1. 50 7
      ESPAsyncWiFiManager.cpp
  2. 7 3
      ESPAsyncWiFiManager.h
  3. 16 116
      README.md
  4. 1 1
      library.json
  5. 1 1
      library.properties

+ 50 - 7
ESPAsyncWiFiManager.cpp

@@ -508,8 +508,8 @@ int AsyncWiFiManager::connectWifi(String ssid, String pass) {
 
   // check if we've got static_ip settings, if we do, use those.
   if (_sta_static_ip) {
-    DEBUG_WM(F("Custom STA IP/GW/Subnet"));
-    WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
+    DEBUG_WM(F("Custom STA IP/GW/Subnet/DNS"));
+    WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn, _sta_static_dns1, _sta_static_dns2);
     DEBUG_WM(WiFi.localIP());
   }
   //fix for auto connect racing issue
@@ -543,7 +543,8 @@ int AsyncWiFiManager::connectWifi(String ssid, String pass) {
 
       WiFi.begin();
     } else {
-      DEBUG_WM("No saved credentials");
+      DEBUG_WM("Try to connect with saved credentials");
+      WiFi.begin();
     }
   }
 
@@ -551,12 +552,13 @@ int AsyncWiFiManager::connectWifi(String ssid, String pass) {
   DEBUG_WM ("Connection result: ");
   DEBUG_WM ( connRes );
   //not connected, WPS enabled, no pass - first attempt
+#ifdef NO_EXTRA_4K_HEAP	
   if (_tryWPS && connRes != WL_CONNECTED && pass == "") {
     startWPS();
     //should be connected at the end of WPS
     connRes = waitForConnectResult();
   }
-
+#endif
   needInfo = true;
   setInfo();
   return connRes;
@@ -584,19 +586,28 @@ uint8_t AsyncWiFiManager::waitForConnectResult() {
     return status;
   }
 }
-
+#ifdef NO_EXTRA_4K_HEAP
 void AsyncWiFiManager::startWPS() {
   DEBUG_WM("START WPS");
 #if defined(ESP8266)
   WiFi.beginWPSConfig();
 #else
-  esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
+  //esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
+  esp_wps_config_t config = {};
+  config.wps_type = ESP_WPS_MODE;
+  config.crypto_funcs = &g_wifi_default_wps_crypto_funcs;
+  strcpy(config.factory_info.manufacturer,"ESPRESSIF");  
+  strcpy(config.factory_info.model_number, "ESP32");  
+  strcpy(config.factory_info.model_name, "ESPRESSIF IOT");  
+  strcpy(config.factory_info.device_name,"ESP STATION");  
+
   esp_wifi_wps_enable(&config);
   esp_wifi_wps_start(0);
 #endif
   DEBUG_WM("END WPS");
 
 }
+#endif
 /*
 String AsyncWiFiManager::getSSID() {
 if (_ssid == "") {
@@ -650,10 +661,12 @@ void AsyncWiFiManager::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress
   _ap_static_sn = sn;
 }
 
-void AsyncWiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) {
+void AsyncWiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns1, IPAddress dns2) {
   _sta_static_ip = ip;
   _sta_static_gw = gw;
   _sta_static_sn = sn;
+  _sta_static_dns1 = dns1;
+  _sta_static_dns2 = dns2;
 }
 
 void AsyncWiFiManager::setMinimumSignalQuality(int quality) {
@@ -782,6 +795,24 @@ void AsyncWiFiManager::handleWifi(AsyncWebServerRequest *request,boolean scan) {
 
     page += item;
 
+    item = FPSTR(HTTP_FORM_PARAM);
+    item.replace("{i}", "dns1");
+    item.replace("{n}", "dns1");
+    item.replace("{p}", "DNS1");
+    item.replace("{l}", "15");
+    item.replace("{v}", _sta_static_dns1.toString());
+
+    page += item;
+
+    item = FPSTR(HTTP_FORM_PARAM);
+    item.replace("{i}", "dns2");
+    item.replace("{n}", "dns2");
+    item.replace("{p}", "DNS2");
+    item.replace("{l}", "15");
+    item.replace("{v}", _sta_static_dns2.toString());
+
+    page += item;
+
     page += "<br/>";
   }
 
@@ -838,6 +869,18 @@ void AsyncWiFiManager::handleWifiSave(AsyncWebServerRequest *request) {
     String sn = request->arg("sn");
     optionalIPFromString(&_sta_static_sn, sn.c_str());
   }
+  if (request->hasArg("dns1")) {
+    DEBUG_WM(F("static DNS 1"));
+    DEBUG_WM(request->arg("dns1"));
+    String dns1 = request->arg("dns1");
+    optionalIPFromString(&_sta_static_dns1, dns1.c_str());
+  }
+  if (request->hasArg("dns2")) {
+    DEBUG_WM(F("static DNS 2"));
+    DEBUG_WM(request->arg("dns2"));
+    String dns2 = request->arg("dns2");
+    optionalIPFromString(&_sta_static_dns2, dns2.c_str());
+  }
 
   String page = FPSTR(WFM_HTTP_HEAD);
   page.replace("{v}", "Credentials Saved");

+ 7 - 3
ESPAsyncWiFiManager.h

@@ -141,7 +141,7 @@ public:
   //sets a custom ip /gateway /subnet configuration
   void          setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
   //sets config for a static IP
-  void          setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
+  void          setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns1=(uint32_t)0x00000000, IPAddress dns2=(uint32_t)0x00000000);
   //called when AP mode and config portal is started
   void          setAPCallback( void (*func)(AsyncWiFiManager*) );
   //called when settings have been changed and connection was successful
@@ -177,8 +177,9 @@ private:
   //const String  HTTP_HEAD = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>{v}</title>";
 
   void          setupConfigPortal();
+#ifdef NO_EXTRA_4K_HEAP
   void          startWPS();
-
+#endif
   String        pager;
   wl_status_t   wifiStatus;
   const char*   _apName                 = "no-net";
@@ -195,13 +196,16 @@ private:
   IPAddress     _sta_static_ip;
   IPAddress     _sta_static_gw;
   IPAddress     _sta_static_sn;
+  IPAddress     _sta_static_dns1= (uint32_t)0x00000000;
+  IPAddress     _sta_static_dns2= (uint32_t)0x00000000;
 
   int           _paramsCount            = 0;
   int           _minimumQuality         = -1;
   boolean       _removeDuplicateAPs     = true;
   boolean       _shouldBreakAfterConfig = false;
+#ifdef NO_EXTRA_4K_HEAP
   boolean       _tryWPS                 = false;
-
+#endif
   const char*   _customHeadElement      = "";
 
   //String        getEEPROMString(int start, int len);

+ 16 - 116
README.md

@@ -76,21 +76,27 @@ __Github version works with release 2.0.0 or newer of the [ESP8266 core for Ardu
 ### Using
 - Include in your sketch
 ```cpp
-#include <ESP8266WiFi.h>          //ESP8266 Core WiFi Library (you most likely already have this in your sketch)
-
-#include <DNSServer.h>            //Local DNS Server used for redirecting all requests to the configuration portal
-#include <ESP8266WebServer.h>     //Local WebServer used to serve the configuration portal
-#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
+#if defined(ESP8266)
+#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
+#else
+#include <WiFi.h>
+#endif
+
+#include <ESPAsyncWebServer.h>     //Local WebServer used to serve the configuration portal
+#include <ESPAsyncWiFiManager.h>          //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
 ```
 
 - Initialize library, in your setup function add
 ```cpp
-WiFiManager wifiManager;
+AsyncWebServer server(80);
+DNSServer dns;
 ```
 
 - Also in the setup function add
 ```cpp
 //first parameter is name of access point, second is the password
+AsyncWiFiManager wifiManager(&server,&dns);
+
 wifiManager.autoConnect("AP-NAME", "AP-PASSWORD");
 ```
 if you just want an unsecured access point
@@ -105,7 +111,7 @@ wifiManager.autoConnect();
 After you write your sketch and start the ESP, it will try to connect to WiFi. If it fails it starts in Access Point mode.
 While in AP mode, connect to it then open a browser to the gateway IP, default 192.168.4.1, configure wifi, save and it should reboot and connect.
 
-Also see [examples](https://github.com/tzapu/WiFiManager/tree/master/examples).
+Also see [examples](https://github.com/alanswx/ESPAsyncWiFiManager/tree/master/examples).
 
 ## Documentation
 
@@ -137,7 +143,7 @@ void configModeCallback (WiFiManager *myWiFiManager) {
 ##### Save settings
 This gets called when custom parameters have been set **AND** a connection has been established. Use it to set a flag, so when all the configuration finishes, you can save the extra parameters somewhere.
 
-See [AutoConnectWithFSParameters Example](https://github.com/tzapu/WiFiManager/tree/master/examples/AutoConnectWithFSParameters).
+See [AutoConnectWithFSParameters Example](https://github.com/alanswx/ESPAsyncWiFiManager/tree/master/examples/AutoConnectWithFSParameters).
 ```cpp
 wifiManager.setSaveConfigCallback(saveConfigCallback);
 ```
@@ -177,7 +183,7 @@ void loop() {
   }
 }
 ```
-See example for a more complex version. [OnDemandConfigPortal](https://github.com/tzapu/WiFiManager/tree/master/examples/OnDemandConfigPortal)
+See example for a more complex version. [OnDemandConfigPortal](https://github.com/alanswx/ESPAsyncWiFiManager/tree/master/examples/OnDemandConfigPortal)
 
 #### Custom Parameters
 You can use WiFiManager to collect more parameters than just SSID and password.
@@ -201,7 +207,7 @@ Usage scenario would be:
 This feature is a lot more involved than all the others, so here are some examples to fully show how it is done.
 You should also take a look at adding custom HTML to your form.
 
-- Save and load custom parameters to file system in json form [AutoConnectWithFSParameters](https://github.com/tzapu/WiFiManager/tree/master/examples/AutoConnectWithFSParameters)
+- Save and load custom parameters to file system in json form [AutoConnectWithFSParameters](https://github.com/alanswx/ESPAsyncWiFiManager/tree/master/examples/AutoConnectWithFSParameters)
 - *Save and load custom parameters to EEPROM* (not done yet)
 
 #### Custom IP Configuration
@@ -261,110 +267,4 @@ Debug is enabled by default on Serial. To disable add before autoConnect
 wifiManager.setDebugOutput(false);
 ```
 
-## Troubleshooting
-If you get compilation errors, more often than not, you may need to install a newer version of the ESP8266 core for Arduino.
-
-Changes added on 0.8 should make the latest trunk work without compilation errors. Tested down to ESP8266 core 2.0.0. **Please update to version 0.8**
-
-I am trying to keep releases working with release versions of the core, so they can be installed through boards manager, but if you checkout the latest version directly from github, sometimes, the library will only work if you update the ESP8266 core to the latest version because I am using some newly added function.
-
-If you connect to the created configuration Access Point but the configuration portal does not show up, just open a browser and type in the IP of the web portal, by default `192.168.4.1`.
-
-If trying to connect ends up in an endless loop, try to add `setConnectTimeout(60)` before `autoConnect();`. The parameter is timeout to try connecting in seconds.
-
-## Releases
-#### 0.12
-- removed 204 header response
-- fixed incompatibility with other libs using isnan and other std:: functions without namespace
-
-##### 0.11
-- a lot more reliable reconnecting to networks
-- custom html in custom parameters (for read only params)
-- custom html in custom parameter form (like labels)
-- custom head element (like custom css)
-- sort networks based on signal quality
-- remove duplicate networks
-
-##### 0.10
-- some css changes
-- bug fixes and speed improvements
-- added an alternative to waitForConnectResult() for debugging
-- changed `setTimeout(seconds)` to `setConfigPortalTimeout(seconds)`
-
-##### 0.9
- - fixed support for encoded characters in ssid/pass
-
-##### 0.8
- - made it compile on older versions of ESP8266 core as well, tested down to 2.0.0
- - added simple example for Custom IP
-
-##### 0.7
- - added static IP in station mode
- - added example of persisting custom IP to FS config.json
- - more option on portal homepage
- - added on PlatformIO
-
-##### 0.6
- - custom parameters
- - prettier
- - on demand config portal
- - commit #100 :D
-
-##### 0.5
- - Added to Arduino Boards Manager - Thanks Max
- - moved most stuff to PROGMEM
- - added signal quality and a nice little padlock to show which networks are encrypted
-
-##### v0.4 - all of it user contributed changes - Thank you
- - added ability to password protect the configuration Access Point
- - callback for enter configuration mode
- - memory allocation improvements
-
-##### v0.3
- - removed the need for EEPROM and works with the 2.0.0 and above stable release of the ESP8266 for Arduino IDE package
- - removed restart on save of credentials
- - updated examples
-
-##### v0.2
-needs the latest staging version (or at least a recent release of the staging version) to work
-
-##### v0.1
-works with the staging release ver. 1.6.5-1044-g170995a, built on Aug 10, 2015 of the ESP8266 Arduino library.
-
-
-### Contributions and thanks
-The support and help I got from the community has been nothing short of phenomenal. I can't thank you guys enough. This is my first real attept in developing open source stuff and I must say, now I understand why people are so dedicated to it, it is because of all the wonderful people involved.
-
-__THANK YOU__
-[tzapu](https://github.com/tzapu/)
-
-[Shawn A](https://github.com/tablatronix)
-
-[Maximiliano Duarte](https://github.com/domonetic)
-
-[alltheblinkythings](https://github.com/alltheblinkythings)
-
-[Niklas Wall](https://github.com/niklaswall)
-
-[Jakub Piasecki](https://github.com/zaporylie)
-
-[Peter Allan](https://github.com/alwynallan)
-
-[John Little](https://github.com/j0hnlittle)
-
-[markaswift](https://github.com/markaswift)
-
-[franklinvv](https://github.com/franklinvv)
-
-[Alberto Ricci Bitti](https://github.com/riccibitti)
-
-[SebiPanther](https://github.com/SebiPanther)
-
-[jonathanendersby](https://github.com/jonathanendersby)
-
-[walthercarsten](https://github.com/walthercarsten)
-
-Sorry if i have missed anyone.
 
-#### Inspiration
-- http://www.esp8266.com/viewtopic.php?f=29&t=2520

+ 1 - 1
library.json

@@ -9,5 +9,5 @@
   },
   "frameworks": "arduino",
   "platforms": ["espressif8266", "espressif32"],
-  "version": "0.15"
+  "version": "0.18"
 }

+ 1 - 1
library.properties

@@ -1,5 +1,5 @@
 name=ESP Async WiFi Manager
-version=0.15
+version=0.18
 author=alanswx
 maintainer=alanswx
 sentence=ESP8266 and ESP32 Async WiFi Connection manager with fallback web configuration portal