mirror of
https://github.com/arduino/Arduino.git
synced 2025-04-06 21:57:57 +02: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:
parent
f8b764a3a6
commit
3f28c2452a
@ -1,18 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
DHCP-based IP printer
|
DHCP-based IP printer
|
||||||
|
|
||||||
This sketch uses the DHCP extensions to the Ethernet library
|
This sketch uses the DHCP extensions to the Ethernet library
|
||||||
to get an IP address via DHCP and print the address obtained.
|
to get an IP address via DHCP and print the address obtained.
|
||||||
using an Arduino Wiznet Ethernet shield.
|
using an Arduino Wiznet Ethernet shield.
|
||||||
|
|
||||||
Circuit:
|
Circuit:
|
||||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
Ethernet shield attached to pins 10, 11, 12, 13
|
||||||
|
|
||||||
created 12 April 2011
|
created 12 April 2011
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
modified 02 Sept 2015
|
||||||
|
by Arturo Guadalupi
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
@ -44,17 +46,54 @@ void setup() {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
// print your local IP address:
|
// 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: ");
|
Serial.print("My IP address: ");
|
||||||
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
||||||
// print the value of each byte of the IP address:
|
// print the value of each byte of the IP address:
|
||||||
Serial.print(Ethernet.localIP()[thisByte], DEC);
|
Serial.print(Ethernet.localIP()[thisByte], DEC);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
created 21 May 2011
|
created 21 May 2011
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
modified 02 Sept 2015
|
||||||
|
by Arturo Guadalupi
|
||||||
Based on ChatServer example by David A. Mellis
|
Based on ChatServer example by David A. Mellis
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@ -83,6 +85,7 @@ void loop() {
|
|||||||
server.write(thisChar);
|
server.write(thisChar);
|
||||||
// echo the bytes to the server as well:
|
// echo the bytes to the server as well:
|
||||||
Serial.print(thisChar);
|
Serial.print(thisChar);
|
||||||
|
Ethernet.maintain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
by Michael Margolis
|
by Michael Margolis
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
modified 02 Sept 2015
|
||||||
|
by Arturo Guadalupi
|
||||||
|
|
||||||
This code is in the public domain.
|
This code is in the public domain.
|
||||||
|
|
||||||
@ -103,6 +105,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
// wait ten seconds before asking for the time again
|
// wait ten seconds before asking for the time again
|
||||||
delay(10000);
|
delay(10000);
|
||||||
|
Ethernet.maintain();
|
||||||
}
|
}
|
||||||
|
|
||||||
// send an NTP request to the time server at the given address
|
// send an NTP request to the time server at the given address
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
modified 02 Sept 2015
|
||||||
|
by Arturo Guadalupi
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -95,6 +97,7 @@ void loop() {
|
|||||||
// close the connection:
|
// close the connection:
|
||||||
client.stop();
|
client.stop();
|
||||||
Serial.println("client disconnected");
|
Serial.println("client disconnected");
|
||||||
|
Ethernet.maintain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user