diff --git a/Tactility/Source/app/mcpsettings/McpSettingsApp.cpp b/Tactility/Source/app/mcpsettings/McpSettingsApp.cpp index 03351640..2faa1e0d 100644 --- a/Tactility/Source/app/mcpsettings/McpSettingsApp.cpp +++ b/Tactility/Source/app/mcpsettings/McpSettingsApp.cpp @@ -50,22 +50,40 @@ class McpSettingsApp final : public App { } std::string url = "http://"; + bool ip_added = false; - if (wsSettings.wifiMode == settings::webserver::WiFiMode::AccessPoint) { - url += "192.168.4.1"; - } else { - esp_netif_t* netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"); - if (netif != nullptr) { + // Try getting station IP first (we are connected to home Wi-Fi) + esp_netif_t* sta_netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"); + if (sta_netif != nullptr) { + esp_netif_ip_info_t ip_info; + if (esp_netif_get_ip_info(sta_netif, &ip_info) == ESP_OK && ip_info.ip.addr != 0) { + char ip_str[16]; + snprintf(ip_str, sizeof(ip_str), IPSTR, IP2STR(&ip_info.ip)); + url += ip_str; + ip_added = true; + } + } + + // If no station IP, check if the AP interface has a valid IP address + if (!ip_added) { + esp_netif_t* ap_netif = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF"); + if (ap_netif != nullptr) { esp_netif_ip_info_t ip_info; - if (esp_netif_get_ip_info(netif, &ip_info) == ESP_OK && ip_info.ip.addr != 0) { + if (esp_netif_get_ip_info(ap_netif, &ip_info) == ESP_OK && ip_info.ip.addr != 0) { char ip_str[16]; snprintf(ip_str, sizeof(ip_str), IPSTR, IP2STR(&ip_info.ip)); url += ip_str; - } else { - url = "Connecting..."; + ip_added = true; } + } + } + + // Fallback if no active IP address is detected on either interface + if (!ip_added) { + if (wsSettings.wifiMode == settings::webserver::WiFiMode::AccessPoint) { + url += "192.168.4.1"; } else { - url = "Not connected"; + url = "Connecting..."; } }