mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
47 lines
1.7 KiB
Arduino
47 lines
1.7 KiB
Arduino
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
|
|
|
// wifimanager can run in a blocking mode or a non blocking mode
|
|
// Be sure to know how to process loops with no delay() if using non blocking
|
|
bool wm_nonblocking = false;
|
|
|
|
void setup() {
|
|
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
|
|
// it is a good practice to make sure your code sets wifi mode how you want it.
|
|
|
|
// put your setup code here, to run once:
|
|
Serial.begin(115200);
|
|
|
|
//WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
|
|
WiFiManager wm;
|
|
if(wm_nonblocking) wm.setConfigPortalBlocking(false);
|
|
|
|
// reset settings - wipe stored credentials for testing
|
|
// these are stored by the esp library
|
|
//wm.resetSettings();
|
|
|
|
// Automatically connect using saved credentials,
|
|
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
|
|
// if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
|
|
// then goes into a blocking loop awaiting configuration and will return success result
|
|
|
|
bool res;
|
|
// res = wm.autoConnect(); // auto generated AP name from chipid
|
|
// res = wm.autoConnect("AutoConnectAP"); // anonymous ap
|
|
res = wm.autoConnect("AutoConnectAP","password"); // password protected ap
|
|
|
|
if(!res) {
|
|
Serial.println("Failed to connect");
|
|
// ESP.restart();
|
|
}
|
|
else {
|
|
//if you get here you have connected to the WiFi
|
|
Serial.println("connected...yeey :)");
|
|
}
|
|
|
|
}
|
|
|
|
void loop() {
|
|
if(wm_nonblocking) wm.process(); // avoid delays() in loop when non-blocking and other long running code
|
|
// put your main code here, to run repeatedly:
|
|
}
|