diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 893e1b339e..8daa071c57 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -3630,6 +3630,10 @@ msgstr "" msgid "matrix is not positive definite" msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "max_connections must be between 0 and 10" +msgstr "" + #: ports/espressif/common-hal/_bleio/Descriptor.c #: ports/nrf/common-hal/_bleio/Characteristic.c #: ports/nrf/common-hal/_bleio/Descriptor.c diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index 7ee5071fcc..80d32da5ea 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -185,7 +185,7 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { set_mode_station(self, false); } -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) { +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) { set_mode_ap(self, true); switch (authmode) { @@ -213,7 +213,7 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ config->ap.password[password_len] = 0; config->ap.channel = channel; config->ap.authmode = authmode; - config->ap.max_connection = 4; // kwarg? + config->ap.max_connection = max_connections; esp_wifi_set_config(WIFI_IF_AP, config); } diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 7701b1ff33..cad7031e1f 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -230,7 +230,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); //| password: ReadableBuffer = b"", //| *, //| channel: Optional[int] = 1, -//| authmode: Optional[AuthMode]) -> None: +//| authmode: Optional[AuthMode], +//| max_connections: Optional[int] = 4) -> None: //| """Starts an Access Point with the specified ssid and password. //| //| 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); //| mode. If a password is given, ``authmode`` must not be ``OPEN``. //| If ``authmode`` isn't given, ``OPEN`` will be used when password isn't provided, //| otherwise ``WPA_WPA2_PSK``.""" +//| +//| If ``max_connections`` is given, the access point will allow up to +//| that number of stations to connect. Default is 4. Maximum is 10. //| ... //| STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_ssid, ARG_password, ARG_channel, ARG_authmode }; + enum { ARG_ssid, ARG_password, ARG_channel, ARG_authmode, ARG_max_connections }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, { MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_max_connections, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 4} }, }; 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_ authmode = 1; } - common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, authmode); + if (args[ARG_max_connections].u_int < 0 || args[ARG_max_connections].u_int > 10) { + mp_raise_ValueError(translate("max_connections must be between 0 and 10")); + } + + 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); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap); diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 78a0c333cd..cee9f6ef15 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -88,7 +88,7 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self); -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); +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); extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self); 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);