mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
fix(wifi): Add max retry count for iperf station command
This commit is contained in:
@@ -55,6 +55,8 @@ static wifi_args_t sta_args;
|
||||
static wifi_scan_arg_t scan_args;
|
||||
static wifi_args_t ap_args;
|
||||
static bool reconnect = true;
|
||||
static int retry_count = 0;
|
||||
static bool reconn_state = false;
|
||||
static const char *TAG = "cmd_wifi";
|
||||
esp_netif_t *netif_ap = NULL;
|
||||
esp_netif_t *netif_sta = NULL;
|
||||
@@ -125,11 +127,15 @@ static void got_ip_handler(void *arg, esp_event_base_t event_base,
|
||||
static void disconnect_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
if (reconnect) {
|
||||
if (reconnect && retry_count < 5) {
|
||||
ESP_LOGI(TAG, "sta disconnect, reconnect...");
|
||||
esp_wifi_connect();
|
||||
reconn_state = true;
|
||||
retry_count++;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "sta disconnect");
|
||||
reconn_state = false;
|
||||
retry_count = 0;
|
||||
}
|
||||
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
|
||||
xEventGroupSetBits(wifi_event_group, DISCONNECTED_BIT);
|
||||
@@ -230,6 +236,7 @@ static bool wifi_cmd_sta_join(const char *ssid, const char *pass, bool enable_he
|
||||
esp_wifi_connect();
|
||||
|
||||
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 5000 / portTICK_PERIOD_MS);
|
||||
reconn_state = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -242,6 +249,10 @@ static int wifi_cmd_sta(int argc, char **argv)
|
||||
arg_print_errors(stderr, sta_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (reconn_state == true) {
|
||||
ESP_LOGE(TAG, "Reconnection in progress, try again later");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
|
||||
|
||||
Reference in New Issue
Block a user