wifimanager
for PlatformIO, add this:
tzapu/WiFiManager @ ^2.0.17
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
WiFiManager wm;
int resetpin=D8;
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
Serial.begin(115200);
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");
} else { Serial.println("connected...yeey :)");
}
pinMode(resetpin, INPUT);
}
void loop() {
if (digitalRead(resetpin)) {
wm.resetSettings();
ESP.restart();
}
delay(1000);
}
BELOW TESTED ON ESP8266:
Short resetwifiPIN with GND to reset wifi credential. LED will remain ON until connection successful
for PlatformIO, add this:
tzapu/WiFiManager @ ^2.0.17
In header before void setup():
#include <WiFiManager.h>
WiFiManager wifiManager;
int resetwifipin=D3; // change this to the PIN for reset
void turnonLED(bool onOff){
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, onOff ? LOW : HIGH); // Inverted for ESP8266
}
Inside void setup():
turnonLED(true);
bool res;
res = wifiManager.autoConnect("AP-NAME", "1234567890");
if(!res) { Serial.println("Failed to connect");
} else { Serial.println("connected...yeey :)");
}
turnonLED(false);
pinMode(resetwifipin, INPUT_PULLUP);
Inside void loop():
if (!digitalRead(resetwifipin)) {
wifiManager.resetSettings();
ESP.restart();
}
Other Tricks: wm.setClass(“invert”); wm.startConfigPortal(“OnDemandAP”)); wm.startWebPortal();
Below is sample of WiFiManager with reconfiguration of WiFi credential when button pressed Note that there is wm for global wifimanager, and there is wifimanager for the local (within loop) to handle the captiveportal
#include <Arduino.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#define TRIGGER_PIN D7
WiFiManager wm;
void setup() {
//WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
Serial.begin(115200);
Serial.println("\n Starting");
wm.autoConnect("SSID","test");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
}
void loop() {
if (!digitalRead(TRIGGER_PIN)){
WiFiManager wifiManager;
wifiManager.startConfigPortal("OnDemandAP");
Serial.println("connected...yeey :)");
}
}
wifimanager.txt · Last modified: by jwan
