1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Added Ethernet.maintain() to examples

According to #3634 I added the Ethernet.maintain to examples:
Webserver
UdpNtpClient
DhcpChatServer
DhcpAddressPrinter
This commit is contained in:
Arturo Guadalupi 2015-09-02 10:07:14 +02:00
parent f8b764a3a6
commit 3f28c2452a
4 changed files with 63 additions and 15 deletions

View File

@ -6,13 +6,15 @@
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
Ethernet shield attached to pins 10, 11, 12, 13
created 12 April 2011
modified 9 Apr 2012
by Tom Igoe
modified 02 Sept 2015
by Arturo Guadalupi
*/
*/
#include <SPI.h>
#include <Ethernet.h>
@ -44,17 +46,54 @@ void setup() {
;
}
// print your local IP address:
printIPAddress();
}
void loop() {
switch (Ethernet.maintain())
{
case 1:
//renewed fail
Serial.println("Error: renewed fail");
break;
case 2:
//renewed success
Serial.println("Renewed success");
//print your local IP address:
printIPAddress();
break;
case 3:
//rebind fail
Serial.println("Error: rebind fail");
break;
case 4:
//rebind success
Serial.println("Rebind success");
//print your local IP address:
printIPAddress();
break;
default:
//nothing happened
break;
}
}
void printIPAddress()
{
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
void loop() {
}

View File

@ -14,6 +14,8 @@
created 21 May 2011
modified 9 Apr 2012
by Tom Igoe
modified 02 Sept 2015
by Arturo Guadalupi
Based on ChatServer example by David A. Mellis
*/
@ -83,6 +85,7 @@ void loop() {
server.write(thisChar);
// echo the bytes to the server as well:
Serial.print(thisChar);
Ethernet.maintain();
}
}

View File

@ -11,6 +11,8 @@
by Michael Margolis
modified 9 Apr 2012
by Tom Igoe
modified 02 Sept 2015
by Arturo Guadalupi
This code is in the public domain.
@ -103,6 +105,7 @@ void loop() {
}
// wait ten seconds before asking for the time again
delay(10000);
Ethernet.maintain();
}
// send an NTP request to the time server at the given address

View File

@ -12,6 +12,8 @@
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 02 Sept 2015
by Arturo Guadalupi
*/
@ -95,6 +97,7 @@ void loop() {
// close the connection:
client.stop();
Serial.println("client disconnected");
Ethernet.maintain();
}
}