Skip to content

Commit b559a0e

Browse files
committed
new kwarg: wifi.radio.start_ap(max_connections=)
1 parent ddac37a commit b559a0e

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
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: 2 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,7 @@ 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+
config->ap.max_connection = max_connections;
217217
esp_wifi_set_config(WIFI_IF_AP, config);
218218
}
219219

shared-bindings/wifi/Radio.c

Lines changed: 12 additions & 3 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
@@ -240,15 +241,19 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
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,
242243
//| 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. Default is 4. Maximum is 10.
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,11 @@ 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+
if (args[ARG_max_connections].u_int < 0 || args[ARG_max_connections].u_int > 10) {
292+
mp_raise_ValueError(translate("max_connections must be between 0 and 10"));
293+
}
294+
295+
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);
287296
return mp_const_none;
288297
}
289298
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)