From 37a711d8291c206c2a085415ddf2e9e154285755 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 19 Sep 2025 12:20:32 +0200 Subject: [PATCH] fix(esp_netif): Enable/disable the lost-ip-timer explicitely Previously we had to set the timer to 0 to disable it completely, now we have a specific config option to switch it on/off --- components/esp_netif/Kconfig | 15 +++++++++++---- components/esp_netif/lwip/esp_netif_lwip.c | 4 +++- docs/en/api-guides/wifi.rst | 2 +- docs/en/api-reference/network/esp_netif.rst | 4 +++- docs/zh_CN/api-guides/wifi.rst | 2 +- docs/zh_CN/api-reference/network/esp_netif.rst | 4 +++- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/components/esp_netif/Kconfig b/components/esp_netif/Kconfig index 1c3f111e177..4ab26cbe6c5 100644 --- a/components/esp_netif/Kconfig +++ b/components/esp_netif/Kconfig @@ -1,17 +1,24 @@ menu "ESP NETIF Adapter" + config ESP_NETIF_LOST_IP_TIMER_ENABLE + bool "Enable IPv4 lost IP event timer" + default y + help + Enable raising LOST_IP events using a timer when the IPv4 address becomes invalid. + When disabled, the timer is not started and LOST_IP events are not posted. + The delay is configured by ESP_NETIF_IP_LOST_TIMER_INTERVAL. + config ESP_NETIF_IP_LOST_TIMER_INTERVAL int "IP Address lost timer interval (seconds)" range 0 65535 default 120 help - The value of 0 indicates the IP lost timer is disabled, otherwise the timer is enabled. - The IP address may be lost because of some reasons, e.g. when the station disconnects from soft-AP, or when DHCP IP renew fails etc. If the IP lost timer is enabled, it will be started every time the IP is lost. Event SYSTEM_EVENT_STA_LOST_IP will be raised if - the timer expires. The IP lost timer is stopped if the station get the IP again before - the timer expires. + the timer expires. The IP lost timer is stopped if the station gets the IP again before + the timer expires. For backward compatibility, setting the interval to 0 disables the + timer as well. config ESP_NETIF_PROVIDE_CUSTOM_IMPLEMENTATION bool "Use only ESP-NETIF headers" diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 4fbb4f3c29a..e156d9b0a09 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -1554,14 +1554,16 @@ static esp_err_t esp_netif_start_ip_lost_timer(esp_netif_t *esp_netif) return ESP_OK; } +#if CONFIG_ESP_NETIF_LOST_IP_TIMER_ENABLE if ( netif && (CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL > 0)) { esp_netif->timer_running = true; sys_timeout(CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL * 1000, esp_netif_ip_lost_timer, (void *)esp_netif); ESP_LOGD(TAG, "if%p start ip lost tmr: interval=%d", esp_netif, CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL); return ESP_OK; } +#endif - ESP_LOGD(TAG, "if%p start ip lost tmr: no need start because netif=%p interval=%d ip=%" PRIx32, + ESP_LOGD(TAG, "if%p start ip lost tmr: disabled or not needed (netif=%p interval=%d ip=%" PRIx32 ")", esp_netif, netif, (CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL), ip_info_old->ip.addr); return ESP_OK; diff --git a/docs/en/api-guides/wifi.rst b/docs/en/api-guides/wifi.rst index d3e759e3e90..f3882b798e1 100644 --- a/docs/en/api-guides/wifi.rst +++ b/docs/en/api-guides/wifi.rst @@ -320,7 +320,7 @@ IP_EVENT_STA_LOST_IP This event arises when the IPV4 address becomes invalid. -IP_EVENT_STA_LOST_IP does not arise immediately after the Wi-Fi disconnects. Instead, it starts an IPV4 address lost timer. If the IPV4 address is got before ip lost timer expires, IP_EVENT_STA_LOST_IP does not happen. Otherwise, the event arises when the IPV4 address lost timer expires. +IP_EVENT_STA_LOST_IP does not arise immediately after the Wi-Fi disconnects. Instead, it starts an IPV4 address lost timer (configurable via :ref:`CONFIG_ESP_NETIF_LOST_IP_TIMER_ENABLE` and :ref:`CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL`). If the IPV4 address is got before the timer expires, IP_EVENT_STA_LOST_IP does not happen. Otherwise, the event arises when the IPV4 address lost timer expires. Generally, the application can ignore this event, because it is just a debug event to inform that the IPV4 address is lost. diff --git a/docs/en/api-reference/network/esp_netif.rst b/docs/en/api-reference/network/esp_netif.rst index 8e20c5df2c5..7da8cc2533b 100644 --- a/docs/en/api-reference/network/esp_netif.rst +++ b/docs/en/api-reference/network/esp_netif.rst @@ -137,7 +137,9 @@ Registering event handlers is crucial due to the asynchronous nature of networki .. note:: - Lost IP events are triggered by a timer configurable by :ref:`CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL`. The timer is started upon losing the IP address and the event will be raised after the configured interval, which is 120 s by default. The event could be disabled when setting the interval to 0. + Lost IP events are triggered by a timer that can be enabled or disabled by :ref:`CONFIG_ESP_NETIF_LOST_IP_TIMER_ENABLE`, + with the delay configured by :ref:`CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL`. The timer is started upon losing the IP address, and the event is raised after the configured interval (120 s by default). + For backward compatibility, setting the interval to 0 also disables the timer. .. _esp-netif structure: diff --git a/docs/zh_CN/api-guides/wifi.rst b/docs/zh_CN/api-guides/wifi.rst index fdf1a9e6354..4b82b1abcbf 100644 --- a/docs/zh_CN/api-guides/wifi.rst +++ b/docs/zh_CN/api-guides/wifi.rst @@ -319,7 +319,7 @@ IP_EVENT_STA_LOST_IP 当 IPV4 地址失效时,将引发此事件。 -此事件不会在 Wi-Fi 断连后立刻出现。Wi-Fi 连接断开后,首先将启动一个 IPV4 地址丢失计时器,如果 station 在该计时器超时之前成功获取了 IPV4 地址,则不会发生此事件。否则,此事件将在计时器超时时发生。 +此事件不会在 Wi-Fi 断连后立刻出现。Wi-Fi 连接断开后,首先将启动一个 IPV4 地址丢失计时器(可通过 :ref:`CONFIG_ESP_NETIF_LOST_IP_TIMER_ENABLE` 与 :ref:`CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL` 配置)。如果 station 在该计时器超时之前成功获取了 IPV4 地址,则不会发生此事件。否则,此事件将在计时器超时时发生。 一般来说,应用程序可忽略此事件。这只是一个调试事件,主要使应用程序获知 IPV4 地址已丢失。 diff --git a/docs/zh_CN/api-reference/network/esp_netif.rst b/docs/zh_CN/api-reference/network/esp_netif.rst index 3dc20d4309b..7e6e0e6cd99 100644 --- a/docs/zh_CN/api-reference/network/esp_netif.rst +++ b/docs/zh_CN/api-reference/network/esp_netif.rst @@ -137,7 +137,9 @@ IP 事件 .. note:: - 丢失 IP 事件由一个可配置的定时器触发,配置项为 :ref:`CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL`。当 IP 地址丢失时定时器启动,事件将在配置的时间间隔后触发,默认值为 120 秒。将时间间隔设置为 0 时可禁用该事件。 + 丢失 IP 事件由一个可配置的定时器触发,可通过 :ref:`CONFIG_ESP_NETIF_LOST_IP_TIMER_ENABLE` 启用或禁用, + 延迟由 :ref:`CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL` 配置。当 IP 地址丢失时定时器启动,事件将在配置的 + 时间间隔后触发(默认 120 秒)。为保持向后兼容,将时间间隔设置为 0 也会禁用该定时器。 .. _esp-netif structure: