Skip to content

Commit d4c2ffe

Browse files
authored
Merge pull request #6022 from anecdata/more_ap_connections
wifi.radio.start_ap() new kwarg: max_connections
2 parents 59837fe + 5742a12 commit d4c2ffe

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,10 @@ msgstr ""
36303630
msgid "matrix is not positive definite"
36313631
msgstr ""
36323632

3633+
#: shared-bindings/wifi/Radio.c
3634+
msgid "max_connections must be between 0 and 10"
3635+
msgstr ""
3636+
36333637
#: ports/espressif/common-hal/_bleio/Descriptor.c
36343638
#: ports/nrf/common-hal/_bleio/Characteristic.c
36353639
#: ports/nrf/common-hal/_bleio/Descriptor.c

ports/espressif/common-hal/wifi/Radio.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
185185
set_mode_station(self, false);
186186
}
187187

188-
void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode) {
188+
void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections) {
189189
set_mode_ap(self, true);
190190

191191
switch (authmode) {
@@ -213,7 +213,12 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_
213213
config->ap.password[password_len] = 0;
214214
config->ap.channel = channel;
215215
config->ap.authmode = authmode;
216-
config->ap.max_connection = 4; // kwarg?
216+
217+
if (max_connections < 0 || max_connections > 10) {
218+
mp_raise_ValueError(translate("max_connections must be between 0 and 10"));
219+
}
220+
config->ap.max_connection = max_connections;
221+
217222
esp_wifi_set_config(WIFI_IF_AP, config);
218223
}
219224

shared-bindings/wifi/Radio.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
230230
//| password: ReadableBuffer = b"",
231231
//| *,
232232
//| channel: Optional[int] = 1,
233-
//| authmode: Optional[AuthMode]) -> None:
233+
//| authmode: Optional[AuthMode],
234+
//| max_connections: Optional[int] = 4) -> None:
234235
//| """Starts an Access Point with the specified ssid and password.
235236
//|
236237
//| If ``channel`` is given, the access point will use that channel unless
@@ -239,16 +240,20 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
239240
//| If ``authmode`` is given, the access point will use that Authentication
240241
//| mode. If a password is given, ``authmode`` must not be ``OPEN``.
241242
//| If ``authmode`` isn't given, ``OPEN`` will be used when password isn't provided,
242-
//| otherwise ``WPA_WPA2_PSK``."""
243+
//| otherwise ``WPA_WPA2_PSK``.
244+
//|
245+
//| If ``max_connections`` is given, the access point will allow up to
246+
//| that number of stations to connect."""
243247
//| ...
244248
//|
245249
STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
246-
enum { ARG_ssid, ARG_password, ARG_channel, ARG_authmode };
250+
enum { ARG_ssid, ARG_password, ARG_channel, ARG_authmode, ARG_max_connections };
247251
static const mp_arg_t allowed_args[] = {
248252
{ MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ },
249253
{ MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
250254
{ MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
251255
{ MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
256+
{ MP_QSTR_max_connections, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 4} },
252257
};
253258

254259
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
@@ -283,7 +288,7 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_
283288
authmode = 1;
284289
}
285290

286-
common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, authmode);
291+
common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, authmode, args[ARG_max_connections].u_int);
287292
return mp_const_none;
288293
}
289294
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap);

shared-bindings/wifi/Radio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self)
8888
extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self);
8989
extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self);
9090

91-
extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode);
91+
extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections);
9292
extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self);
9393

9494
extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len);

0 commit comments

Comments
 (0)