From 77660b5d3c68ac5792066f4cb49423b11f654ef5 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 22 Feb 2022 15:42:04 +0100 Subject: [PATCH] Fix discovery ethernet ip address Fix discovery ethernet ip address (#14929) --- tasmota/xdrv_12_discovery.ino | 12 ++++++++++-- tasmota/xdrv_12_home_assistant.ino | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tasmota/xdrv_12_discovery.ino b/tasmota/xdrv_12_discovery.ino index 112df2387..5d5f71431 100644 --- a/tasmota/xdrv_12_discovery.ino +++ b/tasmota/xdrv_12_discovery.ino @@ -34,10 +34,18 @@ #define XDRV_12 12 void TasDiscoverMessage(void) { + uint32_t ip_address = (uint32_t)WiFi.localIP(); + char* hostname = TasmotaGlobal.hostname; +#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) + if (static_cast(EthernetLocalIP()) != 0) { + ip_address = (uint32_t)EthernetLocalIP(); + hostname = EthernetHostname(); + } +#endif Response_P(PSTR("{\"ip\":\"%_I\"," // IP Address "\"dn\":\"%s\"," // Device Name "\"fn\":["), // Friendly Names (start) - (uint32_t)WiFi.localIP(), + ip_address, SettingsText(SET_DEVICENAME)); uint32_t maxfn = (TasmotaGlobal.devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!TasmotaGlobal.devices_present) ? 1 : TasmotaGlobal.devices_present; @@ -69,7 +77,7 @@ void TasDiscoverMessage(void) { "\"ft\":\"%s\"," // Full Topic "\"tp\":[\"%s\",\"%s\",\"%s\"]," // Topics for command, stat and tele "\"rl\":["), // Relays (start) - TasmotaGlobal.hostname, + hostname, NetworkUniqueId().c_str(), ModuleName().c_str(), TuyaMod, iFanMod, diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 0aa67c753..00bbf6734 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -201,10 +201,18 @@ int hass_tele_period = 0; // NEW DISCOVERY void HassDiscoverMessage(void) { + uint32_t ip_address = (uint32_t)WiFi.localIP(); + char* hostname = TasmotaGlobal.hostname; +#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32 && defined(USE_ETHERNET) + if (static_cast(EthernetLocalIP()) != 0) { + ip_address = (uint32_t)EthernetLocalIP(); + hostname = EthernetHostname(); + } +#endif Response_P(PSTR("{\"ip\":\"%_I\"," // IP Address "\"dn\":\"%s\"," // Device Name "\"fn\":["), // Friendly Names (start) - (uint32_t)WiFi.localIP(), + ip_address, SettingsText(SET_DEVICENAME)); uint32_t maxfn = (TasmotaGlobal.devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!TasmotaGlobal.devices_present) ? 1 : TasmotaGlobal.devices_present; @@ -236,7 +244,7 @@ void HassDiscoverMessage(void) { "\"ft\":\"%s\"," // Full Topic "\"tp\":[\"%s\",\"%s\",\"%s\"]," // Topics for command, stat and tele "\"rl\":["), // Relays (start) - TasmotaGlobal.hostname, + hostname, NetworkUniqueId().c_str(), ModuleName().c_str(), TuyaMod, iFanMod,