@@ -414,6 +414,28 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_subnet_ap_obj, wifi_radio_get_ipv4
414
414
MP_PROPERTY_GETTER (wifi_radio_ipv4_subnet_ap_obj ,
415
415
(mp_obj_t )& wifi_radio_get_ipv4_subnet_ap_obj );
416
416
417
+ //| def set_ipv4_address(self, *, ipv4: ipaddress.IPv4Address, netmask: ipaddress.IPv4Address, gateway: ipaddress.IPv4Address, ipv4_dns: Optional[ipaddress.IPv4Address]) -> None:
418
+ //| """Sets the IP v4 address of the station. Must include the netmask and gateway. DNS address is optional.
419
+ //| Setting the address manually will stop the DHCP client."""
420
+ //| ...
421
+ STATIC mp_obj_t wifi_radio_set_ipv4_address (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
422
+ enum { ARG_ipv4 , ARG_netmask , ARG_gateway , ARG_ipv4_dns };
423
+ static const mp_arg_t allowed_args [] = {
424
+ { MP_QSTR_ipv4 , MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ , },
425
+ { MP_QSTR_netmask , MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ , },
426
+ { MP_QSTR_gateway , MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ , },
427
+ { MP_QSTR_ipv4_dns , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_OBJ_NULL } },
428
+ };
429
+
430
+ wifi_radio_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
431
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
432
+ mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
433
+
434
+ common_hal_wifi_radio_set_ipv4_address (self , args [ARG_ipv4 ].u_obj , args [ARG_netmask ].u_obj , args [ARG_gateway ].u_obj , args [ARG_ipv4_dns ].u_obj );
435
+ return mp_const_none ;
436
+ }
437
+ STATIC MP_DEFINE_CONST_FUN_OBJ_KW (wifi_radio_set_ipv4_address_obj , 1 , wifi_radio_set_ipv4_address );
438
+
417
439
//| ipv4_address: Optional[ipaddress.IPv4Address]
418
440
//| """IP v4 Address of the station when connected to an access point. None otherwise."""
419
441
//|
@@ -438,17 +460,25 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_address_ap_obj, wifi_radio_get_ipv
438
460
MP_PROPERTY_GETTER (wifi_radio_ipv4_address_ap_obj ,
439
461
(mp_obj_t )& wifi_radio_get_ipv4_address_ap_obj );
440
462
441
- //| ipv4_dns: Optional[ ipaddress.IPv4Address]
442
- //| """IP v4 Address of the DNS server in use when connected to an access point. None otherwise ."""
463
+ //| ipv4_dns: ipaddress.IPv4Address
464
+ //| """IP v4 Address of the DNS server to be used ."""
443
465
//|
444
466
STATIC mp_obj_t wifi_radio_get_ipv4_dns (mp_obj_t self ) {
445
467
return common_hal_wifi_radio_get_ipv4_dns (self );
446
468
447
469
}
448
470
MP_DEFINE_CONST_FUN_OBJ_1 (wifi_radio_get_ipv4_dns_obj , wifi_radio_get_ipv4_dns );
449
471
450
- MP_PROPERTY_GETTER (wifi_radio_ipv4_dns_obj ,
451
- (mp_obj_t )& wifi_radio_get_ipv4_dns_obj );
472
+ STATIC mp_obj_t wifi_radio_set_ipv4_dns (mp_obj_t self , mp_obj_t ipv4_dns_addr ) {
473
+ common_hal_wifi_radio_set_ipv4_dns (self , ipv4_dns_addr );
474
+
475
+ return mp_const_none ;
476
+ }
477
+ MP_DEFINE_CONST_FUN_OBJ_2 (wifi_radio_set_ipv4_dns_obj , wifi_radio_set_ipv4_dns );
478
+
479
+ MP_PROPERTY_GETSET (wifi_radio_ipv4_dns_obj ,
480
+ (mp_obj_t )& wifi_radio_get_ipv4_dns_obj ,
481
+ (mp_obj_t )& wifi_radio_set_ipv4_dns_obj );
452
482
453
483
//| ap_info: Optional[Network]
454
484
//| """Network object containing BSSID, SSID, authmode, channel, country and RSSI when connected to an access point. None otherwise."""
@@ -459,6 +489,26 @@ STATIC mp_obj_t wifi_radio_get_ap_info(mp_obj_t self) {
459
489
}
460
490
MP_DEFINE_CONST_FUN_OBJ_1 (wifi_radio_get_ap_info_obj , wifi_radio_get_ap_info );
461
491
492
+ //| def start_dhcp(self) -> None:
493
+ //| """Starts the DHCP client."""
494
+ //| ...
495
+ //|
496
+ STATIC mp_obj_t wifi_radio_start_dhcp_client (mp_obj_t self ) {
497
+ common_hal_wifi_radio_start_dhcp_client (self );
498
+ return mp_const_none ;
499
+ }
500
+ MP_DEFINE_CONST_FUN_OBJ_1 (wifi_radio_start_dhcp_client_obj , wifi_radio_start_dhcp_client );
501
+
502
+ //| def stop_dhcp(self) -> None:
503
+ //| """Stops the DHCP client. Needed to assign a static IP address."""
504
+ //| ...
505
+ //|
506
+ STATIC mp_obj_t wifi_radio_stop_dhcp_client (mp_obj_t self ) {
507
+ common_hal_wifi_radio_stop_dhcp_client (self );
508
+ return mp_const_none ;
509
+ }
510
+ MP_DEFINE_CONST_FUN_OBJ_1 (wifi_radio_stop_dhcp_client_obj , wifi_radio_stop_dhcp_client );
511
+
462
512
MP_PROPERTY_GETTER (wifi_radio_ap_info_obj ,
463
513
(mp_obj_t )& wifi_radio_get_ap_info_obj );
464
514
@@ -509,6 +559,9 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = {
509
559
{ MP_ROM_QSTR (MP_QSTR_start_ap ), MP_ROM_PTR (& wifi_radio_start_ap_obj ) },
510
560
{ MP_ROM_QSTR (MP_QSTR_stop_ap ), MP_ROM_PTR (& wifi_radio_stop_ap_obj ) },
511
561
562
+ { MP_ROM_QSTR (MP_QSTR_start_dhcp ), MP_ROM_PTR (& wifi_radio_start_dhcp_client_obj ) },
563
+ { MP_ROM_QSTR (MP_QSTR_stop_dhcp ), MP_ROM_PTR (& wifi_radio_stop_dhcp_client_obj ) },
564
+
512
565
{ MP_ROM_QSTR (MP_QSTR_connect ), MP_ROM_PTR (& wifi_radio_connect_obj ) },
513
566
// { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) },
514
567
@@ -521,6 +574,8 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = {
521
574
{ MP_ROM_QSTR (MP_QSTR_ipv4_address ), MP_ROM_PTR (& wifi_radio_ipv4_address_obj ) },
522
575
{ MP_ROM_QSTR (MP_QSTR_ipv4_address_ap ), MP_ROM_PTR (& wifi_radio_ipv4_address_ap_obj ) },
523
576
577
+ { MP_ROM_QSTR (MP_QSTR_set_ipv4_address ), MP_ROM_PTR (& wifi_radio_set_ipv4_address_obj ) },
578
+
524
579
// { MP_ROM_QSTR(MP_QSTR_access_point_active), MP_ROM_PTR(&wifi_radio_access_point_active_obj) },
525
580
// { MP_ROM_QSTR(MP_QSTR_start_access_point), MP_ROM_PTR(&wifi_radio_start_access_point_obj) },
526
581
0 commit comments