diff --git a/examples/common_components/protocol_examples_common/Kconfig.projbuild b/examples/common_components/protocol_examples_common/Kconfig.projbuild index eccf778890..5875ccdfa0 100644 --- a/examples/common_components/protocol_examples_common/Kconfig.projbuild +++ b/examples/common_components/protocol_examples_common/Kconfig.projbuild @@ -177,6 +177,7 @@ menu "Example Connection Configuration" config EXAMPLE_CONNECT_IPV6 bool "Obtain IPv6 address" default y + depends on EXAMPLE_CONNECT_WIFI || EXAMPLE_CONNECT_ETHERNET help By default, examples will wait until IPv4 and IPv6 local link addresses are obtained. Disable this option if the network does not support IPv6. diff --git a/examples/common_components/protocol_examples_common/connect.c b/examples/common_components/protocol_examples_common/connect.c index ed502210c8..dfba995e81 100644 --- a/examples/common_components/protocol_examples_common/connect.c +++ b/examples/common_components/protocol_examples_common/connect.c @@ -43,9 +43,10 @@ #define NR_OF_IP_ADDRESSES_TO_WAIT_FOR (s_active_interfaces) #endif +#define EXAMPLE_DO_CONNECT CONFIG_EXAMPLE_CONNECT_WIFI || CONFIG_EXAMPLE_CONNECT_ETHERNET + static int s_active_interfaces = 0; static xSemaphoreHandle s_semph_get_ip_addrs; -static esp_ip4_addr_t s_ip_addr; static esp_netif_t *s_example_esp_netif = NULL; #ifdef CONFIG_EXAMPLE_CONNECT_IPV6 @@ -102,7 +103,11 @@ static void start(void) s_example_esp_netif = NULL; #endif +#if EXAMPLE_DO_CONNECT + /* create semaphore if at least one interface is active */ s_semph_get_ip_addrs = xSemaphoreCreateCounting(NR_OF_IP_ADDRESSES_TO_WAIT_FOR, 0); +#endif + } /* tear down connection, release resources */ @@ -119,6 +124,9 @@ static void stop(void) #endif } +#if EXAMPLE_DO_CONNECT +static esp_ip4_addr_t s_ip_addr; + static void on_got_ip(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { @@ -131,6 +139,7 @@ static void on_got_ip(void *arg, esp_event_base_t event_base, memcpy(&s_ip_addr, &event->ip_info.ip, sizeof(s_ip_addr)); xSemaphoreGive(s_semph_get_ip_addrs); } +#endif #ifdef CONFIG_EXAMPLE_CONNECT_IPV6 @@ -155,9 +164,11 @@ static void on_got_ipv6(void *arg, esp_event_base_t event_base, esp_err_t example_connect(void) { +#if EXAMPLE_DO_CONNECT if (s_semph_get_ip_addrs != NULL) { return ESP_ERR_INVALID_STATE; } +#endif start(); ESP_ERROR_CHECK(esp_register_shutdown_handler(&stop)); ESP_LOGI(TAG, "Waiting for IP(s)"); diff --git a/examples/common_components/protocol_examples_common/include/protocol_examples_common.h b/examples/common_components/protocol_examples_common/include/protocol_examples_common.h index 859264df06..8c0a0a30e0 100644 --- a/examples/common_components/protocol_examples_common/include/protocol_examples_common.h +++ b/examples/common_components/protocol_examples_common/include/protocol_examples_common.h @@ -24,6 +24,11 @@ extern "C" { #define EXAMPLE_INTERFACE get_example_netif() #endif +#if !defined (CONFIG_EXAMPLE_CONNECT_ETHERNET) && !defined (CONFIG_EXAMPLE_CONNECT_WIFI) +// This is useful for some tests which do not need a network connection +#define EXAMPLE_INTERFACE NULL +#endif + /** * @brief Configure Wi-Fi or Ethernet, connect, wait for IP *