Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
esp8266-smart-config
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
void setup() {
int cnt = 0;
// set for STA mode
WiFi.mode(WIFI_STA);
// put your setup code here, to run once:
Serial.begin(9600);
// led status at pin16
pinMode(16,OUTPUT);
//configure pin0
pinMode(0, INPUT_PULLUP);
// deplay for 2 sec for smartConfig
Serial.println("2 sec before clear SmartConfig");
delay(2000);
// read pullup
int isSmartConfig = digitalRead(0);
if (isSmartConfig==0) {
// bink for clear config
blinkClearConfig();
Serial.println("clear config");
// reset default 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");
blinkSmartConfig();
break;
}
}
}
}
Serial.println("");
Serial.println("");
WiFi.printDiag(Serial);
// Print the IP address
Serial.println(WiFi.localIP());
}
void blinkSmartConfig() {
digitalWrite(16, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(16, LOW); // turn the LED off by making the voltage LOW
delay(50);
}
void blinkClearConfig() {
int i=0;
while(i<=3) {
digitalWrite(16, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(16, LOW); // turn the LED off by making the voltage LOW
delay(100);
i++;
}
}
void blinkStartConfig() {
pinMode(16,OUTPUT);
int i=0;
digitalWrite(16, HIGH); // turn the LED on (HIGH is the voltage level)
}
void loop() {
}
@s90304a123

This comment has been minimized.

Copy link

s90304a123 commented Mar 30, 2017

very nice! Thanks

@cafe5hsang

This comment has been minimized.

Copy link

cafe5hsang commented Apr 16, 2017

👍

@dancluj

This comment has been minimized.

Copy link

dancluj commented Aug 24, 2018

👍 Very useful repository

@marrobHD

This comment has been minimized.

Copy link

marrobHD commented Sep 30, 2018

Can anyone help to add this to this code? Hastebin: https://hastebin.com/nanotamuri.cpp

@rodvan

This comment has been minimized.

Copy link

rodvan commented Jan 24, 2019

I dont really understand how you are doing to store the Wifi config and so we avoidhaving to reconnect manually everytime the board resets. My respects, you are a life saver, but... please explain how this works or how you save it :)

@bkrajendra

This comment has been minimized.

Copy link

bkrajendra commented Aug 12, 2019

Smart config works through UDP. ESP receives credentials through UDP broadcast packets sent by SmartConfig App.

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.