@@ -38,6 +38,20 @@ void wpsInitConfig(){
38
38
strcpy (config.factory_info .device_name , ESP_DEVICE_NAME);
39
39
}
40
40
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
+
41
55
String wpspin2string (uint8_t a[]){
42
56
char wps_pin[9 ];
43
57
for (int i=0 ;i<8 ;i++){
@@ -63,24 +77,22 @@ void WiFiEvent(WiFiEvent_t event, arduino_event_info_t info){
63
77
break ;
64
78
case ARDUINO_EVENT_WPS_ER_SUCCESS:
65
79
Serial.println (" WPS Successfull, stopping WPS and connecting to: " + String (WiFi.SSID ()));
66
- esp_wifi_wps_disable ();
80
+ wpsStop ();
67
81
delay (10 );
68
82
WiFi.begin ();
69
83
break ;
70
84
case ARDUINO_EVENT_WPS_ER_FAILED:
71
85
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 ();
75
88
break ;
76
89
case ARDUINO_EVENT_WPS_ER_TIMEOUT:
77
90
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 ();
81
93
break ;
82
94
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 ));
84
96
break ;
85
97
default :
86
98
break ;
@@ -90,19 +102,14 @@ void WiFiEvent(WiFiEvent_t event, arduino_event_info_t info){
90
102
void setup (){
91
103
Serial.begin (115200 );
92
104
delay (10 );
93
-
94
105
Serial.println ();
95
-
96
106
WiFi.onEvent (WiFiEvent);
97
107
WiFi.mode (WIFI_MODE_STA);
98
-
99
108
Serial.println (" Starting WPS" );
100
-
101
109
wpsInitConfig ();
102
- esp_wifi_wps_enable (&config);
103
- esp_wifi_wps_start (0 );
110
+ wpsStart ();
104
111
}
105
112
106
113
void loop (){
107
114
// nothing to do here
108
- }
115
+ }
0 commit comments