After SmartConfig Esp8266 by a key distribution network, such as how to replace the routing reconfiguration

Esp8266 after SmartConfig by a key distribution network, replacement of how to reconfigure routing

In a recent written SmartConfig key programs and found that there are two noteworthy issues

1. When the start SmartConfig configuration must be set to Station mode Esp8266

2. When the configuration is complete, the next time you want to reconfigure the new WIFI route, you need to enter the SmartConfig configuration again, it can be used in two ways

1. 重新启动后,配置一GPIO脚位为上拉输入脚,平时为高电平,一但该脚位接低则进入SmartConfig配置 
2. 每次程序启动后,直接进入SmartConfig配置,设置超时时间,一旦超时则退出SmartConfig配置,在此时间段内可进行 配置   `在这里插入代码片`
#include <ESP8266WiFi.h>
  void SmartConfig()
{
    int TimerOverCount=0;
    WiFi.mode(WIFI_STA);
    Serial.println("WIFI Wait for Smartconfig");
    WiFi.beginSmartConfig();
       while (1)
    {
        Serial.printf(".%d",TimerOverCount);
        if (WiFi.smartConfigDone())
        {
         Serial.println("WIFI SmartConfig Success");
        Serial.printf("SSID:%s", WiFi.SSID().c_str());
        Serial.printf(", PSW:%s\r\n", WiFi.psk().c_str());
        Serial.print("LocalIP:");
        Serial.print(WiFi.localIP());
        Serial.print(" ,GateIP:");
        Serial.println(WiFi.gatewayIP());
        WiFi.setAutoConnect(true);  // 设置自动连接
        break;
        }
        if(TimerOverCount>=15)
         {
           WiFi.stopSmartConfig();
           WiFi.begin();
           break;
         }
         TimerOverCount ++;
        delay(1000);
      }
}
void setup(void)
{
  // Start Serial
  Serial.begin(115200);
  delay(100);
  SmartConfig();
  } 
    ```
    
  
Released three original articles · won praise 0 · Views 34

Guess you like

Origin blog.csdn.net/chen20171013/article/details/105318156