From 16c39aab9e4f19c8dc201365195840dfefc55bd2 Mon Sep 17 00:00:00 2001 From: rogg Date: Sat, 20 Aug 2022 23:17:05 -0700 Subject: [PATCH] mDNS resolution for *.local fixes #16269 "Add user control over DNS timeout reducing blocking" https://github.com/arendst/Tasmota/commit/c988ba16451186c55873793978e7730619a25074 created DnsClient so that a timeout can be used to prevent blocking on ESP32, but it can't do one-shot mDNS queries. Use WiFi.hostByName () for those. --- tasmota/tasmota_support/support_wifi.ino | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tasmota/tasmota_support/support_wifi.ino b/tasmota/tasmota_support/support_wifi.ino index 495fe71b8..899733c61 100644 --- a/tasmota/tasmota_support/support_wifi.ino +++ b/tasmota/tasmota_support/support_wifi.ino @@ -807,6 +807,17 @@ void wifiKeepAlive(void) { #endif // ESP8266 bool WifiHostByName(const char* aHostname, IPAddress& aResult) { + // DnsClient can't do one-shot mDNS queries so use WiFi.hostByName() for *.local + size_t hostname_len = strlen(aHostname); + if (strstr(aHostname, ".local") == &aHostname[hostname_len] - 6) { + if (WiFi.hostByName(aHostname, aResult)) { + // Host name resolved + if (0xFFFFFFFF != (uint32_t)aResult) { + return true; + } + return false; + } + } // Use this instead of WiFi.hostByName or connect(host_name,.. to block less if DNS server is not found uint32_t dns_address = (!TasmotaGlobal.global_state.eth_down) ? Settings->eth_ipv4_address[3] : Settings->ipv4_address[3]; DnsClient.begin((IPAddress)dns_address);