From 833fdf1da3889ad90c1cbe039637b0ea458a38a7 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Fri, 10 Feb 2023 17:58:02 -0300 Subject: [PATCH 1/2] Avoid starting AP Mode even when the password is too short --- libraries/WiFi/src/WiFiAP.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/WiFi/src/WiFiAP.cpp b/libraries/WiFi/src/WiFiAP.cpp index 6f69121be72..0eb0935345e 100644 --- a/libraries/WiFi/src/WiFiAP.cpp +++ b/libraries/WiFi/src/WiFiAP.cpp @@ -136,12 +136,6 @@ void wifi_softap_config(wifi_config_t *wifi_config, const char * ssid=NULL, cons bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder) { - if(!WiFi.enableAP(true)) { - // enable AP failed - log_e("enable AP first!"); - return false; - } - if(!ssid || *ssid == 0) { // fail SSID missing log_e("SSID missing!"); @@ -154,6 +148,13 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, return false; } + // last step after checking the SSID and password + if(!WiFi.enableAP(true)) { + // enable AP failed + log_e("enable AP first!"); + return false; + } + wifi_config_t conf; wifi_config_t conf_current; wifi_softap_config(&conf, ssid, passphrase, channel, WIFI_AUTH_WPA2_PSK, ssid_hidden, max_connection, ftm_responder); From 6069d4f5a17f1d68f49966d9497a1330781201b8 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Fri, 10 Feb 2023 19:48:59 -0300 Subject: [PATCH 2/2] Check SoftAP return code in case of failure --- libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino b/libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino index 4e654d12c79..eafc484f6d6 100644 --- a/libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino +++ b/libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino @@ -32,7 +32,11 @@ void setup() { Serial.println("Configuring access point..."); // You can remove the password parameter if you want the AP to be open. - WiFi.softAP(ssid, password); + // a valid password must have more than 7 characters + if (!WiFi.softAP(ssid, password)) { + log_e("Soft AP creation failed."); + while(1); + } IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP);