How to detect ethernet link up state

Getting this flicker state

0002407548 [net.en] INFO: Link up
0002407549 [net.ifapi] INFO: Netif en2 link UP, profile=NONE
0002407555 [net.ifapi] INFO: Netif en2 link DOWN, profile=NONE
0002407557 [hal] INFO: DNS server list changed
0002407558 [hal] INFO: DNS server list changed
0002408148 [net.en] INFO: Link up
0002408149 [net.ifapi] INFO: Netif en2 link UP, profile=NONE
0002408156 [net.ifapi] INFO: Netif en2 link DOWN, profile=NONE
0002408157 [hal] INFO: DNS server list changed
0002408158 [hal] INFO: DNS server list changed

It is easily fixable by me calling Ethernet.off(); and reinitializing the ethernet, thought im running into an issue of detecting it, Ethernet.ready() is always returning false. Im not sure if there is a built in particle function to check if the "Link is up" or something like that

I'm not positive what's happening in this log, but I believe it works like this:

  • "Link up" is based on the Wiznet PHY status. It appears to be polled every 500 ms and you get that message when it changes from down to up. There is also "Link down" which you are not getting.
  • In order for the Ethernet interface to be considered fully up you need both PHY and an IP address (DHCP or static).

If you are using Ethernet for your cloud connection, you may able to leverage Particle.connected() instead because in this state even if Ethernet.ready() is true Particle.connect() is probably false.

Ethernet is just being used for local connection, literally plugged from board into another device, maybe also through a switch. Otherwise were using cellular for the particle connection. Im not sure why but occasionally the ethernet fails simultaneously for all connected devices and it prints that log pretty much forever, until i power cycle or have code to restart the ethernet. Issue is its hard to detect the difference between just there being a bad connection for one or more devices, or the ethernet on the board stopping

void setup()
{
  System.enableFeature(FEATURE_RESET_INFO);
  System.enableFeature(FEATURE_ETHERNET_DETECTION);

  // Turn on cellular and connect; this is used for the cloud connection
  Cellular.prefer();
  WiFi.off();
  Cellular.on();
  Cellular.connect();
  waitFor(Cellular.ready, 10000);
  Log.info("Cellular connected");

  ParticleFunctions::setUpFunctions();
  TimingScheduler::setUpTimeZone();
  FaultLight::begin(); // Initialize fault light system

  Particle.connect(); // Connect to the Particle Cloud
}
bool EthernetCommunication::initializeW5500()
{
    if (initialized)
    {
        return true;
    }
    Log.info("Using static IP configuration: %s", sharedLocalIP.toString().c_str());
    IPAddress subnet(255, 255, 255, 0);
    Ethernet.setConfig(NetworkInterfaceConfig()
                           .source(NetworkInterfaceConfigSource::STATIC, AF_INET)
                           .address(sharedLocalIP, subnet)
                           .gateway(IPAddress(0, 0, 0, 0)));
    Ethernet.on();
    waitFor(Ethernet.isOn, 2000);
    Ethernet.connect();

    // Wait for Ethernet to finish connecting and have a valid IP
    if (!waitFor([]
                 { return !Ethernet.connecting() && Ethernet.localIP() != IPAddress(); }, 10000))
    {
        Log.error("Ethernet failed to get IP address");
        return false;
    }

    Log.info("Ethernet initialized successfully");
    String localIPStr = Ethernet.localIP().toString();
    String subnetStr = Ethernet.subnetMask().toString();
    String gatewayStr = Ethernet.gatewayIP().toString();
    String dnsStr = Ethernet.dnsServerIP().toString();

    Log.info("Local IP: %s", localIPStr.c_str());
    Log.info("Subnet: %s", subnetStr.c_str());
    Log.info("Gateway: %s", gatewayStr.c_str());
    Log.info("DNS: %s", dnsStr.c_str());
    initialized = true;
    return true;
}
0002763426 [net.ifapi] INFO: Netif en2 link DOWN, profile=NONE
0002763427 [hal] INFO: DNS server list changed
0002763429 [hal] INFO: DNS server list changed
0002763435 [app] WARN: Write failed: 0 of 7 bytes, error 118
0002763476 [app] WARN: Write failed: 0 of 16 bytes, error 118
0002763518 [app] WARN: Write failed: 0 of 16 bytes, error 118

0002764084 [net.en] INFO: Link up
0002764085 [net.ifapi] INFO: Netif en2 link UP, profile=NONE
0002764092 [net.ifapi] INFO: Netif en2 link DOWN, profile=NONE
0002764094 [hal] INFO: DNS server list changed
0002764095 [hal] INFO: DNS server list changed
0002764770 [net.en] INFO: Link up
0002764771 [net.ifapi] INFO: Netif en2 link UP, profile=NONE
0002764778 [net.ifapi] INFO: Netif en2 link DOWN, profile=NONE
0002764779 [hal] INFO: DNS server list changed
0002764781 [hal] INFO: DNS server list changed

Error 118 means EHOSTUNREACH 118 Host is unreachable why would the ethernet just fail for all three of my connections at once. Ive tried multiple cords at this point so I don't believe its the hardware?