Skip to content

Commit 55e9c3d

Browse files
committed
IDF v4 Ethernet Fixes
1 parent a244910 commit 55e9c3d

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

wled00/network.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ int getSignalQuality(int rssi)
161161
return quality;
162162
}
163163

164+
#if ESP_IDF_VERSION_MAJOR >= 4
165+
#define SYSTEM_EVENT_ETH_CONNECTED ARDUINO_EVENT_ETH_CONNECTED
166+
#define SYSTEM_EVENT_ETH_DISCONNECTED ARDUINO_EVENT_ETH_DISCONNECTED
167+
#define SYSTEM_EVENT_ETH_START ARDUINO_EVENT_ETH_START
168+
#define SYSTEM_EVENT_ETH_GOT_IP ARDUINO_EVENT_ETH_GOT_IP
169+
#endif
164170

165171
//handle Ethernet connection event
166172
void WiFiEvent(WiFiEvent_t event)
@@ -170,12 +176,21 @@ void WiFiEvent(WiFiEvent_t event)
170176
case SYSTEM_EVENT_ETH_START:
171177
DEBUG_PRINTLN(F("ETH Started"));
172178
break;
179+
case SYSTEM_EVENT_ETH_GOT_IP:
180+
if (Network.isEthernet()) {
181+
if (!apActive) {
182+
DEBUG_PRINTLN(F("WiFi Connected *and* ETH Connected. Disabling WIFi"));
183+
WiFi.disconnect(true);
184+
} else {
185+
DEBUG_PRINTLN(F("WiFi Connected *and* ETH Connected. Leaving AP WiFi active"));
186+
}
187+
} else {
188+
DEBUG_PRINTLN(F("WiFi Connected. No ETH"));
189+
}
190+
break;
173191
case SYSTEM_EVENT_ETH_CONNECTED:
174192
{
175193
DEBUG_PRINTLN(F("ETH Connected"));
176-
if (!apActive) {
177-
WiFi.disconnect(true);
178-
}
179194
if (staticIP != (uint32_t)0x00000000 && staticGateway != (uint32_t)0x00000000) {
180195
ETH.config(staticIP, staticGateway, staticSubnet, IPAddress(8, 8, 8, 8));
181196
} else {

wled00/wled.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,16 +1370,15 @@ void WLED::handleConnection()
13701370
} else if (!interfacesInited) { //newly connected
13711371
USER_PRINTLN("");
13721372
USER_PRINT(F("Connected! IP address: http://"));
1373-
USER_PRINTLN(Network.localIP());
1374-
//if (Network.isEthernet()) {
1375-
// #if ESP32
1376-
// USER_PRINT(ETH.localIP());
1377-
// USER_PRINTLN(" via Ethernet");
1378-
// #endif
1379-
//} else {
1380-
// USER_PRINT(Network.localIP());
1381-
// USER_PRINTLN(" via WiFi");
1382-
//}
1373+
USER_PRINT(Network.localIP());
1374+
if (Network.isEthernet()) {
1375+
#if ESP32
1376+
USER_PRINTLN(" via Ethernet (disabling WiFi)");
1377+
WiFi.disconnect(true);
1378+
#endif
1379+
} else {
1380+
USER_PRINTLN(" via WiFi");
1381+
}
13831382

13841383
if (improvActive) {
13851384
if (improvError == 3) sendImprovStateResponse(0x00, true);

0 commit comments

Comments
 (0)