From e301734b2c30606408a2cc8c6413795aa93f3526 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 21 Aug 2022 11:46:43 +0200 Subject: [PATCH] Fix WifiHostByName for .local --- tasmota/tasmota_support/support_wifi.ino | 38 +++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/tasmota/tasmota_support/support_wifi.ino b/tasmota/tasmota_support/support_wifi.ino index 899733c61..af50e53ac 100644 --- a/tasmota/tasmota_support/support_wifi.ino +++ b/tasmota/tasmota_support/support_wifi.ino @@ -673,12 +673,22 @@ void WifiEnable(void) { Wifi.counter = 1; } +//#ifdef ESP8266 +//#include // sntp_servermode_dhcp() +//#endif // ESP8266 + void WifiConnect(void) { if (!Settings->flag4.network_wifi) { return; } WifiSetState(0); WifiSetOutputPower(); + +//#ifdef ESP8266 + // https://github.com/arendst/Tasmota/issues/16061#issuecomment-1216970170 +// sntp_servermode_dhcp(0); +//#endif // ESP8266 + WiFi.persistent(false); // Solve possible wifi init errors Wifi.status = 0; Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + (ESP_getChipId() & 0xF); // Add extra delay to stop overrun by simultanous re-connects @@ -809,23 +819,23 @@ void wifiKeepAlive(void) { 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 (strstr_P(aHostname, PSTR(".local")) == &aHostname[hostname_len] - 6) { if (WiFi.hostByName(aHostname, aResult)) { - // Host name resolved - if (0xFFFFFFFF != (uint32_t)aResult) { - return true; - } - return false; + // Host name resolved + if (0xFFFFFFFF != (uint32_t)aResult) { + return true; + } + } + } else { + // 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); + if (1 == DnsClient.getHostByName(aHostname, aResult)) { + return true; } } - // 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); - if (DnsClient.getHostByName(aHostname, aResult) != 1) { - AddLog(LOG_LEVEL_DEBUG, PSTR("DNS: Unable to resolve '%s'"), aHostname); - return false; - } - return true; + AddLog(LOG_LEVEL_DEBUG, PSTR("DNS: Unable to resolve '%s'"), aHostname); + return false; } bool WifiDnsPresent(const char* aHostname) {