fix: dynamically check and display active station (WIFI_STA_DEF) IP on MCP Settings view
This commit is contained in:
@@ -50,23 +50,41 @@ 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(netif, &ip_info) == ESP_OK && ip_info.ip.addr != 0) {
|
||||
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(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;
|
||||
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 = "Connecting...";
|
||||
}
|
||||
} else {
|
||||
url = "Not connected";
|
||||
}
|
||||
}
|
||||
|
||||
if (url.starts_with("http://")) {
|
||||
|
||||
Reference in New Issue
Block a user