example/eth2ap: fix station multi-connection problem and add channel config item.
Closes https://github.com/espressif/esp-idf/issues/5029
This commit is contained in:
parent
168660aebf
commit
1f43f025d8
2 changed files with 20 additions and 5 deletions
|
@ -143,6 +143,13 @@ menu "Example Configuration"
|
||||||
help
|
help
|
||||||
Set the password of Wi-Fi ap interface.
|
Set the password of Wi-Fi ap interface.
|
||||||
|
|
||||||
|
config EXAMPLE_WIFI_CHANNEL
|
||||||
|
int "WiFi channel"
|
||||||
|
range 1 13
|
||||||
|
default 1
|
||||||
|
help
|
||||||
|
Set the channel of Wi-Fi ap.
|
||||||
|
|
||||||
config EXAMPLE_MAX_STA_CONN
|
config EXAMPLE_MAX_STA_CONN
|
||||||
int "Maximum STA connections"
|
int "Maximum STA connections"
|
||||||
default 4
|
default 4
|
||||||
|
|
|
@ -124,16 +124,23 @@ static void eth_event_handler(void *arg, esp_event_base_t event_base,
|
||||||
static void wifi_event_handler(void *arg, esp_event_base_t event_base,
|
static void wifi_event_handler(void *arg, esp_event_base_t event_base,
|
||||||
int32_t event_id, void *event_data)
|
int32_t event_id, void *event_data)
|
||||||
{
|
{
|
||||||
|
static uint8_t s_con_cnt = 0;
|
||||||
switch (event_id) {
|
switch (event_id) {
|
||||||
case WIFI_EVENT_AP_STACONNECTED:
|
case WIFI_EVENT_AP_STACONNECTED:
|
||||||
ESP_LOGI(TAG, "Wi-Fi AP got a station connected");
|
ESP_LOGI(TAG, "Wi-Fi AP got a station connected");
|
||||||
|
if (!s_con_cnt) {
|
||||||
s_sta_is_connected = true;
|
s_sta_is_connected = true;
|
||||||
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, pkt_wifi2eth);
|
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, pkt_wifi2eth);
|
||||||
|
}
|
||||||
|
s_con_cnt++;
|
||||||
break;
|
break;
|
||||||
case WIFI_EVENT_AP_STADISCONNECTED:
|
case WIFI_EVENT_AP_STADISCONNECTED:
|
||||||
ESP_LOGI(TAG, "Wi-Fi AP got a station disconnected");
|
ESP_LOGI(TAG, "Wi-Fi AP got a station disconnected");
|
||||||
|
s_con_cnt--;
|
||||||
|
if (!s_con_cnt) {
|
||||||
s_sta_is_connected = false;
|
s_sta_is_connected = false;
|
||||||
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, NULL);
|
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, NULL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -205,7 +212,8 @@ static void initialize_wifi(void)
|
||||||
.ssid_len = strlen(CONFIG_EXAMPLE_WIFI_SSID),
|
.ssid_len = strlen(CONFIG_EXAMPLE_WIFI_SSID),
|
||||||
.password = CONFIG_EXAMPLE_WIFI_PASSWORD,
|
.password = CONFIG_EXAMPLE_WIFI_PASSWORD,
|
||||||
.max_connection = CONFIG_EXAMPLE_MAX_STA_CONN,
|
.max_connection = CONFIG_EXAMPLE_MAX_STA_CONN,
|
||||||
.authmode = WIFI_AUTH_WPA_WPA2_PSK
|
.authmode = WIFI_AUTH_WPA_WPA2_PSK,
|
||||||
|
.channel = CONFIG_EXAMPLE_WIFI_CHANNEL // default: channel 1
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (strlen(CONFIG_EXAMPLE_WIFI_PASSWORD) == 0) {
|
if (strlen(CONFIG_EXAMPLE_WIFI_PASSWORD) == 0) {
|
||||||
|
|
Loading…
Reference in a new issue