Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/PsychicHttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "PsychicWebHandler.h"
#include "PsychicWebSocket.h"
#include "WiFi.h"
#include "esp_netif.h"
#ifdef PSY_ENABLE_ETHERNET
#include "ETH.h"
#endif
Expand Down Expand Up @@ -84,16 +85,23 @@ uint16_t PsychicHttpServer::getPort()

bool PsychicHttpServer::isConnected()
{
if (WiFi.softAPIP())
return true;
if (WiFi.localIP())
return true;

#ifdef PSY_ENABLE_ETHERNET
if (ETH.localIP())
return true;
#endif
// Use esp_netif API to enumerate all network interfaces
// This works universally across all ESP32 variants including P4 with co-processor WiFi/Ethernet
esp_netif_t* netif = esp_netif_next(NULL);
while (netif != NULL) {
if (esp_netif_is_netif_up(netif)) {
esp_netif_ip_info_t ip_info;
if (esp_netif_get_ip_info(netif, &ip_info) == ESP_OK && ip_info.ip.addr != 0) {
const char* desc = esp_netif_get_desc(netif);
ESP_LOGD(PH_TAG, "Network connected via interface: %s (IP: " IPSTR ")",
desc ? desc : "unknown", IP2STR(&ip_info.ip));
return true;
}
}
netif = esp_netif_next(netif);
}

ESP_LOGD(PH_TAG, "No active network interfaces found");
return false;
}

Expand All @@ -102,9 +110,10 @@ esp_err_t PsychicHttpServer::start()
if (_running)
return ESP_OK;

// starting without network will crash us.
// starting without network will crash us
// isConnected() now checks all network interfaces including co-processor connections
if (!isConnected()) {
ESP_LOGE(PH_TAG, "Server start failed - no network.");
ESP_LOGE(PH_TAG, "Server start failed - no network interface available.");
return ESP_FAIL;
}

Expand Down