Add DNS optional to set IP
This commit is contained in:
parent
4f6d4e2284
commit
40e890323b
@ -412,7 +412,7 @@ void common_hal_wifi_radio_stop_dhcp_client(wifi_radio_obj_t *self) {
|
||||
esp_netif_dhcpc_stop(self->netif);
|
||||
}
|
||||
|
||||
void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway) {
|
||||
void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway, mp_obj_t ipv4_dns) {
|
||||
common_hal_wifi_radio_stop_dhcp_client(self); // Must stop DHCP to set a manual address
|
||||
|
||||
esp_netif_ip_info_t ip_info;
|
||||
@ -421,6 +421,10 @@ void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv
|
||||
ipaddress_ipaddress_to_esp_idf_ip4(gateway, &ip_info.gw);
|
||||
|
||||
esp_netif_set_ip_info(self->netif, &ip_info);
|
||||
|
||||
if (ipv4_dns != MP_OBJ_NULL) {
|
||||
common_hal_wifi_radio_set_ipv4_dns(self, ipv4_dns);
|
||||
}
|
||||
}
|
||||
|
||||
mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout) {
|
||||
|
@ -414,23 +414,24 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_subnet_ap_obj, wifi_radio_get_ipv4
|
||||
MP_PROPERTY_GETTER(wifi_radio_ipv4_subnet_ap_obj,
|
||||
(mp_obj_t)&wifi_radio_get_ipv4_subnet_ap_obj);
|
||||
|
||||
//| def set_ipv4_address(self, ipv4: ipaddress.IPv4Address, netmask: ipaddress.IPv4Address, gateway: ipaddress.IPv4Address) -> None:
|
||||
//| """Sets the IP v4 address of the station. Must include the netmask and gateway.
|
||||
//| def set_ipv4_address(self, ipv4: ipaddress.IPv4Address, netmask: ipaddress.IPv4Address, gateway: ipaddress.IPv4Address, ipv4_dns: Optional[ipaddress.IPv4Address]) -> None:
|
||||
//| """Sets the IP v4 address of the station. Must include the netmask and gateway. DNS address is optional.
|
||||
//| Setting the address manually will stop the DHCP client."""
|
||||
//| ...
|
||||
STATIC mp_obj_t wifi_radio_set_ipv4_address(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_ipv4, ARG_netmask, ARG_gateway };
|
||||
enum { ARG_ipv4, ARG_netmask, ARG_gateway, ARG_ipv4_dns };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_ipv4, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
{ MP_QSTR_netmask, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
{ MP_QSTR_gateway, MP_ARG_REQUIRED | MP_ARG_OBJ, },
|
||||
{ MP_QSTR_ipv4_dns, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
|
||||
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
common_hal_wifi_radio_set_ipv4_address(self, args[ARG_ipv4].u_obj, args[ARG_netmask].u_obj, args[ARG_gateway].u_obj);
|
||||
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);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_set_ipv4_address_obj, 4, wifi_radio_set_ipv4_address);
|
||||
|
@ -106,7 +106,7 @@ extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self)
|
||||
extern mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self);
|
||||
extern mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self);
|
||||
|
||||
extern void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway);
|
||||
extern void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway, mp_obj_t ipv4_dns_addr);
|
||||
|
||||
extern mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user