mirror of
https://github.com/espressif/esp-idf.git
synced 2024-09-18 18:06:27 -04:00
fix(examples): Timeout waiting for IP addrs in protocol_examples_common
For example, in case a unique local address is preferred (via sdkconfig) but not available on the network, this patch prevents initialisation from hanging indefinitely. Instead, we wait up to 10s for an IPv4 address and another 10s for the preferred type of IPv6 address. In case of timeout, a warning is logged and the program continues.
This commit is contained in:
parent
d7ca8b94c8
commit
099c7c0541
@ -232,10 +232,14 @@ esp_err_t example_ethernet_connect(void)
|
||||
eth_start();
|
||||
ESP_LOGI(TAG, "Waiting for IP(s).");
|
||||
#if CONFIG_EXAMPLE_CONNECT_IPV4
|
||||
xSemaphoreTake(s_semph_get_ip_addrs, portMAX_DELAY);
|
||||
if (xSemaphoreTake(s_semph_get_ip_addrs, pdMS_TO_TICKS(10000)) == pdFALSE) {
|
||||
ESP_LOGW(TAG, "Gave up waiting for IPv4 address.");
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_EXAMPLE_CONNECT_IPV6
|
||||
xSemaphoreTake(s_semph_get_ip6_addrs, portMAX_DELAY);
|
||||
if (xSemaphoreTake(s_semph_get_ip6_addrs, pdMS_TO_TICKS(10000)) == pdFALSE) {
|
||||
ESP_LOGW(TAG, "Gave up waiting for (preferred) IPv6 address.");
|
||||
}
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
@ -166,10 +166,14 @@ esp_err_t example_wifi_sta_do_connect(wifi_config_t wifi_config, bool wait)
|
||||
if (wait) {
|
||||
ESP_LOGI(TAG, "Waiting for IP(s)");
|
||||
#if CONFIG_EXAMPLE_CONNECT_IPV4
|
||||
xSemaphoreTake(s_semph_get_ip_addrs, portMAX_DELAY);
|
||||
if (xSemaphoreTake(s_semph_get_ip_addrs, pdMS_TO_TICKS(10000)) == pdFALSE) {
|
||||
ESP_LOGW(TAG, "Gave up waiting for IPv4 address.");
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_EXAMPLE_CONNECT_IPV6
|
||||
xSemaphoreTake(s_semph_get_ip6_addrs, portMAX_DELAY);
|
||||
if (xSemaphoreTake(s_semph_get_ip6_addrs, pdMS_TO_TICKS(10000)) == pdFALSE) {
|
||||
ESP_LOGW(TAG, "Gave up waiting for (preferred) IPv6 address.");
|
||||
}
|
||||
#endif
|
||||
if (s_retry_num > CONFIG_EXAMPLE_WIFI_CONN_MAX_RETRY) {
|
||||
return ESP_FAIL;
|
||||
|
Loading…
Reference in New Issue
Block a user