Skip to content

Examples

Juraj Andrassy edited this page Aug 31, 2020 · 7 revisions

The EthernetENC library doesn't have examples, because examples of the Arduino Ethernet library apply. You can find them in the Arduino IDE Examples menu Ethernet section. Only change #include <Ethernet.h> to #include <EthernetENC.h>.

EthernetServer in EthernetENC library doesn't support writing to all clients. In the ChatServer examples please change server.write to client.write.

If you use Linux telnet client to communicate with the ChatServer examples, change the port to 2323. The Linux telnet client attempts to negotiate the connection settings with the server. This is not a problem of the EthernetENC library.

The LinkStatus example will not work without Ethernet.begin(mac, ip).

In UDPSendReceiveString example add #define UDP_TX_PACKET_MAX_SIZE 256.

To have a nicer WebClient example you can replace server to "arduino.cc" and GET and Host string print with

    client.println("GET /asciilogo.txt HTTP/1.1");
    client.print("Host: ");
    client.println(server);

EthernetENC must handle all network traffic targeted to its MAC address and some broadcast packets too. EthernetENC uses every function of the library to do this. If your sketch doesn't call the functions of the library all the time (like with server.available() or client.available()), then put Ethernet.maintain(); as first in loop(). If you use DHCP it should be there anyway for the IP lease renewal.

If your sketch has many or long delays with delay() function, then you should write your own delay function which will call Ethernet.maintain()

void mDelay(unsigned long milliseconds) {
  const unsigned d = 1;
  while (milliseconds > d) {
    Ethernet.maintain();
    delay(d);
    milliseconds -= d;
  }
  Ethernet.maintain();
  delay(milliseconds);
}

If the Ethernet.linkStatus() is invoked too soon, it may return LinkOFF. You can do the check in setup() this way:

  if (Ethernet.linkStatus() == LinkOFF) {
    delay(500);
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
  }
Clone this wiki locally