-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SmartConfig auto connect to AP, without manually input AP ssid and password.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
hardware/esp8266com/esp8266/libraries/ESP8266WiFi/examples/SmartConfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <ESP8266WiFi.h> | ||
#include <WiFiUdp.h> | ||
|
||
WiFiUDP Udp; | ||
|
||
void setup() { | ||
uint8_t cnt = 0; | ||
|
||
Serial.begin(115200); | ||
|
||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(); | ||
|
||
while(WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
if(cnt++ >= 10){ | ||
WiFi.setSmartLink(); | ||
while(1){ | ||
delay(1000); | ||
if(WiFi.getSmartlinkStatus() == SC_STATUS_LINK_OVER){ | ||
Serial.println("SmartConfig Success"); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
Serial.println(""); | ||
Serial.println(""); | ||
|
||
WiFi.printDiag(Serial); | ||
|
||
// Start the server | ||
Udp.begin(49999); | ||
Serial.println("USP Server started"); | ||
|
||
// Print the IP address | ||
Serial.println(WiFi.localIP()); | ||
} | ||
|
||
void loop() { | ||
// Check if a client has connected | ||
Udp.parsePacket(); | ||
while(Udp.available()){ | ||
Serial.println(Udp.remoteIP()); | ||
Udp.flush(); | ||
delay(5); | ||
} | ||
} | ||
|