This example program shows the various combinations that are possible and how to detect them:
#include "Particle.h"
SerialLogHandler logHandler;
SYSTEM_THREAD(ENABLED);
const unsigned long CHECK_INTERVAL = 5000;
unsigned long lastCheck = 0;
void setup() {
Serial.begin();
}
void loop() {
if (millis() - lastCheck >= CHECK_INTERVAL) {
lastCheck = millis();
#if Wiring_Ethernet
Log.info("this device could have Ethernet (is 3rd generation)");
if (System.featureEnabled(FEATURE_ETHERNET_DETECTION)) {
Log.info("FEATURE_ETHERNET_DETECTION enabled");
if (Ethernet.ready()) {
Log.info("Ethernet ready (has link and IP address %s)", Ethernet.localIP().toString().c_str());
}
else {
uint8_t mac[6];
if (Ethernet.macAddress(mac) != 0) {
Log.info("Ethernet present but not ready");
}
else {
// the macAddress function returns 0 if there is no Ethernet adapter present
Log.info("Ethernet detection enabled, but no Ethernet present");
}
}
}
else {
Log.info("FEATURE_ETHERNET_DETECTION not enabled, so Ethernet will not be used (even if present)");
}
#else
Log.info("no Ethernet (1st or 2nd generation device)");
#endif
}
}