Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SmartConfig ESP8266 save Wifi configuration on Pin0
#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
You can’t perform that action at this time.