Skip to content

Commit 01a5df1

Browse files
Copilotnetmindz
andcommitted
Fix HTTP server startup by bypassing uninitialized ETH object in QEMU
Root cause: Network.isConnected() relied on ETH.localIP() which returned 0.0.0.0 because ETH.begin() was skipped to avoid MAC register crash. This prevented initInterfaces() and server.begin() from being called. Solution: Modified Network.cpp to check tcpip_adapter directly when WLED_QEMU is defined, bypassing the uninitialized ETH object. This allows WLED to detect the network connection established via DHCP and start the HTTP server. Changes: - Added tcpip_adapter.h and esp_system.h includes for QEMU mode - Modified localIP(), subnetMask(), gatewayIP() to query tcpip_adapter directly - Modified isConnected() to check tcpip_adapter IP assignment - Modified isEthernet() to always return true in QEMU mode This completes the QEMU networking fix recommended by @coderabbitai analysis Co-authored-by: netmindz <[email protected]>
1 parent f0ee919 commit 01a5df1

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

wled00/src/dependencies/network/Network.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
#include "Network.h"
22

3+
#ifdef WLED_QEMU
4+
#include "esp_system.h"
5+
#include "tcpip_adapter.h"
6+
#endif
7+
38
IPAddress NetworkClass::localIP()
49
{
10+
#ifdef WLED_QEMU
11+
// QEMU: Get IP directly from tcpip_adapter
12+
tcpip_adapter_ip_info_t ip_info;
13+
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip_info) == ESP_OK) {
14+
if (ip_info.ip.addr != 0) {
15+
return IPAddress(ip_info.ip.addr);
16+
}
17+
}
18+
return INADDR_NONE;
19+
#else
520
IPAddress localIP;
621
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
722
localIP = ETH.localIP();
@@ -15,10 +30,20 @@ IPAddress NetworkClass::localIP()
1530
}
1631

1732
return INADDR_NONE;
33+
#endif
1834
}
1935

2036
IPAddress NetworkClass::subnetMask()
2137
{
38+
#ifdef WLED_QEMU
39+
tcpip_adapter_ip_info_t ip_info;
40+
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip_info) == ESP_OK) {
41+
if (ip_info.netmask.addr != 0) {
42+
return IPAddress(ip_info.netmask.addr);
43+
}
44+
}
45+
return IPAddress(255, 255, 255, 0);
46+
#else
2247
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
2348
if (ETH.localIP()[0] != 0) {
2449
return ETH.subnetMask();
@@ -28,10 +53,20 @@ IPAddress NetworkClass::subnetMask()
2853
return WiFi.subnetMask();
2954
}
3055
return IPAddress(255, 255, 255, 0);
56+
#endif
3157
}
3258

3359
IPAddress NetworkClass::gatewayIP()
3460
{
61+
#ifdef WLED_QEMU
62+
tcpip_adapter_ip_info_t ip_info;
63+
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip_info) == ESP_OK) {
64+
if (ip_info.gw.addr != 0) {
65+
return IPAddress(ip_info.gw.addr);
66+
}
67+
}
68+
return INADDR_NONE;
69+
#else
3570
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
3671
if (ETH.localIP()[0] != 0) {
3772
return ETH.gatewayIP();
@@ -41,6 +76,7 @@ IPAddress NetworkClass::gatewayIP()
4176
return WiFi.gatewayIP();
4277
}
4378
return INADDR_NONE;
79+
#endif
4480
}
4581

4682
void NetworkClass::localMAC(uint8_t* MAC)
@@ -73,19 +109,34 @@ void NetworkClass::localMAC(uint8_t* MAC)
73109

74110
bool NetworkClass::isConnected()
75111
{
112+
#ifdef WLED_QEMU
113+
// QEMU: Check tcpip_adapter directly since ETH object is not initialized
114+
tcpip_adapter_ip_info_t ip_info;
115+
if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip_info) == ESP_OK) {
116+
if (ip_info.ip.addr != 0) {
117+
return true; // We have an IP from QEMU networking
118+
}
119+
}
120+
return false;
121+
#else
76122
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
77123
return (WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED) || ETH.localIP()[0] != 0;
78124
#else
79125
return (WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED);
80126
#endif
127+
#endif
81128
}
82129

83130
bool NetworkClass::isEthernet()
84131
{
132+
#ifdef WLED_QEMU
133+
return true; // Always ethernet in QEMU mode
134+
#else
85135
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
86136
return (ETH.localIP()[0] != 0);
87137
#endif
88138
return false;
139+
#endif
89140
}
90141

91142
NetworkClass Network;

0 commit comments

Comments
 (0)