Skip to content

Commit a1e2afa

Browse files
committed
AP ip_info, gateway, & subnet
1 parent a328cff commit a1e2afa

File tree

5 files changed

+64
-15
lines changed

5 files changed

+64
-15
lines changed

ports/esp32s2/common-hal/wifi/Radio.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ static void set_mode_station(wifi_radio_obj_t *self, bool state) {
5656
} else {
5757
next_mode = WIFI_MODE_NULL;
5858
}
59-
}
60-
59+
}
6160
esp_wifi_set_mode(next_mode);
6261
self->sta_mode = state;
6362
}
@@ -76,8 +75,7 @@ static void set_mode_ap(wifi_radio_obj_t *self, bool state) {
7675
} else {
7776
next_mode = WIFI_MODE_NULL;
7877
}
79-
}
80-
78+
}
8179
esp_wifi_set_mode(next_mode);
8280
self->ap_mode = state;
8381
}
@@ -174,7 +172,7 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_
174172
config->ap.password[password_len] = 0;
175173
config->ap.channel = channel;
176174
config->ap.authmode = authmode;
177-
config->ap.max_connection = 4;
175+
config->ap.max_connection = 4; // kwarg?
178176
esp_wifi_set_config(WIFI_IF_AP, config);
179177
}
180178

@@ -294,6 +292,14 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) {
294292
return common_hal_ipaddress_new_ipv4address(self->ip_info.gw.addr);
295293
}
296294

295+
mp_obj_t common_hal_wifi_radio_get_ipv4_gateway_ap(wifi_radio_obj_t *self) {
296+
if (!esp_netif_is_netif_up(self->ap_netif)) {
297+
return mp_const_none;
298+
}
299+
esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info);
300+
return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.gw.addr);
301+
}
302+
297303
mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) {
298304
if (!esp_netif_is_netif_up(self->netif)) {
299305
return mp_const_none;
@@ -302,6 +308,14 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) {
302308
return common_hal_ipaddress_new_ipv4address(self->ip_info.netmask.addr);
303309
}
304310

311+
mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self) {
312+
if (!esp_netif_is_netif_up(self->ap_netif)) {
313+
return mp_const_none;
314+
}
315+
esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info);
316+
return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.netmask.addr);
317+
}
318+
305319
mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) {
306320
if (!esp_netif_is_netif_up(self->netif)) {
307321
return mp_const_none;
@@ -314,8 +328,8 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self) {
314328
if (!esp_netif_is_netif_up(self->ap_netif)) {
315329
return mp_const_none;
316330
}
317-
esp_netif_get_ip_info(self->ap_netif, &self->ip_info);
318-
return common_hal_ipaddress_new_ipv4address(self->ip_info.ip.addr);
331+
esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info);
332+
return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.ip.addr);
319333
}
320334

321335
mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self) {

ports/esp32s2/common-hal/wifi/Radio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typedef struct {
5959
uint8_t last_disconnect_reason;
6060

6161
wifi_config_t ap_config;
62+
esp_netif_ip_info_t ap_ip_info;
6263
esp_netif_t *ap_netif;
6364
} wifi_radio_obj_t;
6465

ports/esp32s2/common-hal/wifi/__init__.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ static void event_handler(void *arg, esp_event_base_t event_base,
5656
case WIFI_EVENT_AP_STOP:
5757
ESP_LOGW(TAG, "ap stop");
5858
break;
59-
case WIFI_EVENT_AP_STACONNECTED: {
59+
case WIFI_EVENT_AP_STACONNECTED:
6060
break;
61-
}
62-
case WIFI_EVENT_AP_STADISCONNECTED: {
61+
case WIFI_EVENT_AP_STADISCONNECTED:
6362
break;
64-
}
6563
case WIFI_EVENT_STA_START:
6664
ESP_LOGW(TAG, "sta start");
6765
break;

shared-bindings/wifi/Radio.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m
332332
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_connect_obj, 1, wifi_radio_connect);
333333

334334
//| ipv4_gateway: Optional[ipaddress.IPv4Address]
335-
//| """IP v4 Address of the gateway when connected to an access point. None otherwise."""
335+
//| """IP v4 Address of the station gateway when connected to an access point. None otherwise."""
336336
//|
337337
STATIC mp_obj_t wifi_radio_get_ipv4_gateway(mp_obj_t self) {
338338
return common_hal_wifi_radio_get_ipv4_gateway(self);
@@ -347,8 +347,24 @@ const mp_obj_property_t wifi_radio_ipv4_gateway_obj = {
347347
(mp_obj_t)&mp_const_none_obj },
348348
};
349349

350+
//| ipv4_gateway_ap: Optional[ipaddress.IPv4Address]
351+
//| """IP v4 Address of the access point gateway, when enabled. None otherwise."""
352+
//|
353+
STATIC mp_obj_t wifi_radio_get_ipv4_gateway_ap(mp_obj_t self) {
354+
return common_hal_wifi_radio_get_ipv4_gateway_ap(self);
355+
356+
}
357+
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_gateway_ap_obj, wifi_radio_get_ipv4_gateway_ap);
358+
359+
const mp_obj_property_t wifi_radio_ipv4_gateway_ap_obj = {
360+
.base.type = &mp_type_property,
361+
.proxy = { (mp_obj_t)&wifi_radio_get_ipv4_gateway_ap_obj,
362+
(mp_obj_t)&mp_const_none_obj,
363+
(mp_obj_t)&mp_const_none_obj },
364+
};
365+
350366
//| ipv4_subnet: Optional[ipaddress.IPv4Address]
351-
//| """IP v4 Address of the subnet when connected to an access point. None otherwise."""
367+
//| """IP v4 Address of the station subnet when connected to an access point. None otherwise."""
352368
//|
353369
STATIC mp_obj_t wifi_radio_get_ipv4_subnet(mp_obj_t self) {
354370
return common_hal_wifi_radio_get_ipv4_subnet(self);
@@ -363,8 +379,24 @@ const mp_obj_property_t wifi_radio_ipv4_subnet_obj = {
363379
(mp_obj_t)&mp_const_none_obj },
364380
};
365381

