Skip to content

Commit efe966d

Browse files
authored
Avoid starting AP Mode even when the password is too short (#7832)
* Avoid starting AP Mode even when the password is too short * Check SoftAP return code in case of failure
1 parent b31c936 commit efe966d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

Diff for: libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ void setup() {
3232
Serial.println("Configuring access point...");
3333

3434
// You can remove the password parameter if you want the AP to be open.
35-
WiFi.softAP(ssid, password);
35+
// a valid password must have more than 7 characters
36+
if (!WiFi.softAP(ssid, password)) {
37+
log_e("Soft AP creation failed.");
38+
while(1);
39+
}
3640
IPAddress myIP = WiFi.softAPIP();
3741
Serial.print("AP IP address: ");
3842
Serial.println(myIP);

Diff for: libraries/WiFi/src/WiFiAP.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ void wifi_softap_config(wifi_config_t *wifi_config, const char * ssid=NULL, cons
136136
bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder)
137137
{
138138

139-
if(!WiFi.enableAP(true)) {
140-
// enable AP failed
141-
log_e("enable AP first!");
142-
return false;
143-
}
144-
145139
if(!ssid || *ssid == 0) {
146140
// fail SSID missing
147141
log_e("SSID missing!");
@@ -154,6 +148,13 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel,
154148
return false;
155149
}
156150

151+
// last step after checking the SSID and password
152+
if(!WiFi.enableAP(true)) {
153+
// enable AP failed
154+
log_e("enable AP first!");
155+
return false;
156+
}
157+
157158
wifi_config_t conf;
158159
wifi_config_t conf_current;
159160
wifi_softap_config(&conf, ssid, passphrase, channel, WIFI_AUTH_WPA2_PSK, ssid_hidden, max_connection, ftm_responder);

0 commit comments

Comments
 (0)