esp32/network_wlan: Use esp_wifi_set/get_channel to config wifi channel.

Set the channel with esp_wifi_set_channel(), which adds support for setting
the channel of the STA interface

Get the channel with esp_wifi_get_channel() which returns the actual wifi
channel of the radio, rather than the configured channel.
pull/9058/head
glenn20 2022-07-31 16:36:10 +10:00 zatwierdzone przez Damien George
rodzic 47c45d0e7f
commit 98d1c50159
1 zmienionych plików z 22 dodań i 5 usunięć

Wyświetl plik

@ -448,8 +448,22 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_
break;
}
case MP_QSTR_channel: {
req_if = WIFI_IF_AP;
cfg.ap.channel = mp_obj_get_int(kwargs->table[i].value);
uint8_t primary;
wifi_second_chan_t secondary;
// Get the current value of secondary
esp_exceptions(esp_wifi_get_channel(&primary, &secondary));
primary = mp_obj_get_int(kwargs->table[i].value);
esp_err_t err = esp_wifi_set_channel(primary, secondary);
if (err == ESP_ERR_INVALID_ARG) {
// May need to swap secondary channel above to below or below to above
secondary = (
(secondary == WIFI_SECOND_CHAN_ABOVE)
? WIFI_SECOND_CHAN_BELOW
: (secondary == WIFI_SECOND_CHAN_BELOW)
? WIFI_SECOND_CHAN_ABOVE
: WIFI_SECOND_CHAN_NONE);
esp_exceptions(esp_wifi_set_channel(primary, secondary));
}
break;
}
case MP_QSTR_hostname:
@ -535,10 +549,13 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_
req_if = WIFI_IF_AP;
val = MP_OBJ_NEW_SMALL_INT(cfg.ap.authmode);
break;
case MP_QSTR_channel:
req_if = WIFI_IF_AP;
val = MP_OBJ_NEW_SMALL_INT(cfg.ap.channel);
case MP_QSTR_channel: {
uint8_t channel;
wifi_second_chan_t second;
esp_exceptions(esp_wifi_get_channel(&channel, &second));
val = MP_OBJ_NEW_SMALL_INT(channel);
break;
}
case MP_QSTR_hostname:
case MP_QSTR_dhcp_hostname: {
const char *s;