Skip to content

Instantly share code, notes, and snippets.

@tzapu
Created February 23, 2016 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzapu/5b13866aaa584b32074a to your computer and use it in GitHub Desktop.
Save tzapu/5b13866aaa584b32074a to your computer and use it in GitHub Desktop.
#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