46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
/*
|
|
* @Author: dugulingping
|
|
* @Date: 2022-06-09 17:14:49
|
|
* @LastEditTime: 2022-06-16 15:35:00
|
|
* @LastEditors: dugulingping
|
|
* @Description:
|
|
* @FilePath: \test\SmartComfigWIFI\SmartComfigWIFI.ino
|
|
*/
|
|
#include <ESP8266WiFi.h>
|
|
void smartConfig()
|
|
{
|
|
Serial.begin(115200);
|
|
WiFi.mode(WIFI_STA); //设置WIFI模块为STA模式
|
|
Serial.println("\r\nWaiting for connection");
|
|
//smartconfig进行初始化
|
|
WiFi.beginSmartConfig();
|
|
while (1) //等待连接成功
|
|
{
|
|
Serial.print(">");
|
|
digitalWrite(LED_BUILTIN, 0);
|
|
delay(100);
|
|
digitalWrite(LED_BUILTIN, 1);
|
|
delay(100);
|
|
//如果连接成功后就打印出连接的WIFI信息
|
|
if (WiFi.smartConfigDone())
|
|
{
|
|
Serial.println("SmartConfig Success");
|
|
Serial.printf("SSID:%s", WiFi.SSID().c_str());
|
|
Serial.printf("PW:%s", WiFi.psk().c_str());//打印出密码
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void setup() {
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
smartConfig();
|
|
}
|
|
|
|
void loop() {
|
|
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
|
|
delay(1000); // Wait for a second
|
|
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
|
|
delay(1000); // Wait for two seconds (to demonstrate the active low LED)
|
|
} |