stm32duino / STM32Ethernet

Arduino library to support Ethernet for STM32 based board
156 stars 43 forks source link

Add Ethernet.linkStatus #29

Closed gdsports closed 5 years ago

gdsports commented 5 years ago

Also remove 2 printf debug. Should close #19. Here is the test code.

#include <LwIP.h>
#include <STM32Ethernet.h>

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  Serial.println("Ethernet.linkStatus test");
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  // start the Ethernet connection:
  if (Ethernet.begin() == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for (;;)
      ;
  }
}

void loop () {
  if (Ethernet.linkStatus() == Unknown) {
    Serial.println("Link status unknown.");
  }
  else if (Ethernet.linkStatus() == LinkON) {
    Serial.println("Link status: On");
  }
  else if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Link status: Off");
  }
  delay(250);
}