From ee4d42cbf6bdff4b3fc1ee87c88f9084dfc11935 Mon Sep 17 00:00:00 2001 From: Matthias Hertel Date: Tue, 18 Jun 2024 02:30:57 +0200 Subject: [PATCH] V2.x compatible to ESP32 Core 2.x (#44) --- src/ESP32SSDP.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ESP32SSDP.cpp b/src/ESP32SSDP.cpp index c413268..9a543f0 100644 --- a/src/ESP32SSDP.cpp +++ b/src/ESP32SSDP.cpp @@ -153,6 +153,22 @@ void SSDPClass::end() { } IPAddress SSDPClass::localIP() { + +#if (ESP_ARDUINO_VERSION_MAJOR < 3) + // Arduino ESP32 2.x board version + tcpip_adapter_ip_info_t ip; + if (WiFi.getMode() == WIFI_STA) { + if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip)) { + return IPAddress(); + } + } else if (WiFi.getMode() == WIFI_OFF) { + if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip)) { + return IPAddress(); + } + } + +#else + // Arduino ESP32 3.x board version esp_netif_ip_info_t ip; if (WiFi.getMode() == WIFI_STA) { if (esp_netif_get_ip_info(get_esp_interface_netif(ESP_IF_WIFI_STA), &ip)) { @@ -163,9 +179,13 @@ IPAddress SSDPClass::localIP() { return IPAddress(); } } + +#endif + return IPAddress(ip.ip.addr); } + void SSDPClass::setUUID(const char *uuid, bool rootonly) { // no sanity check is done - TBD if (rootonly) {