fix: dynamically check and display active station (WIFI_STA_DEF) IP on MCP Settings view
This commit is contained in:
@@ -50,22 +50,40 @@ class McpSettingsApp final : public App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string url = "http://";
|
std::string url = "http://";
|
||||||
|
bool ip_added = false;
|
||||||
|
|
||||||
if (wsSettings.wifiMode == settings::webserver::WiFiMode::AccessPoint) {
|
// Try getting station IP first (we are connected to home Wi-Fi)
|
||||||
url += "192.168.4.1";
|
esp_netif_t* sta_netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
|
||||||
} else {
|
if (sta_netif != nullptr) {
|
||||||
esp_netif_t* netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
|
esp_netif_ip_info_t ip_info;
|
||||||
if (netif != nullptr) {
|
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;
|
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];
|
char ip_str[16];
|
||||||
snprintf(ip_str, sizeof(ip_str), IPSTR, IP2STR(&ip_info.ip));
|
snprintf(ip_str, sizeof(ip_str), IPSTR, IP2STR(&ip_info.ip));
|
||||||
url += ip_str;
|
url += ip_str;
|
||||||
} else {
|
ip_added = true;
|
||||||
url = "Connecting...";
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
} else {
|
||||||
url = "Not connected";
|
url = "Connecting...";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user