Skip to content

Commit ac84329

Browse files
Import PaulStoffregen fork as version 2.0.0
1 parent 21b7128 commit ac84329

32 files changed

+3371
-2705
lines changed

examples/AdvancedChatServer/AdvancedChatServer.ino

+12-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ EthernetServer server(23);
4040
EthernetClient clients[4];
4141

4242
void setup() {
43+
// You can use Ethernet.init(pin) to configure the CS pin
44+
//Ethernet.init(10); // Most Arduino shields
45+
//Ethernet.init(5); // MKR ETH shield
46+
//Ethernet.init(0); // Teensy 2.0
47+
//Ethernet.init(20); // Teensy++ 2.0
48+
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
49+
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
50+
4351
// initialize the Ethernet device
4452
Ethernet.begin(mac, ip, myDns, gateway, subnet);
4553
// start listening for clients
@@ -63,7 +71,7 @@ void loop() {
6371
if (client) {
6472

6573
boolean newClient = true;
66-
for (byte i = 0; i < 4; i++) {
74+
for (byte i=0; i < 4; i++) {
6775
//check whether this client refers to the same socket as one of the existing instances:
6876
if (clients[i] == client) {
6977
newClient = false;
@@ -73,7 +81,7 @@ void loop() {
7381

7482
if (newClient) {
7583
//check which of the existing clients can be overridden:
76-
for (byte i = 0; i < 4; i++) {
84+
for (byte i=0; i < 4; i++) {
7785
if (!clients[i] && clients[i] != client) {
7886
clients[i] = client;
7987
// clear out the input buffer:
@@ -91,7 +99,7 @@ void loop() {
9199
// read the bytes incoming from the client:
92100
char thisChar = client.read();
93101
// echo the bytes back to all other connected clients:
94-
for (byte i = 0; i < 4; i++) {
102+
for (byte i=0; i < 4; i++) {
95103
if (clients[i] && (clients[i] != client)) {
96104
clients[i].write(thisChar);
97105
}
@@ -100,7 +108,7 @@ void loop() {
100108
Serial.write(thisChar);
101109
}
102110
}
103-
for (byte i = 0; i < 4; i++) {
111+
for (byte i=0; i < 4 ; i++) {
104112
if (!(clients[i].connected())) {
105113
// client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false;
106114
clients[i].stop();

examples/BarometricPressureWebServer/BarometricPressureWebServer.ino

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
This sketch adapted from Nathan Seidle's SCP1000 example for PIC:
99
http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip
1010
11+
TODO: this hardware is long obsolete. This example program should
12+
be rewritten to use https://www.sparkfun.com/products/9721
13+
1114
Circuit:
1215
SCP1000 sensor attached to pins 6,7, and 11 - 13:
1316
DRDY: pin 6
@@ -55,14 +58,22 @@ long pressure = 0;
5558
long lastReadingTime = 0;
5659

5760
void setup() {
61+
// You can use Ethernet.init(pin) to configure the CS pin
62+
//Ethernet.init(10); // Most Arduino shields
63+
//Ethernet.init(5); // MKR ETH shield
64+
//Ethernet.init(0); // Teensy 2.0
65+
//Ethernet.init(20); // Teensy++ 2.0
66+
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
67+
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
68+
5869
// start the SPI library:
5970
SPI.begin();
6071

6172
// start the Ethernet connection and the server:
6273
Ethernet.begin(mac, ip);
6374
server.begin();
6475

65-
// initalize the data ready and chip select pins:
76+
// initalize the data ready and chip select pins:
6677
pinMode(dataReadyPin, INPUT);
6778
pinMode(chipSelectPin, OUTPUT);
6879

examples/ChatServer/ChatServer.ino

+11-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
// The IP address will be dependent on your local network.
2424
// gateway and subnet are optional:
2525
byte mac[] = {
26-
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
27-
};
26+
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
2827
IPAddress ip(192, 168, 1, 177);
29-
IPAddress myDns(192,168,1, 1);
28+
IPAddress myDns(192, 168, 1, 1);
3029
IPAddress gateway(192, 168, 1, 1);
3130
IPAddress subnet(255, 255, 0, 0);
3231

@@ -36,13 +35,21 @@ EthernetServer server(23);
3635
boolean alreadyConnected = false; // whether or not the client was connected previously
3736

3837
void setup() {
38+
// You can use Ethernet.init(pin) to configure the CS pin
39+
//Ethernet.init(10); // Most Arduino shields
40+
//Ethernet.init(5); // MKR ETH shield
41+
//Ethernet.init(0); // Teensy 2.0
42+
//Ethernet.init(20); // Teensy++ 2.0
43+
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
44+
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
45+
3946
// initialize the ethernet device
4047
Ethernet.begin(mac, ip, myDns, gateway, subnet);
4148
// start listening for clients
4249
server.begin();
4350
// Open serial communications and wait for port to open:
4451
Serial.begin(9600);
45-
while (!Serial) {
52+
while (!Serial) {
4653
; // wait for serial port to connect. Needed for native USB port only
4754
}
4855

examples/DhcpAddressPrinter/DhcpAddressPrinter.ino

+13-21
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
modified 02 Sept 2015
1515
by Arturo Guadalupi
1616
17-
*/
17+
*/
1818

1919
#include <SPI.h>
2020
#include <Ethernet.h>
@@ -25,12 +25,15 @@ byte mac[] = {
2525
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
2626
};
2727

28-
// Initialize the Ethernet client library
29-
// with the IP address and port of the server
30-
// that you want to connect to (port 80 is default for HTTP):
31-
EthernetClient client;
32-
3328
void setup() {
29+
// You can use Ethernet.init(pin) to configure the CS pin
30+
//Ethernet.init(10); // Most Arduino shields
31+
//Ethernet.init(5); // MKR ETH shield
32+
//Ethernet.init(0); // Teensy 2.0
33+
//Ethernet.init(20); // Teensy++ 2.0
34+
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
35+
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
36+
3437
// Open serial communications and wait for port to open:
3538
Serial.begin(9600);
3639
// this check is only needed on the Leonardo:
@@ -39,6 +42,7 @@ void setup() {
3942
}
4043

4144
// start the Ethernet connection:
45+
Serial.println("Initialize Ethernet with DHCP:");
4246
if (Ethernet.begin(mac) == 0) {
4347
Serial.println("Failed to configure Ethernet using DHCP");
4448
// no point in carrying on, so do nothing forevermore:
@@ -50,9 +54,7 @@ void setup() {
5054
}
5155

5256
void loop() {
53-
54-
switch (Ethernet.maintain())
55-
{
57+
switch (Ethernet.maintain()) {
5658
case 1:
5759
//renewed fail
5860
Serial.println("Error: renewed fail");
@@ -61,7 +63,6 @@ void loop() {
6163
case 2:
6264
//renewed success
6365
Serial.println("Renewed success");
64-
6566
//print your local IP address:
6667
printIPAddress();
6768
break;
@@ -74,26 +75,17 @@ void loop() {
7475
case 4:
7576
//rebind success
7677
Serial.println("Rebind success");
77-
7878
//print your local IP address:
7979
printIPAddress();
8080
break;
8181

8282
default:
8383
//nothing happened
8484
break;
85-
8685
}
8786
}
8887

89-
void printIPAddress()
90-
{
88+
void printIPAddress() {
9189
Serial.print("My IP address: ");
92-
for (byte thisByte = 0; thisByte < 4; thisByte++) {
93-
// print the value of each byte of the IP address:
94-
Serial.print(Ethernet.localIP()[thisByte], DEC);
95-
Serial.print(".");
96-
}
97-
98-
Serial.println();
90+
Serial.println(Ethernet.localIP());
9991
}

examples/DhcpChatServer/DhcpChatServer.ino

+10-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ byte mac[] = {
3030
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
3131
};
3232
IPAddress ip(192, 168, 1, 177);
33-
IPAddress myDns(192,168,1, 1);
33+
IPAddress myDns(192, 168, 1, 1);
3434
IPAddress gateway(192, 168, 1, 1);
3535
IPAddress subnet(255, 255, 0, 0);
3636

@@ -39,10 +39,18 @@ EthernetServer server(23);
3939
boolean gotAMessage = false; // whether or not you got a message from the client yet
4040

4141
void setup() {
42+
// You can use Ethernet.init(pin) to configure the CS pin
43+
//Ethernet.init(10); // Most Arduino shields
44+
//Ethernet.init(5); // MKR ETH shield
45+
//Ethernet.init(0); // Teensy 2.0
46+
//Ethernet.init(20); // Teensy++ 2.0
47+
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
48+
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
49+
4250
// Open serial communications and wait for port to open:
4351
Serial.begin(9600);
4452
// this check is only needed on the Leonardo:
45-
while (!Serial) {
53+
while (!Serial) {
4654
; // wait for serial port to connect. Needed for native USB port only
4755
}
4856

examples/LinkStatus/LinkStatus.ino

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Link Status
3+
This sketch prints the ethernet link status. When the
4+
ethernet cable is connected the link status should go to "ON".
5+
NOTE: Only WizNet W5200 and W5500 are capable of reporting
6+
the link status. W5100 will report "Unknown".
7+
Hardware:
8+
- Ethernet shield or equivalent board/shield with WizNet 5200/5500
9+
Written by Cristian Maglie
10+
This example is public domain.
11+
*/
12+
13+
#include <SPI.h>
14+
#include <Ethernet.h>
15+
16+
void setup() {
17+
// You can use Ethernet.init(pin) to configure the CS pin
18+
//Ethernet.init(10); // Most Arduino shields
19+
//Ethernet.init(5); // MKR ETH shield
20+
//Ethernet.init(0); // Teensy 2.0
21+
//Ethernet.init(20); // Teensy++ 2.0
22+
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
23+
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
24+
25+
Serial.begin(9600);
26+
}
27+
28+
void loop() {
29+
auto link = Ethernet.linkStatus();
30+
Serial.print("Link status: ");
31+
switch (link) {
32+
case Unknown:
33+
Serial.println("Unknown");
34+
break;
35+
case LinkON:
36+
Serial.println("ON");
37+
break;
38+
case LinkOFF:
39+
Serial.println("OFF");
40+
break;
41+
}
42+
delay(1000);
43+
}

examples/TelnetClient/TelnetClient.ino

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
created 14 Sep 2010
1616
modified 9 Apr 2012
1717
by Tom Igoe
18-
1918
*/
2019

2120
#include <SPI.h>
@@ -38,6 +37,14 @@ IPAddress server(1, 1, 1, 1);
3837
EthernetClient client;
3938

4039
void setup() {
40+
// You can use Ethernet.init(pin) to configure the CS pin
41+
//Ethernet.init(10); // Most Arduino shields
42+
//Ethernet.init(5); // MKR ETH shield
43+
//Ethernet.init(0); // Teensy 2.0
44+
//Ethernet.init(20); // Teensy++ 2.0
45+
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
46+
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
47+
4148
// start the Ethernet connection:
4249
Ethernet.begin(mac, ip);
4350
// Open serial communications and wait for port to open:

examples/UDPSendReceiveString/UDPSendReceiveString.ino

+11-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,21 @@ IPAddress ip(192, 168, 1, 177);
2828
unsigned int localPort = 8888; // local port to listen on
2929

3030
// buffers for receiving and sending data
31-
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
32-
char ReplyBuffer[] = "acknowledged"; // a string to send back
31+
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet,
32+
char ReplyBuffer[] = "acknowledged"; // a string to send back
3333

3434
// An EthernetUDP instance to let us send and receive packets over UDP
3535
EthernetUDP Udp;
3636

3737
void setup() {
38+
// You can use Ethernet.init(pin) to configure the CS pin
39+
//Ethernet.init(10); // Most Arduino shields
40+
//Ethernet.init(5); // MKR ETH shield
41+
//Ethernet.init(0); // Teensy 2.0
42+
//Ethernet.init(20); // Teensy++ 2.0
43+
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
44+
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
45+
3846
// start the Ethernet and UDP:
3947
Ethernet.begin(mac, ip);
4048
Udp.begin(localPort);
@@ -50,7 +58,7 @@ void loop() {
5058
Serial.println(packetSize);
5159
Serial.print("From ");
5260
IPAddress remote = Udp.remoteIP();
53-
for (int i = 0; i < 4; i++) {
61+
for (int i=0; i < 4; i++) {
5462
Serial.print(remote[i], DEC);
5563
if (i < 3) {
5664
Serial.print(".");

examples/UdpNtpClient/UdpNtpClient.ino

+12-4
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ byte mac[] = {
3030

3131
unsigned int localPort = 8888; // local port to listen for UDP packets
3232

33-
char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server
33+
const char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server
3434

3535
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
3636

37-
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
37+
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
3838

3939
// A UDP instance to let us send and receive packets over UDP
4040
EthernetUDP Udp;
4141

4242
void setup() {
43+
// You can use Ethernet.init(pin) to configure the CS pin
44+
//Ethernet.init(10); // Most Arduino shields
45+
//Ethernet.init(5); // MKR ETH shield
46+
//Ethernet.init(0); // Teensy 2.0
47+
//Ethernet.init(20); // Teensy++ 2.0
48+
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
49+
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
50+
4351
// Open serial communications and wait for port to open:
4452
Serial.begin(9600);
4553
while (!Serial) {
@@ -109,7 +117,7 @@ void loop() {
109117
}
110118

111119
// send an NTP request to the time server at the given address
112-
void sendNTPpacket(char* address) {
120+
void sendNTPpacket(const char * address) {
113121
// set all bytes in the buffer to 0
114122
memset(packetBuffer, 0, NTP_PACKET_SIZE);
115123
// Initialize values needed to form NTP request
@@ -126,7 +134,7 @@ void sendNTPpacket(char* address) {
126134

127135
// all NTP fields have been given values, now
128136
// you can send a packet requesting a timestamp:
129-
Udp.beginPacket(address, 123); //NTP requests are to port 123
137+
Udp.beginPacket(address, 123); // NTP requests are to port 123
130138
Udp.write(packetBuffer, NTP_PACKET_SIZE);
131139
Udp.endPacket();
132140
}

0 commit comments

Comments
 (0)