ESP 01 WIFI配網微信Airkiss配網

3824 ワード

#include 

// led 
int led =2 ;


void setup() {

     // 
     Serial.begin(115200);
     
     // LED 
     pinMode(led, OUTPUT);
     digitalWrite(led, HIGH);

    if(!autoConfig()){
        smartConfig();
    }
      

}

void loop() {
  // put your main code here, to run repeatedly:

}






//*******************************************************   WIFI   ***************************************************
//ap  
void smartConfig(){
  WiFi.mode(WIFI_STA);
  Serial.println("\r
Smartconfig..."); WiFi.beginSmartConfig(); while (1){ Serial.println("."); // delay(200); digitalWrite(led, LOW); delay(200); digitalWrite(led, HIGH); if (WiFi.smartConfigDone()){ // Serial.println("SmartConfig Success"); digitalWrite(led, LOW); Serial.printf("SSID:%s\r
", WiFi.SSID().c_str()); Serial.printf("PSW:%s\r
", WiFi.psk().c_str()); Serial.print("LocalIP:"); Serial.print(WiFi.localIP()); Serial.print(" ,GateIP:"); Serial.println(WiFi.gatewayIP()); break; } } } // bool autoConfig(){ WiFi.begin(); // for (int i = 0; i < 20; i++){ int wstatus = WiFi.status(); if (wstatus == WL_CONNECTED){ digitalWrite(led, LOW); Serial.println("WIFI SmartConfig Success"); Serial.printf("SSID:%s", WiFi.SSID().c_str()); Serial.printf(", PSW:%s\r
", WiFi.psk().c_str()); Serial.print("LocalIP:"); Serial.print(WiFi.localIP()); Serial.print(" ,GateIP:"); Serial.println(WiFi.gatewayIP()); return true; }else{ Serial.println("WIFI AutoConfig Waiting......"); delay(1000); digitalWrite(led, LOW); delay(1000); digitalWrite(led, HIGH); } } Serial.println("WIFI " ); return false; }

 
 
 
//*******************************************************   WIFI   ***************************************************
//ap  
void smartConfig(){
  WiFi.mode(WIFI_STA);
  Serial.println("\r
Smartconfig..."); WiFi.beginSmartConfig(); while (1){ Serial.print("."); digitalWrite(led, HIGH); delay(500); digitalWrite(led, LOW); delay(500); // if (WiFi.smartConfigDone()){ // Serial.println("SmartConfig Success"); Serial.printf("SSID:%s\r
", WiFi.SSID().c_str()); Serial.printf("PSW:%s\r
", WiFi.psk().c_str()); Serial.print("LocalIP:"); Serial.print(WiFi.localIP()); Serial.print(" ,GateIP:"); Serial.println(WiFi.gatewayIP()); break; } } } // bool autoConfig(){ WiFi.begin(); // for (int i = 0; i < 20; i++){ int wstatus = WiFi.status(); if (wstatus == WL_CONNECTED){ Serial.println("WIFI SmartConfig Success"); Serial.printf("SSID:%s", WiFi.SSID().c_str()); Serial.printf(", PSW:%s\r
", WiFi.psk().c_str()); Serial.print("LocalIP:"); Serial.print(WiFi.localIP()); Serial.print(" ,GateIP:"); Serial.println(WiFi.gatewayIP()); return true; }else{ Serial.println("WIFI AutoConfig Waiting......"); delay(1000); digitalWrite(led, HIGH); delay(1000); digitalWrite(led, LOW); } } Serial.println("WIFI " ); return false; }