Skip to content

Commit

Permalink
example/eth2ap: fix station multi-connection problem and add channel …
Browse files Browse the repository at this point in the history
…config item.

Closes espressif#5029
  • Loading branch information
InfiniteYuan committed Apr 1, 2020
1 parent 168660a commit 1f43f02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 7 additions & 0 deletions examples/ethernet/eth2ap/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ menu "Example Configuration"
help
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
int "Maximum STA connections"
default 4
Expand Down
18 changes: 13 additions & 5 deletions examples/ethernet/eth2ap/main/ethernet_example_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
int32_t event_id, void *event_data)
{
static uint8_t s_con_cnt = 0;
switch (event_id) {
case WIFI_EVENT_AP_STACONNECTED:
ESP_LOGI(TAG, "Wi-Fi AP got a station connected");
s_sta_is_connected = true;
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, pkt_wifi2eth);
if (!s_con_cnt) {
s_sta_is_connected = true;
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, pkt_wifi2eth);
}
s_con_cnt++;
break;
case WIFI_EVENT_AP_STADISCONNECTED:
ESP_LOGI(TAG, "Wi-Fi AP got a station disconnected");
s_sta_is_connected = false;
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, NULL);
s_con_cnt--;
if (!s_con_cnt) {
s_sta_is_connected = false;
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, NULL);
}
break;
default:
break;
Expand Down Expand Up @@ -205,7 +212,8 @@ static void initialize_wifi(void)
.ssid_len = strlen(CONFIG_EXAMPLE_WIFI_SSID),
.password = CONFIG_EXAMPLE_WIFI_PASSWORD,
.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) {
Expand Down

0 comments on commit 1f43f02

Please sign in to comment.