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
#include <WiFiManager.h> #define TRIGGER\_PIN 2 int timeout = 120; // seconds to run for
void setup() { if (!LittleFS.begin()) { //to start littlefs Serial.println("LittleFS mount failed"); return; } data = readFile(LittleFS, "/data.txt").toInt(); WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP // put your setup code here, to run once: pinMode(TRIGGER_PIN, INPUT_PULLUP); WiFiManager wm; //wm.resetSettings(); bool res; res = wm.autoConnect("Setup"); if(!res) { Serial.println("Failed to connect"); // ESP.restart(); }
}
void loop() { if ( digitalRead(TRIGGER_PIN) == LOW) { WiFiManager wm; //wm.resetSettings(); wm.setConfigPortalTimeout(timeout); if (!wm.startConfigPortal("Sharmander")) { Serial.println("failed to connect and hit timeout"); delay(3000); ESP.restart(); delay(5000); } Serial.println("connected...yeey :)"); } }