38 lines
1.2 KiB
Markdown
38 lines
1.2 KiB
Markdown
extern "C" {
|
|
#include "lwip/netif.h"
|
|
}
|
|
|
|
void listNetworkInterfaces() {
|
|
esp_netif_t *netif = NULL;
|
|
Serial.println("\n=== Listing Network Interfaces ===");
|
|
|
|
for (netif = esp_netif_next(NULL); netif != NULL; netif = esp_netif_next(netif)) {
|
|
const char* if_key = esp_netif_get_ifkey(netif);
|
|
const char* if_desc = esp_netif_get_desc(netif);
|
|
|
|
Serial.printf("Interface Key: %s\n", if_key);
|
|
Serial.printf("Description : %s\n", if_desc);
|
|
Serial.println("-----------------------------");
|
|
}
|
|
}
|
|
|
|
void setEthernetAsDefault() {
|
|
Logger.log(0, ELOG_LEVEL_DEBUG, "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
|
|
listNetworkInterfaces();
|
|
// Attempt to locate the Ethernet network interface.
|
|
// (The name may vary—on some systems it might be "eth0")
|
|
esp_netif_t* netif = esp_netif_get_handle_from_ifkey("ETH_DEF");
|
|
|
|
if (netif) {
|
|
Serial.println("Netif handle obtained successfully.");
|
|
} else {
|
|
Serial.println("Failed to obtain netif handle.");
|
|
}
|
|
struct netif *eth_netif2 = netif_find("ETH_DEF");
|
|
if (netif) {
|
|
netif_set_default(eth_netif2);
|
|
Logger.log(0, ELOG_LEVEL_DEBUG, "Ethernet set as default network interface.");
|
|
} else {
|
|
Logger.log(0, ELOG_LEVEL_DEBUG, "Could not find Ethernet netif.");
|
|
}
|
|
} |