diff --git a/WiFiManager.h b/WiFiManager.h index 9013b53..6779dcb 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -169,7 +169,7 @@ class WiFiManager void setSaveConnectTimeout(unsigned long seconds); // toggle debug output void setDebugOutput(boolean debug); - //defaults to not showing anything under 8% signal quality if called + //set min quality percentage to include in scan, defaults to 8% if not specified void setMinimumSignalQuality(int quality = 8); //sets a custom ip /gateway /subnet configuration void setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn); diff --git a/examples/Advanced/Advanced.ino b/examples/Advanced/Advanced.ino new file mode 100644 index 0000000..a864dda --- /dev/null +++ b/examples/Advanced/Advanced.ino @@ -0,0 +1,90 @@ +/** + * WiFiManager advanced demo, contains advanced configurartion options + * Implements TRIGGEN_PIN button press, press for ondemand configportal, hold for 3 seconds for reset settings. + */ +#include // https://github.com/tzapu/WiFiManager + +#define TRIGGER_PIN 0 + +WiFiManager wm; + +void setup() { + Serial.begin(115200); + Serial.setDebugOutput(true); + delay(3000); + Serial.println("\n Starting"); + + pinMode(TRIGGER_PIN, INPUT); + + // wm.resetSettings(); // wipe settings + + // add a custom input field + int customFieldLength = 40; + WiFiManagerParameter custom_field("customfield", "Custom Field", "Default Value", customFieldLength); + wm.addParameter(&custom_field); + + // custom menu via array or vector + // menu tokens, "wifi","wifinoscan","info","param","close","sep","erase","restart","exit" + // const char* menu[] = {"wifi","info","param","sep","restart","exit"}; + // wm.setMenu(menu,6); + std::vector menu = {"wifi","info","param","sep","restart","exit"}; + wm.setMenu(menu); + + //set static ip + // wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // set static ip,gw,sn + // wm.setShowStaticFields(true); // force show static ip fields + // wm.setShowDnsFields(true); // force show dns field always + + // wm.setConnectTimeout(20); // how long to try to connect for before continuing + // wm.setConfigPortalTimeout(60); // auto close configportal after n seconds + // wifiManager.setCaptivePortalEnable(false); // disable captive portal redirection + + // wifi scan settings + // wm.setRemoveDuplicateAPs(false); // do not remove duplicate ap names (true) + // wm.setMinimumSignalQuality(20); // set min RSSI to show in scans, null = 8% + // wm.setShowInfoErase(false); // do not show erase button on info page + // wm.setScanDispPerc(true); // show RSSI as percentage not graph icons + + bool res; + // res = wm.autoConnect(); // auto generated AP name from chipid + // res = wm.autoConnect("AutoConnectAP"); // anonymous ap + res = wm.autoConnect("AutoConnectAP"); // password protected ap + + if(!res) { + Serial.println("Failed to connect or hit timeout"); + } + else { + //if you get here you have connected to the WiFi + Serial.println("connected...yeey :)"); + } +} + + +void loop() { + // check for button press + if ( digitalRead(TRIGGER_PIN) == LOW ) { + // poor mans debounce, not recommended for production code + delay(50); + if( digitalRead(TRIGGER_PIN) == LOW ){ + + delay(3000); // reset timer + if( digitalRead(TRIGGER_PIN) == LOW ){ + // holding button 3000 ms, reset settings + wm.resetSettings(); + ESP.restart(); + } + + wm.setConfigPortalTimeout(120); + + if (!wm.startConfigPortal("OnDemandAP")) { + Serial.println("failed to connect or hit timeout"); + delay(3000); + } else { + //if you get here you have connected to the WiFi + Serial.println("connected...yeey :)"); + } + } + } + + // put your main code here, to run repeatedly: +}