-
Notifications
You must be signed in to change notification settings - Fork 30
Examples
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>
.
In PagerServer, ChatServer and DhcpChatServer examples please use EthernetServerPrint server(23)
. EthernetServer in EthernetENC library doesn't support writing to all clients because it takes flash and RAM and has little use. This function is only in EthernetServerPrint class.
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.
In UDPSendReceiveString example add #define UDP_TX_PACKET_MAX_SIZE 256
.
To have a nicer WebClient example you can replace server to "arduino.tips" 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.");
}
}
You can check with client.getWriteError() if EthernetClient could write the printed data:
while (file.available()) {
client.write(file.read());
if (client.getWriteError()) {
Serial.println("Write error");
break;
}
}