-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ethernet Support
- Loading branch information
Showing
9 changed files
with
191 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "Network.h" | ||
|
||
IPAddress NetworkClass::localIP() | ||
{ | ||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET) | ||
if (ETH.localIP()[0] != 0) { | ||
return ETH.localIP(); | ||
} | ||
#endif | ||
if (WiFi.localIP()[0] != 0) { | ||
return WiFi.localIP(); | ||
} | ||
return INADDR_NONE; | ||
} | ||
|
||
IPAddress NetworkClass::subnetMask() | ||
{ | ||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET) | ||
if (ETH.localIP()[0] != 0) { | ||
return ETH.subnetMask(); | ||
} | ||
#endif | ||
if (WiFi.localIP()[0] != 0) { | ||
return WiFi.subnetMask(); | ||
} | ||
return IPAddress(255, 255, 255, 0); | ||
} | ||
|
||
IPAddress NetworkClass::gatewayIP() | ||
{ | ||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET) | ||
if (ETH.localIP()[0] != 0) { | ||
return ETH.gatewayIP(); | ||
} | ||
#endif | ||
if (WiFi.localIP()[0] != 0) { | ||
return WiFi.gatewayIP(); | ||
} | ||
return INADDR_NONE; | ||
} | ||
|
||
bool NetworkClass::isConnected() | ||
{ | ||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET) | ||
return (WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED) || ETH.localIP()[0] != 0; | ||
#else | ||
return (WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED); | ||
#endif | ||
} | ||
|
||
bool NetworkClass::isEthernet() | ||
{ | ||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET) | ||
return (ETH.localIP()[0] != 0); | ||
#endif | ||
return false; | ||
} | ||
|
||
NetworkClass Network; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifdef ESP8266 | ||
#include <ESP8266WiFi.h> | ||
#else // ESP32 | ||
#include <WiFi.h> | ||
#include <ETH.h> | ||
#endif | ||
|
||
#ifndef Network_h | ||
#define Network_h | ||
|
||
class NetworkClass | ||
{ | ||
public: | ||
IPAddress localIP(); | ||
IPAddress subnetMask(); | ||
IPAddress gatewayIP(); | ||
bool isConnected(); | ||
bool isEthernet(); | ||
}; | ||
|
||
extern NetworkClass Network; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters