Skip to content

Commit b04124a

Browse files
committed
Update examples
1 parent d1501d0 commit b04124a

File tree

13 files changed

+207
-266
lines changed

13 files changed

+207
-266
lines changed

libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@
2020
*/
2121

2222
#include <SPI.h>
23+
#include <PortentaEthernet.h>
2324
#include <Ethernet.h>
2425

25-
// Enter a MAC address and IP address for your controller below.
2626
// The IP address will be dependent on your local network.
2727
// gateway and subnet are optional:
28-
byte mac[] = {
29-
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
30-
};
3128
IPAddress ip(192, 168, 1, 177);
3229
IPAddress myDns(192, 168, 1, 1);
3330
IPAddress gateway(192, 168, 1, 1);
34-
IPAddress subnet(255, 255, 0, 0);
31+
IPAddress subnet(255, 255, 255, 0);
3532

3633

3734
// telnet defaults to port 23
@@ -40,16 +37,9 @@ EthernetServer server(23);
4037
EthernetClient clients[8];
4138

4239
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
5040

5141
// initialize the Ethernet device
52-
Ethernet.begin(mac, ip, myDns, gateway, subnet);
42+
Ethernet.begin(ip, myDns, gateway, subnet);
5343

5444
// Open serial communications and wait for port to open:
5545
Serial.begin(9600);
@@ -77,7 +67,7 @@ void setup() {
7767

7868
void loop() {
7969
// check for any new client connecting, and say hello (before any incoming data)
80-
EthernetClient newClient = server.accept();
70+
EthernetClient newClient = server.available();
8171
if (newClient) {
8272
for (byte i=0; i < 8; i++) {
8373
if (!clients[i]) {

libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@
2323
by Tom Igoe
2424
*/
2525

26+
#include <PortentaEthernet.h>
2627
#include <Ethernet.h>
2728
// the sensor communicates using SPI, so include the library:
2829
#include <SPI.h>
2930

3031

31-
// assign a MAC address for the Ethernet controller.
32-
// fill in your address here:
33-
byte mac[] = {
34-
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
35-
};
3632
// assign an IP address for the controller:
3733
IPAddress ip(192, 168, 1, 20);
3834

@@ -58,19 +54,12 @@ long pressure = 0;
5854
long lastReadingTime = 0;
5955

6056
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
6857

6958
// start the SPI library:
7059
SPI.begin();
7160

7261
// start the Ethernet connection
73-
Ethernet.begin(mac, ip);
62+
Ethernet.begin(ip);
7463

7564
// Open serial communications and wait for port to open:
7665
Serial.begin(9600);

libraries/Ethernet/examples/ChatServer/ChatServer.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
*/
1818

1919
#include <SPI.h>
20+
#include <PortentaEthernet.h>
2021
#include <Ethernet.h>
2122

22-
// Enter a MAC address and IP address for your controller below.
2323
// The IP address will be dependent on your local network.
2424
// gateway and subnet are optional:
25-
byte mac[] = {
26-
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
2725
IPAddress ip(192, 168, 1, 177);
2826
IPAddress myDns(192, 168, 1, 1);
2927
IPAddress gateway(192, 168, 1, 1);
@@ -44,7 +42,7 @@ void setup() {
4442
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
4543

4644
// initialize the ethernet device
47-
Ethernet.begin(mac, ip, myDns, gateway, subnet);
45+
Ethernet.begin(ip, myDns, gateway, subnet);
4846

4947
// Open serial communications and wait for port to open:
5048
Serial.begin(9600);

libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino

Lines changed: 54 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,80 +16,67 @@
1616
1717
*/
1818

19-
#include <SPI.h>
2019
#include <Ethernet.h>
20+
#include <PortentaEthernet.h>
21+
#include <SPI.h>
2122

22-
// Enter a MAC address for your controller below.
23-
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
24-
byte mac[] = {
25-
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
26-
};
27-
28-
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-
37-
// Open serial communications and wait for port to open:
38-
Serial.begin(9600);
39-
while (!Serial) {
40-
; // wait for serial port to connect. Needed for native USB port only
41-
}
23+
void setup()
24+
{
4225

43-
// start the Ethernet connection:
44-
Serial.println("Initialize Ethernet with DHCP:");
45-
if (Ethernet.begin(mac) == 0) {
46-
Serial.println("Failed to configure Ethernet using DHCP");
47-
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
48-
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
49-
} else if (Ethernet.linkStatus() == LinkOFF) {
50-
Serial.println("Ethernet cable is not connected.");
26+
// Open serial communications and wait for port to open:
27+
Serial.begin(9600);
28+
while (!Serial) {
29+
; // wait for serial port to connect. Needed for native USB port only
5130
}
52-
// no point in carrying on, so do nothing forevermore:
53-
while (true) {
54-
delay(1);
31+
32+
// start the Ethernet connection:
33+
Serial.println("Initialize Ethernet with DHCP:");
34+
if (Ethernet.begin() == 0) {
35+
Serial.println("Failed to configure Ethernet using DHCP");
36+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
37+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
38+
} else if (Ethernet.linkStatus() == LinkOFF) {
39+
Serial.println("Ethernet cable is not connected.");
40+
}
41+
// no point in carrying on, so do nothing forevermore:
42+
while (true) {
43+
delay(1);
44+
}
5545
}
56-
}
57-
// print your local IP address:
58-
Serial.print("My IP address: ");
59-
Serial.println(Ethernet.localIP());
46+
// print your local IP address:
47+
Serial.print("My IP address: ");
48+
Serial.println(Ethernet.localIP());
6049
}
6150

62-
void loop() {
63-
switch (Ethernet.maintain()) {
64-
case 1:
65-
//renewed fail
66-
Serial.println("Error: renewed fail");
67-
break;
68-
69-
case 2:
70-
//renewed success
71-
Serial.println("Renewed success");
72-
//print your local IP address:
73-
Serial.print("My IP address: ");
74-
Serial.println(Ethernet.localIP());
75-
break;
76-
77-
case 3:
78-
//rebind fail
79-
Serial.println("Error: rebind fail");
80-
break;
51+
void loop()
52+
{
53+
if (Ethernet.status() != 0) {
54+
Serial.println(Ethernet.status());
55+
connectEth();
56+
}
57+
}
8158

82-
case 4:
83-
//rebind success
84-
Serial.println("Rebind success");
85-
//print your local IP address:
86-
Serial.print("My IP address: ");
87-
Serial.println(Ethernet.localIP());
88-
break;
59+
void connectEth()
60+
{
61+
// start the Ethernet connection:
62+
Serial.println("Initialize Ethernet with DHCP:");
63+
if (Ethernet.begin() == 0) {
64+
Serial.println("Failed to configure Ethernet using DHCP");
65+
// Check for Ethernet hardware present
66+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
67+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
68+
while (true) {
69+
delay(1); // do nothing, no point running without Ethernet hardware
70+
}
71+
}
72+
if (Ethernet.linkStatus() == LinkOFF) {
73+
Serial.println("Ethernet cable is not connected.");
74+
}
75+
} else {
76+
Serial.print(" DHCP assigned IP ");
77+
Serial.println(Ethernet.localIP());
78+
}
8979

90-
default:
91-
//nothing happened
92-
break;
93-
}
80+
Serial.println("You're connected to the network");
81+
Serial.println();
9482
}
95-

libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@
2121
*/
2222

2323
#include <SPI.h>
24+
#include <PortentaEthernet.h>
2425
#include <Ethernet.h>
2526

26-
// Enter a MAC address and IP address for your controller below.
2727
// The IP address will be dependent on your local network.
2828
// gateway and subnet are optional:
29-
byte mac[] = {
30-
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
31-
};
3229
IPAddress ip(192, 168, 1, 177);
3330
IPAddress myDns(192, 168, 1, 1);
3431
IPAddress gateway(192, 168, 1, 1);
@@ -39,13 +36,6 @@ EthernetServer server(23);
3936
boolean gotAMessage = false; // whether or not you got a message from the client yet
4037

4138
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
4939

5040
// Open serial communications and wait for port to open:
5141
Serial.begin(9600);
@@ -55,7 +45,7 @@ void setup() {
5545

5646
// start the Ethernet connection:
5747
Serial.println("Trying to get an IP address using DHCP");
58-
if (Ethernet.begin(mac) == 0) {
48+
if (Ethernet.begin() == 0) {
5949
Serial.println("Failed to configure Ethernet using DHCP");
6050
// Check for Ethernet hardware present
6151
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
@@ -68,7 +58,7 @@ void setup() {
6858
Serial.println("Ethernet cable is not connected.");
6959
}
7060
// initialize the Ethernet device not using DHCP:
71-
Ethernet.begin(mac, ip, myDns, gateway, subnet);
61+
Ethernet.begin(ip, myDns, gateway, subnet);
7262
}
7363
// print your local IP address:
7464
Serial.print("My IP address: ");
@@ -96,7 +86,6 @@ void loop() {
9686
server.write(thisChar);
9787
// echo the bytes to the server as well:
9888
Serial.print(thisChar);
99-
Ethernet.maintain();
10089
}
10190
}
10291

libraries/Ethernet/examples/LinkStatus/LinkStatus.ino

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@
1111
*/
1212

1313
#include <SPI.h>
14+
#include <PortentaEthernet.h>
1415
#include <Ethernet.h>
1516

1617
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-
2518
Serial.begin(9600);
2619
}
2720

libraries/Ethernet/examples/TelnetClient/TelnetClient.ino

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@
1818
*/
1919

2020
#include <SPI.h>
21+
#include <PortentaEthernet.h>
2122
#include <Ethernet.h>
2223

23-
// Enter a MAC address and IP address for your controller below.
2424
// The IP address will be dependent on your local network:
25-
byte mac[] = {
26-
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
27-
};
2825
IPAddress ip(192, 168, 1, 177);
2926

3027
// Enter the IP address of the server you're connecting to:
@@ -37,16 +34,9 @@ IPAddress server(1, 1, 1, 1);
3734
EthernetClient client;
3835

3936
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
4737

4838
// start the Ethernet connection:
49-
Ethernet.begin(mac, ip);
39+
Ethernet.begin(ip);
5040

5141
// Open serial communications and wait for port to open:
5242
Serial.begin(9600);

libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
This code is in the public domain.
1313
*/
1414

15-
15+
#include <PortentaEthernet.h>
1616
#include <Ethernet.h>
1717
#include <EthernetUdp.h>
1818

19-
// Enter a MAC address and IP address for your controller below.
2019
// The IP address will be dependent on your local network:
21-
byte mac[] = {
22-
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
23-
};
2420
IPAddress ip(192, 168, 1, 177);
2521

2622
unsigned int localPort = 8888; // local port to listen on
@@ -33,16 +29,9 @@ char ReplyBuffer[] = "acknowledged"; // a string to send back
3329
EthernetUDP Udp;
3430

3531
void setup() {
36-
// You can use Ethernet.init(pin) to configure the CS pin
37-
//Ethernet.init(10); // Most Arduino shields
38-
//Ethernet.init(5); // MKR ETH shield
39-
//Ethernet.init(0); // Teensy 2.0
40-
//Ethernet.init(20); // Teensy++ 2.0
41-
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
42-
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
4332

4433
// start the Ethernet
45-
Ethernet.begin(mac, ip);
34+
Ethernet.begin(ip);
4635

4736
// Open serial communications and wait for port to open:
4837
Serial.begin(9600);

0 commit comments

Comments
 (0)