Skip to content

Commit ca7d22e

Browse files
committed
Merge pull request #3761 from agdl/EthernetMaintainImprovement
Added Ethernet.maintain() to examples
2 parents e9ffe05 + 3f28c24 commit ca7d22e

File tree

4 files changed

+63
-15
lines changed

4 files changed

+63
-15
lines changed

libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
/*
22
DHCP-based IP printer
33
4-
This sketch uses the DHCP extensions to the Ethernet library
5-
to get an IP address via DHCP and print the address obtained.
6-
using an Arduino Wiznet Ethernet shield.
4+
This sketch uses the DHCP extensions to the Ethernet library
5+
to get an IP address via DHCP and print the address obtained.
6+
using an Arduino Wiznet Ethernet shield.
77
8-
Circuit:
9-
* Ethernet shield attached to pins 10, 11, 12, 13
8+
Circuit:
9+
Ethernet shield attached to pins 10, 11, 12, 13
1010
11-
created 12 April 2011
12-
modified 9 Apr 2012
13-
by Tom Igoe
11+
created 12 April 2011
12+
modified 9 Apr 2012
13+
by Tom Igoe
14+
modified 02 Sept 2015
15+
by Arturo Guadalupi
1416
15-
*/
17+
*/
1618

1719
#include <SPI.h>
1820
#include <Ethernet.h>
@@ -44,17 +46,54 @@ void setup() {
4446
;
4547
}
4648
// print your local IP address:
49+
printIPAddress();
50+
}
51+
52+
void loop() {
53+
54+
switch (Ethernet.maintain())
55+
{
56+
case 1:
57+
//renewed fail
58+
Serial.println("Error: renewed fail");
59+
break;
60+
61+
case 2:
62+
//renewed success
63+
Serial.println("Renewed success");
64+
65+
//print your local IP address:
66+
printIPAddress();
67+
break;
68+
69+
case 3:
70+
//rebind fail
71+
Serial.println("Error: rebind fail");
72+
break;
73+
74+
case 4:
75+
//rebind success
76+
Serial.println("Rebind success");
77+
78+
//print your local IP address:
79+
printIPAddress();
80+
break;
81+
82+
default:
83+
//nothing happened
84+
break;
85+
86+
}
87+
}
88+
89+
void printIPAddress()
90+
{
4791
Serial.print("My IP address: ");
4892
for (byte thisByte = 0; thisByte < 4; thisByte++) {
4993
// print the value of each byte of the IP address:
5094
Serial.print(Ethernet.localIP()[thisByte], DEC);
5195
Serial.print(".");
5296
}
53-
Serial.println();
54-
}
55-
56-
void loop() {
5797

98+
Serial.println();
5899
}
59-
60-

libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
created 21 May 2011
1515
modified 9 Apr 2012
1616
by Tom Igoe
17+
modified 02 Sept 2015
18+
by Arturo Guadalupi
1719
Based on ChatServer example by David A. Mellis
1820
1921
*/
@@ -83,6 +85,7 @@ void loop() {
8385
server.write(thisChar);
8486
// echo the bytes to the server as well:
8587
Serial.print(thisChar);
88+
Ethernet.maintain();
8689
}
8790
}
8891

libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
by Michael Margolis
1212
modified 9 Apr 2012
1313
by Tom Igoe
14+
modified 02 Sept 2015
15+
by Arturo Guadalupi
1416
1517
This code is in the public domain.
1618
@@ -103,6 +105,7 @@ void loop() {
103105
}
104106
// wait ten seconds before asking for the time again
105107
delay(10000);
108+
Ethernet.maintain();
106109
}
107110

108111
// send an NTP request to the time server at the given address

libraries/Ethernet/examples/WebServer/WebServer.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
by David A. Mellis
1313
modified 9 Apr 2012
1414
by Tom Igoe
15+
modified 02 Sept 2015
16+
by Arturo Guadalupi
1517
1618
*/
1719

@@ -95,6 +97,7 @@ void loop() {
9597
// close the connection:
9698
client.stop();
9799
Serial.println("client disconnected");
100+
Ethernet.maintain();
98101
}
99102
}
100103

0 commit comments

Comments
 (0)