Unverified Commit efe966d5 authored by Rodrigo Garcia's avatar Rodrigo Garcia Committed by GitHub

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
parent b31c9361
...@@ -32,7 +32,11 @@ void setup() { ...@@ -32,7 +32,11 @@ void setup() {
Serial.println("Configuring access point..."); Serial.println("Configuring access point...");
// You can remove the password parameter if you want the AP to be open. // 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(); IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: "); Serial.print("AP IP address: ");
Serial.println(myIP); Serial.println(myIP);
......
...@@ -136,12 +136,6 @@ void wifi_softap_config(wifi_config_t *wifi_config, const char * ssid=NULL, cons ...@@ -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) 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) { if(!ssid || *ssid == 0) {
// fail SSID missing // fail SSID missing
log_e("SSID missing!"); log_e("SSID missing!");
...@@ -154,6 +148,13 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, ...@@ -154,6 +148,13 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel,
return false; 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;
wifi_config_t conf_current; wifi_config_t conf_current;
wifi_softap_config(&conf, ssid, passphrase, channel, WIFI_AUTH_WPA2_PSK, ssid_hidden, max_connection, ftm_responder); wifi_softap_config(&conf, ssid, passphrase, channel, WIFI_AUTH_WPA2_PSK, ssid_hidden, max_connection, ftm_responder);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment