Skip to content

Commit 5bdf9e0

Browse files
committed
fix(example): Add better WPS logging
Provides a better log of what went wrong when using WPS
1 parent 4e3523c commit 5bdf9e0

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

libraries/WiFi/examples/WPS/WPS.ino

+14-22
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,28 @@ Pranav Cherukupalli <[email protected]>
2020
Change the definition of the WPS mode
2121
from WPS_TYPE_PBC to WPS_TYPE_PIN in
2222
the case that you are using pin type
23-
WPS
23+
WPS (pin is 00000000)
2424
*/
2525
#define ESP_WPS_MODE WPS_TYPE_PBC
26-
#define ESP_MANUFACTURER "ESPRESSIF"
27-
#define ESP_MODEL_NUMBER "ESP32"
28-
#define ESP_MODEL_NAME "ESPRESSIF IOT"
29-
#define ESP_DEVICE_NAME "ESP STATION"
30-
31-
static esp_wps_config_t config;
32-
33-
void wpsInitConfig() {
34-
config.wps_type = ESP_WPS_MODE;
35-
strcpy(config.factory_info.manufacturer, ESP_MANUFACTURER);
36-
strcpy(config.factory_info.model_number, ESP_MODEL_NUMBER);
37-
strcpy(config.factory_info.model_name, ESP_MODEL_NAME);
38-
strcpy(config.factory_info.device_name, ESP_DEVICE_NAME);
39-
}
4026

4127
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");
28+
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(ESP_WPS_MODE);
29+
esp_err_t err = esp_wifi_wps_enable(&config);
30+
if (err != ESP_OK) {
31+
Serial.printf("WPS Enable Failed: 0x%x: %s\n", err, esp_err_to_name(err));
32+
return;
33+
}
34+
35+
err = esp_wifi_wps_start(0);
36+
if (err != ESP_OK) {
37+
Serial.printf("WPS Start Failed: 0x%x: %s\n", err, esp_err_to_name(err));
4638
}
4739
}
4840

4941
void wpsStop() {
50-
if (esp_wifi_wps_disable()) {
51-
Serial.println("WPS Disable Failed");
42+
esp_err_t err = esp_wifi_wps_disable();
43+
if (err != ESP_OK) {
44+
Serial.printf("WPS Disable Failed: 0x%x: %s\n", err, esp_err_to_name(err));
5245
}
5346
}
5447

@@ -102,7 +95,6 @@ void setup() {
10295
WiFi.onEvent(WiFiEvent); // Will call WiFiEvent() from another thread.
10396
WiFi.mode(WIFI_MODE_STA);
10497
Serial.println("Starting WPS");
105-
wpsInitConfig();
10698
wpsStart();
10799
}
108100

0 commit comments

Comments
 (0)