Skip to content

Commit

Permalink
fix(examples): Timeout waiting for IP addresses in protocol_examples_…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
serpent213 committed Aug 14, 2024
1 parent d7ca8b9 commit 55f0ed6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 55f0ed6

Please sign in to comment.