Last active
January 24, 2019 19:20
-
-
Save rodvan/e55a869d45f8c624a794e09b81ab92a5 to your computer and use it in GitHub Desktop.
SmartConfig ESP8266 save Wifi configuration on Pin0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <WiFiUdp.h> | |
void setup() { | |
int cnt = 0; | |
WiFi.mode(WIFI_STA); | |
Serial.begin(9600); | |
pinMode(0, INPUT_PULLUP); | |
Serial.println("2 sec before clear SmartConfig"); | |
delay(2000); | |
int isSmartConfig = digitalRead(0); | |
if (isSmartConfig==0) { | |
Serial.println("clear config"); | |
WiFi.disconnect(); | |
} | |
// if wifi cannot connect start smartconfig | |
while(WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
if(cnt++ >= 15){ | |
WiFi.beginSmartConfig(); | |
while(1){ | |
delay(500); | |
if(WiFi.smartConfigDone()){ | |
Serial.println("SmartConfig Success"); | |
break; | |
} | |
} | |
} | |
} | |
Serial.println(""); | |
WiFi.printDiag(Serial); | |
// Print the IP address | |
Serial.println(WiFi.localIP()); | |
Serial.println(WiFi.macAddress()); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment