Skip to content

wifi.radio.start_ap() new kwarg: max_connections #6022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions ports/espressif/common-hal/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down
13 changes: 9 additions & 4 deletions shared-bindings/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/wifi/Radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down