Skip to content

Instantly share code, notes, and snippets.

@rodvan
Last active January 24, 2019 19:20
Show Gist options
  • Save rodvan/e55a869d45f8c624a794e09b81ab92a5 to your computer and use it in GitHub Desktop.
Save rodvan/e55a869d45f8c624a794e09b81ab92a5 to your computer and use it in GitHub Desktop.

Revisions

  1. rodvan renamed this gist Jan 24, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. rodvan created this gist Jan 24, 2019.
    43 changes: 43 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #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() {
    }