@@ -230,7 +230,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
230
230
//| password: ReadableBuffer = b"",
231
231
//| *,
232
232
//| channel: Optional[int] = 1,
233
- //| authmode: Optional[AuthMode]) -> None:
233
+ //| authmode: Optional[AuthMode],
234
+ //| max_connections: Optional[int] = 4) -> None:
234
235
//| """Starts an Access Point with the specified ssid and password.
235
236
//|
236
237
//| 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);
240
241
//| mode. If a password is given, ``authmode`` must not be ``OPEN``.
241
242
//| If ``authmode`` isn't given, ``OPEN`` will be used when password isn't provided,
242
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. Default is 4. Maximum is 10.
243
247
//| ...
244
248
//|
245
249
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 };
247
251
static const mp_arg_t allowed_args [] = {
248
252
{ MP_QSTR_ssid , MP_ARG_REQUIRED | MP_ARG_OBJ },
249
253
{ MP_QSTR_password , MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
250
254
{ MP_QSTR_channel , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1 } },
251
255
{ 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 } },
252
257
};
253
258
254
259
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_
283
288
authmode = 1 ;
284
289
}
285
290
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 );
287
296
return mp_const_none ;
288
297
}
289
298
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (wifi_radio_start_ap_obj , 1 , wifi_radio_start_ap );
0 commit comments