Skip to content

Commit 9b5b26d

Browse files
committed
Cleaner and disables WiFi when Ethernet gets an IP
1 parent d54c9c4 commit 9b5b26d

File tree

1 file changed

+13
-113
lines changed

1 file changed

+13
-113
lines changed

wled00/network.cpp

Lines changed: 13 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -169,61 +169,22 @@ int getSignalQuality(int rssi)
169169
return quality;
170170
}
171171

172-
const String ARDUINO_EVENT_LIST[41] = {
173-
"WIFI_READY",
174-
"WIFI_SCAN_DONE",
175-
"WIFI_STA_START",
176-
"WIFI_STA_STOP",
177-
"WIFI_STA_CONNECTED",
178-
"WIFI_STA_DISCONNECTED",
179-
"WIFI_STA_AUTHMODE_CHANGE",
180-
"WIFI_STA_GOT_IP",
181-
"WIFI_STA_GOT_IP6",
182-
"WIFI_STA_LOST_IP",
183-
"WIFI_AP_START",
184-
"WIFI_AP_STOP",
185-
"WIFI_AP_STACONNECTED",
186-
"WIFI_AP_STADISCONNECTED",
187-
"WIFI_AP_STAIPASSIGNED",
188-
"WIFI_AP_PROBEREQRECVED",
189-
"WIFI_AP_GOT_IP6",
190-
"WIFI_FTM_REPORT",
191-
"ETH_START",
192-
"ETH_STOP",
193-
"ETH_CONNECTED",
194-
"ETH_DISCONNECTED",
195-
"ETH_GOT_IP",
196-
"ETH_GOT_IP6",
197-
"WPS_ER_SUCCESS",
198-
"WPS_ER_FAILED",
199-
"WPS_ER_TIMEOUT",
200-
"WPS_ER_PIN",
201-
"WPS_ER_PBC_OVERLAP",
202-
"SC_SCAN_DONE",
203-
"SC_FOUND_CHANNEL",
204-
"SC_GOT_SSID_PSWD",
205-
"SC_SEND_ACK_DONE",
206-
"PROV_INIT",
207-
"PROV_DEINIT",
208-
"PROV_START",
209-
"PROV_END",
210-
"PROV_CRED_RECV",
211-
"PROV_CRED_FAIL",
212-
"PROV_CRED_SUCCESS",
213-
"ARDUINO_NETWORK_EVENT_MAX"
214-
};
172+
#if ESP_IDF_VERSION_MAJOR >= 4
173+
#define SYSTEM_EVENT_ETH_CONNECTED ARDUINO_EVENT_ETH_CONNECTED
174+
#define SYSTEM_EVENT_ETH_DISCONNECTED ARDUINO_EVENT_ETH_DISCONNECTED
175+
#define SYSTEM_EVENT_ETH_START ARDUINO_EVENT_ETH_START
176+
#define SYSTEM_EVENT_ETH_GOT_IP ARDUINO_EVENT_ETH_GOT_IP
177+
#endif
215178

216179
//handle Ethernet connection event
217-
void WiFiEvent(WiFiEvent_t event) {
218-
219-
#if ESP32 && ESP_IDF_VERSION_MAJOR >= 4
220-
221-
DEBUG_PRINT(F("Network Event: "));
222-
DEBUG_PRINT(ARDUINO_EVENT_LIST[event]);
223-
DEBUG_PRINT(F(" = "));
224-
180+
void WiFiEvent(WiFiEvent_t event)
181+
{
225182
switch (event) {
226-
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
183+
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
184+
case SYSTEM_EVENT_ETH_START:
185+
DEBUG_PRINTLN(F("ETH Started"));
186+
break;
187+
case SYSTEM_EVENT_ETH_GOT_IP:
227188
if (Network.isEthernet()) {
228189
if (!apActive) {
229190
DEBUG_PRINTLN(F("WiFi Connected *and* ETH Connected. Disabling WIFi"));
@@ -235,67 +196,9 @@ void WiFiEvent(WiFiEvent_t event) {
235196
DEBUG_PRINTLN(F("WiFi Connected. No ETH"));
236197
}
237198
break;
238-
239-
#ifdef WLED_USE_ETHERNET
240-
case ARDUINO_EVENT_ETH_GOT_IP: {
241-
IPAddress localIP = ETH.localIP();
242-
DEBUG_PRINTF("Ethernet has IP %d.%d.%d.%d. ", localIP[0], localIP[1], localIP[2], localIP[3]);
243-
if (!apActive) {
244-
DEBUG_PRINTLN(F("Disabling WIFi."));
245-
WiFi.disconnect(true);
246-
} else {
247-
DEBUG_PRINTLN(F("Leaving AP WiFi Active."));
248-
}
249-
}
250-
break;
251-
252-
case ARDUINO_EVENT_ETH_CONNECTED: {// was SYSTEM_EVENT_ETH_CONNECTED:
253-
DEBUG_PRINTLN(F("ETH connected. Setting up ETH"));
254-
if (multiWiFi[0].staticIP != (uint32_t)0x00000000 && multiWiFi[0].staticGW != (uint32_t)0x00000000) {
255-
ETH.config(multiWiFi[0].staticIP, multiWiFi[0].staticGW, multiWiFi[0].staticSN, dnsAddress);
256-
} else {
257-
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
258-
}
259-
// convert the "serverDescription" into a valid DNS hostname (alphanumeric)
260-
char hostname[64];
261-
prepareHostname(hostname);
262-
ETH.setHostname(hostname);
263-
showWelcomePage = false;
264-
DEBUG_PRINTF("Ethernet link is up. Speed is %u mbit and link is %sfull duplex! (MAC: ", ETH.linkSpeed(), ETH.fullDuplex()?"":"not ");
265-
DEBUG_PRINT(ETH.macAddress());
266-
DEBUG_PRINTLN(")");
267-
}
268-
break;
269-
270-
case ARDUINO_EVENT_ETH_DISCONNECTED: // was SYSTEM_EVENT_ETH_DISCONNECTED:
271-
DEBUG_PRINTLN(F("ETH Disconnected. Forcing reconnect"));
272-
// This doesn't really affect ethernet per se,
273-
// as it's only configured once. Rather, it
274-
// may be necessary to reconnect the WiFi when
275-
// ethernet disconnects, as a way to provide
276-
// alternative access to the device.
277-
forceReconnect = true;
278-
break;
279-
#endif
280-
281-
default:
282-
DEBUG_PRINTLN(F("No action"));
283-
break;
284-
285-
}
286-
#else
287-
288-
switch (event) {
289-
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
290-
case SYSTEM_EVENT_ETH_START:
291-
DEBUG_PRINTLN(F("ETH Started"));
292-
break;
293199
case SYSTEM_EVENT_ETH_CONNECTED:
294200
{
295201
DEBUG_PRINTLN(F("ETH Connected"));
296-
if (!apActive) {
297-
WiFi.disconnect(true);
298-
}
299202
if (multiWiFi[0].staticIP != (uint32_t)0x00000000 && multiWiFi[0].staticGW != (uint32_t)0x00000000) {
300203
ETH.config(multiWiFi[0].staticIP, multiWiFi[0].staticGW, multiWiFi[0].staticSN, dnsAddress);
301204
} else {
@@ -319,9 +222,6 @@ void WiFiEvent(WiFiEvent_t event) {
319222
break;
320223
#endif
321224
default:
322-
DEBUG_PRINTF_P(PSTR("Network event: %d\n"), (int)event);
323225
break;
324226
}
325-
#endif
326227
}
327-

0 commit comments

Comments
 (0)