Skip to content

Commit c52088c

Browse files
Stefano-Orsoliniigrr
authored andcommitted
set max_connection from code (when less than 4 is needed) (#2326)
* Update ESP8266WiFiAP.cpp It is not very common but some might require to set the maximum number of clients, from code, to smaller than 4. in my case i must allow only one client at a time (TESTED WORKING) * Update ESP8266WiFiAP.h as discussed in the .cpp (set max connections) * Update ESP8266WiFiAP.cpp corrected indentation @70 add param comment @86 * Update ESP8266WiFiAP.cpp
1 parent be3727c commit c52088c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ static bool softap_config_equal(const softap_config& lhs, const softap_config& r
6666
if(lhs.ssid_hidden != rhs.ssid_hidden) {
6767
return false;
6868
}
69+
if(lhs.max_connection != rhs.max_connection) {
70+
return false;
71+
}
6972
return true;
7073
}
7174

@@ -76,12 +79,13 @@ static bool softap_config_equal(const softap_config& lhs, const softap_config& r
7679

7780
/**
7881
* Set up an access point
79-
* @param ssid Pointer to the SSID (max 63 char).
80-
* @param passphrase (for WPA2 min 8 char, for open use NULL)
81-
* @param channel WiFi channel number, 1 - 13.
82-
* @param ssid_hidden Network cloaking (0 = broadcast SSID, 1 = hide SSID)
82+
* @param ssid Pointer to the SSID (max 63 char).
83+
* @param passphrase (for WPA2 min 8 char, for open use NULL)
84+
* @param channel WiFi channel number, 1 - 13.
85+
* @param ssid_hidden Network cloaking (0 = broadcast SSID, 1 = hide SSID)
86+
* @param max_connection Max simultaneous connected clients, 1 - 4.
8387
*/
84-
bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden) {
88+
bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection) {
8589

8690
if(!WiFi.enableAP(true)) {
8791
// enable AP failed
@@ -108,7 +112,7 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
108112
conf.channel = channel;
109113
conf.ssid_len = strlen(ssid);
110114
conf.ssid_hidden = ssid_hidden;
111-
conf.max_connection = 4;
115+
conf.max_connection = max_connection;
112116
conf.beacon_interval = 100;
113117

114118
if(!passphrase || strlen(passphrase) == 0) {

libraries/ESP8266WiFi/src/ESP8266WiFiAP.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ESP8266WiFiAPClass {
3636

3737
public:
3838

39-
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0);
39+
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4);
4040
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
4141
bool softAPdisconnect(bool wifioff = false);
4242

0 commit comments

Comments
 (0)