Skip to content

Instantly share code, notes, and snippets.

@tzapu tzapu/TestWiFiBegin
Created Feb 23, 2016

Embed
What would you like to do?
#include <ESP8266WiFi.h>
//this sketch duplicated the flow that WiFIManager or any other connection manager would take
//first try to connect, if it fails spin up an AP, get some credentials from user, connect again
//then spin everything down
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.println("Start");
WiFi.mode(WIFI_STA);
WiFi.begin("wrongssid","wrongpass");
Serial.println(WiFi.waitForConnectResult());
WiFi.mode(WIFI_AP);
WiFi.softAP("APName");
delay(2000);
//change details below to your router
WiFi.begin("correctssid","correctpass");
Serial.println(WiFi.waitForConnectResult());
WiFi.mode(WIFI_STA);
if(WiFi.status() == WL_CONNECTED) {
Serial.println("Connected");
} else {
Serial.println("Not Connected");
}
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.