382+
//| ipv4_subnet_ap: Optional[ipaddress.IPv4Address]
383+
//| """IP v4 Address of the access point subnet, when enabled. None otherwise."""
384+
//|
385+
STATIC mp_obj_t wifi_radio_get_ipv4_subnet_ap(mp_obj_t self) {
386+
return common_hal_wifi_radio_get_ipv4_subnet_ap(self);
387+
388+
}
389+
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_subnet_ap_obj, wifi_radio_get_ipv4_subnet_ap);
390+
391+
const mp_obj_property_t wifi_radio_ipv4_subnet_ap_obj = {
392+
.base.type = &mp_type_property,
393+
.proxy = { (mp_obj_t)&wifi_radio_get_ipv4_subnet_ap_obj,
394+
(mp_obj_t)&mp_const_none_obj,
395+
(mp_obj_t)&mp_const_none_obj },
396+
};
397+
366398
//| ipv4_address: Optional[ipaddress.IPv4Address]
367-
//| """IP v4 Address of the radio when connected to an access point. None otherwise."""
399+
//| """IP v4 Address of the station when connected to an access point. None otherwise."""
368400
//|
369401
STATIC mp_obj_t wifi_radio_get_ipv4_address(mp_obj_t self) {
370402
return common_hal_wifi_radio_get_ipv4_address(self);
@@ -380,7 +412,7 @@ const mp_obj_property_t wifi_radio_ipv4_address_obj = {
380412
};
381413

382414
//| ipv4_address_ap: Optional[ipaddress.IPv4Address]
383-
//| """IP v4 Address of the radio access point, when enabled. None otherwise."""
415+
//| """IP v4 Address of the access point, when enabled. None otherwise."""
384416
//|
385417
STATIC mp_obj_t wifi_radio_get_ipv4_address_ap(mp_obj_t self) {
386418
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[] = {
482514
{ MP_ROM_QSTR(MP_QSTR_ap_info), MP_ROM_PTR(&wifi_radio_ap_info_obj) },
483515
{ MP_ROM_QSTR(MP_QSTR_ipv4_dns), MP_ROM_PTR(&wifi_radio_ipv4_dns_obj) },
484516
{ MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) },
517+
{ MP_ROM_QSTR(MP_QSTR_ipv4_gateway_ap), MP_ROM_PTR(&wifi_radio_ipv4_gateway_ap_obj) },
485518
{ MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) },
519+
{ MP_ROM_QSTR(MP_QSTR_ipv4_subnet_ap), MP_ROM_PTR(&wifi_radio_ipv4_subnet_ap_obj) },
486520
{ MP_ROM_QSTR(MP_QSTR_ipv4_address), MP_ROM_PTR(&wifi_radio_ipv4_address_obj) },
487521
{ MP_ROM_QSTR(MP_QSTR_ipv4_address_ap), MP_ROM_PTR(&wifi_radio_ipv4_address_ap_obj) },
488522

shared-bindings/wifi/Radio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self,
105105
extern mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self);
106106
extern mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self);
107107
extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self);
108+
extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway_ap(wifi_radio_obj_t *self);
108109
extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self);
110+
extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self);
109111
extern mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self);
110112
extern mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self);
111113

0 commit comments

Comments
 (0)