diff --git a/esphome/components/mdns/mdns_component.h b/esphome/components/mdns/mdns_component.h index 4f651f7d84..798af0e0bf 100644 --- a/esphome/components/mdns/mdns_component.h +++ b/esphome/components/mdns/mdns_component.h @@ -76,7 +76,17 @@ class MDNSComponent final : public Component // and update() becomes pure overhead. We arm a bounded polling window from IP state // listener events so update() runs only during that phase. static constexpr uint32_t MDNS_UPDATE_INTERVAL_MS = 50; - static constexpr uint32_t MDNS_POLL_WINDOW_MS = 12000; // ~9s phase + jitter/restart margin + // Must exceed LEAmDNS's longest restart-to-announce-complete path: + // MDNS_PROBE_DELAY (250ms) × MDNS_PROBE_COUNT (3) = 750ms probing + // + MDNS_ANNOUNCE_DELAY (1000ms) × MDNS_ANNOUNCE_COUNT (8) = 8000ms announcing + // + rand() % MDNS_PROBE_DELAY jitter on first probe (0–250ms) + // + debounced schedule_function() hop when statusChangeCB fires on ESP8266 + // ≈ 9s nominal. 15s gives ~6s margin to absorb main-loop blocking (long + // component setup, WiFi scan, flash writes) that could stretch the deadlines + // between our polls. If LEAmDNS ever extends its phase (upstream library + // update) this constant needs to grow. Constants defined in LEAmDNS_Priv.h + // (ESP8266 core 3.1.2 / arduino-pico 5.5.1). + static constexpr uint32_t MDNS_POLL_WINDOW_MS = 15000; static constexpr uint32_t MDNS_POLL_ID = 0; static constexpr uint32_t MDNS_POLL_STOP_ID = 1; #endif diff --git a/esphome/components/mdns/mdns_esp8266.cpp b/esphome/components/mdns/mdns_esp8266.cpp index 95137ea116..f6d5786675 100644 --- a/esphome/components/mdns/mdns_esp8266.cpp +++ b/esphome/components/mdns/mdns_esp8266.cpp @@ -48,7 +48,7 @@ void MDNSComponent::start_polling_window_() { void MDNSComponent::setup() { this->setup_buffers_and_register_(register_esp8266); -#ifdef USE_MDNS_EVENT_DRIVEN_POLLING +#ifdef USE_MDNS_WIFI_LISTENER // LEAmDNS's own LwipIntf::statusChangeCB drives _restart() on netif changes; we just // arm the window around the initial probe/announce and each reconnect. Unconditional // here is safe: setup_priority::AFTER_CONNECTION guarantees the network is up. @@ -57,7 +57,7 @@ void MDNSComponent::setup() { #endif } -#ifdef USE_MDNS_EVENT_DRIVEN_POLLING +#ifdef USE_MDNS_WIFI_LISTENER void MDNSComponent::on_ip_state(const network::IPAddresses &ips, const network::IPAddress &, const network::IPAddress &) { // IP listener only fires on acquisition (not loss), so any notification is a fresh