AP ip_info, gateway, & subnet

This commit is contained in:
anecdata 2021-04-26 00:22:51 -05:00
parent a328cff209
commit a1e2afadce
5 changed files with 64 additions and 15 deletions

View File

@ -56,8 +56,7 @@ static void set_mode_station(wifi_radio_obj_t *self, bool state) {
} else {
next_mode = WIFI_MODE_NULL;
}
}
}
esp_wifi_set_mode(next_mode);
self->sta_mode = state;
}
@ -76,8 +75,7 @@ static void set_mode_ap(wifi_radio_obj_t *self, bool state) {
} else {
next_mode = WIFI_MODE_NULL;
}
}
}
esp_wifi_set_mode(next_mode);
self->ap_mode = state;
}
@ -174,7 +172,7 @@ 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;
config->ap.max_connection = 4; // kwarg?
esp_wifi_set_config(WIFI_IF_AP, config);
}
@ -294,6 +292,14 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) {
return common_hal_ipaddress_new_ipv4address(self->ip_info.gw.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_gateway_ap(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->ap_netif)) {
return mp_const_none;
}
esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info);
return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.gw.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->netif)) {
return mp_const_none;
@ -302,6 +308,14 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) {
return common_hal_ipaddress_new_ipv4address(self->ip_info.netmask.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->ap_netif)) {
return mp_const_none;
}
esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info);
return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.netmask.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->netif)) {
return mp_const_none;
@ -314,8 +328,8 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self) {
if (!esp_netif_is_netif_up(self->ap_netif)) {
return mp_const_none;
}
esp_netif_get_ip_info(self->ap_netif, &self->ip_info);
return common_hal_ipaddress_new_ipv4address(self->ip_info.ip.addr);
esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info);
return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.ip.addr);
}
mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self) {

View File

@ -59,6 +59,7 @@ typedef struct {
uint8_t last_disconnect_reason;
wifi_config_t ap_config;
esp_netif_ip_info_t ap_ip_info;
esp_netif_t *ap_netif;
} wifi_radio_obj_t;

View File

@ -56,12 +56,10 @@ static void event_handler(void *arg, esp_event_base_t event_base,
case WIFI_EVENT_AP_STOP:
ESP_LOGW(TAG, "ap stop");
break;
case WIFI_EVENT_AP_STACONNECTED: {
case WIFI_EVENT_AP_STACONNECTED:
break;
}
case WIFI_EVENT_AP_STADISCONNECTED: {
case WIFI_EVENT_AP_STADISCONNECTED:
break;
}
case WIFI_EVENT_STA_START:
ESP_LOGW(TAG, "sta start");
break;

View File

@ -332,7 +332,7 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_connect_obj, 1, wifi_radio_connect);
//| ipv4_gateway: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the gateway when connected to an access point. None otherwise."""
//| """IP v4 Address of the station gateway when connected to an access point. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_gateway(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_gateway(self);
@ -347,8 +347,24 @@ const mp_obj_property_t wifi_radio_ipv4_gateway_obj = {
(mp_obj_t)&mp_const_none_obj },
};
//| ipv4_gateway_ap: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the access point gateway, when enabled. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_gateway_ap(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_gateway_ap(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_gateway_ap_obj, wifi_radio_get_ipv4_gateway_ap);
const mp_obj_property_t wifi_radio_ipv4_gateway_ap_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&wifi_radio_get_ipv4_gateway_ap_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
//| ipv4_subnet: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the subnet when connected to an access point. None otherwise."""
//| """IP v4 Address of the station subnet when connected to an access point. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_subnet(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_subnet(self);
@ -363,8 +379,24 @@ const mp_obj_property_t wifi_radio_ipv4_subnet_obj = {
(mp_obj_t)&mp_const_none_obj },
};
//| ipv4_subnet_ap: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the access point subnet, when enabled. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_subnet_ap(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_subnet_ap(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_subnet_ap_obj, wifi_radio_get_ipv4_subnet_ap);
const mp_obj_property_t wifi_radio_ipv4_subnet_ap_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&wifi_radio_get_ipv4_subnet_ap_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
//| ipv4_address: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the radio when connected to an access point. None otherwise."""
//| """IP v4 Address of the station when connected to an access point. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_address(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_address(self);
@ -380,7 +412,7 @@ const mp_obj_property_t wifi_radio_ipv4_address_obj = {
};
//| ipv4_address_ap: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the radio access point, when enabled. None otherwise."""
//| """IP v4 Address of the access point, when enabled. None otherwise."""
//|
STATIC mp_obj_t wifi_radio_get_ipv4_address_ap(mp_obj_t self) {
return common_hal_wifi_radio_get_ipv4_address_ap(self);
@ -482,7 +514,9 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_ap_info), MP_ROM_PTR(&wifi_radio_ap_info_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_dns), MP_ROM_PTR(&wifi_radio_ipv4_dns_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_gateway_ap), MP_ROM_PTR(&wifi_radio_ipv4_gateway_ap_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_subnet_ap), MP_ROM_PTR(&wifi_radio_ipv4_subnet_ap_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_address), MP_ROM_PTR(&wifi_radio_ipv4_address_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_address_ap), MP_ROM_PTR(&wifi_radio_ipv4_address_ap_obj) },

View File

@ -105,7 +105,9 @@ extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self,
extern mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway_ap(wifi_radio_obj_t *self);
extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self);
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);