Skip to content

Commit d111001

Browse files
committed
Update WPS.ino
1 parent caca107 commit d111001

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

libraries/WiFi/examples/WPS/WPS.ino

+22-15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ void wpsInitConfig(){
3838
strcpy(config.factory_info.device_name, ESP_DEVICE_NAME);
3939
}
4040

41+
void wpsStart(){
42+
if(esp_wifi_wps_enable(&config)){
43+
Serial.println("WPS Enable Failed");
44+
} else if(esp_wifi_wps_start(0)){
45+
Serial.println("WPS Start Failed");
46+
}
47+
}
48+
49+
void wpsStop(){
50+
if(esp_wifi_wps_disable()){
51+
Serial.println("WPS Disable Failed");
52+
}
53+
}
54+
4155
String wpspin2string(uint8_t a[]){
4256
char wps_pin[9];
4357
for(int i=0;i<8;i++){
@@ -63,24 +77,22 @@ void WiFiEvent(WiFiEvent_t event, arduino_event_info_t info){
6377
break;
6478
case ARDUINO_EVENT_WPS_ER_SUCCESS:
6579
Serial.println("WPS Successfull, stopping WPS and connecting to: " + String(WiFi.SSID()));
66-
esp_wifi_wps_disable();
80+
wpsStop();
6781
delay(10);
6882
WiFi.begin();
6983
break;
7084
case ARDUINO_EVENT_WPS_ER_FAILED:
7185
Serial.println("WPS Failed, retrying");
72-
esp_wifi_wps_disable();
73-
esp_wifi_wps_enable(&config);
74-
esp_wifi_wps_start(0);
86+
wpsStop();
87+
wpsStart();
7588
break;
7689
case ARDUINO_EVENT_WPS_ER_TIMEOUT:
7790
Serial.println("WPS Timedout, retrying");
78-
esp_wifi_wps_disable();
79-
esp_wifi_wps_enable(&config);
80-
esp_wifi_wps_start(0);
91+
wpsStop();
92+
wpsStart();
8193
break;
8294
case ARDUINO_EVENT_WPS_ER_PIN:
83-
Serial.println("WPS_PIN = " + wpspin2string(info.sta_er_pin.pin_code));
95+
Serial.println("WPS_PIN = " + wpspin2string(info.wps_er_pin.pin_code));
8496
break;
8597
default:
8698
break;
@@ -90,19 +102,14 @@ void WiFiEvent(WiFiEvent_t event, arduino_event_info_t info){
90102
void setup(){
91103
Serial.begin(115200);
92104
delay(10);
93-
94105
Serial.println();
95-
96106
WiFi.onEvent(WiFiEvent);
97107
WiFi.mode(WIFI_MODE_STA);
98-
99108
Serial.println("Starting WPS");
100-
101109
wpsInitConfig();
102-
esp_wifi_wps_enable(&config);
103-
esp_wifi_wps_start(0);
110+
wpsStart();
104111
}
105112

106113
void loop(){
107114
//nothing to do here
108-
}
115+
}

0 commit comments

Comments
 (0)