Merge pull request #6022 from anecdata/more_ap_connections

wifi.radio.start_ap() new kwarg: max_connections
This commit is contained in:
Scott Shawcroft 2022-02-14 10:08:39 -08:00 committed by GitHub
commit d4c2ffea27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 7 deletions

View File

@ -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

View File

@ -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,12 @@ 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?
if (max_connections < 0 || max_connections > 10) {
mp_raise_ValueError(translate("max_connections must be between 0 and 10"));
}
config->ap.max_connection = max_connections;
esp_wifi_set_config(WIFI_IF_AP, config);
}

View File

@ -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
@ -239,16 +240,20 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
//| If ``authmode`` is given, the access point will use that Authentication
//| 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``."""
//| otherwise ``WPA_WPA2_PSK``.
//|
//| If ``max_connections`` is given, the access point will allow up to
//| that number of stations to connect."""
//| ...
//|
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,7 @@ 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);
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);

View File

@ -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);