Skip to content

Commit 56a0751

Browse files
ethernet lib: fix examples
1 parent 82159aa commit 56a0751

File tree

8 files changed

+72
-33
lines changed

8 files changed

+72
-33
lines changed

libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@
55
to all connected clients but the client the message comes from.
66
To use, telnet to your device's IP address and type.
77
8+
Usage:
9+
1. Upload this sketch to your board.
10+
2. Make sure your board is connected to the network and note its IP address.
11+
3. From a computer on the same network, open a terminal and connect via Telnet:
12+
13+
- On macOS or Linux (using netcat if telnet is not available):
14+
telnet <board_ip> 23
15+
# or, if telnet is missing:
16+
nc <board_ip> 23
17+
18+
- On Windows (Command Prompt):
19+
telnet <board_ip> 23
20+
# If 'telnet' is not recognized, enable it in "Windows Features".
21+
22+
4. Type a message and press Enter.
23+
Your message will be broadcast to all connected clients except you.
24+
25+
Example:
26+
telnet 192.168.1.177 23
27+
28+
Press CTRL + ] then 'quit' to exit Telnet.
29+
830
*/
931

1032
#include "ZephyrServer.h"
@@ -18,23 +40,29 @@ IPAddress myDns(192, 168, 1, 1);
1840
IPAddress gateway(192, 168, 1, 1);
1941
IPAddress subnet(255, 255, 255, 0);
2042

21-
2243
// telnet defaults to port 23
2344
ZephyrServer server(23);
2445

2546
ZephyrClient clients[8];
2647

2748
void setup() {
28-
29-
// initialize the Ethernet device
30-
Ethernet.begin(ip, myDns, gateway, subnet);
31-
32-
// Open serial communications and wait for port to open:
49+
// start serial port:
3350
Serial.begin(9600);
3451
while (!Serial) {
3552
; // wait for serial port to connect. Needed for native USB port only
3653
}
3754

55+
// in Zephyr system check if Ethernet is ready before proceeding to initialize
56+
Serial.print("Waiting for link on");
57+
while (Ethernet.linkStatus() != LinkON) {
58+
Serial.print(".");
59+
delay(100);
60+
}
61+
Serial.println();
62+
63+
// initialize the Ethernet device
64+
Ethernet.begin(ip, myDns, gateway, subnet);
65+
3866
// Check for Ethernet hardware present
3967
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
4068
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");

libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@
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-
1411
Circuit:
1512
SCP1000 sensor attached to pins 6,7, and 11 - 13:
1613
DRDY: pin 6
1714
CSB: pin 7
1815
MOSI: pin 11
1916
MISO: pin 12
2017
SCK: pin 13
21-
18+
19+
How it works:
20+
1. The board reads temperature and pressure data from the SCP1000 sensor.
21+
2. It hosts a simple HTTP server on port 80 that serves the current readings as a web page.
22+
3. You can view the readings from any device on the same network via a browser.
23+
Open a web browser and go to: http://192.168.1.20/ (Replace with your board's IP address if changed)
24+
25+
Note: The SCP1000 sensor is long obsolete. For modern projects, consider replacing it
26+
with the BMP085/BMP180/BMP280 or similar (e.g. https://www.sparkfun.com/products/9721).
2227
*/
2328

2429
#include "ZephyrServer.h"
@@ -53,15 +58,23 @@ void setup() {
5358
// start the SPI library:
5459
SPI.begin();
5560

56-
// start the Ethernet connection
57-
Ethernet.begin(ip);
58-
59-
// Open serial communications and wait for port to open:
61+
// start serial port:
6062
Serial.begin(9600);
6163
while (!Serial) {
6264
; // wait for serial port to connect. Needed for native USB port only
6365
}
6466

67+
// in Zephyr system check if Ethernet is ready before proceeding to initialize
68+
Serial.print("Waiting for link on");
69+
while (Ethernet.linkStatus() != LinkON) {
70+
Serial.print(".");
71+
delay(100);
72+
}
73+
Serial.println();
74+
75+
// start the Ethernet connection
76+
Ethernet.begin(ip);
77+
6578
// Check for Ethernet hardware present
6679
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
6780
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");

libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
void setup()
1313
{
14-
15-
// Open serial communications and wait for port to open:
14+
// start serial port:
1615
Serial.begin(9600);
1716
while (!Serial) {
1817
; // wait for serial port to connect. Needed for native USB port only

libraries/Ethernet/examples/TelnetClient/TelnetClient.ino

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
/*
1+
/*
22
Telnet client
33
4-
This sketch connects to a a telnet server (http://www.google.com)
5-
using an Arduino Wiznet Ethernet shield. You'll need a telnet server
6-
to test this with.
7-
Processing's ChatServer example (part of the network library) works well,
8-
running on port 10002. It can be found as part of the examples
9-
in the Processing application, available at
10-
http://processing.org/
11-
*/
4+
This sketch connects to a telnet server.
5+
You need a telnet server to test this.
6+
*/
127

138
#include "ZephyrClient.h"
149
#include "ZephyrEthernet.h"
1510

1611
// The IP address will be dependent on your local network:
1712
IPAddress ip(192, 168, 1, 177);
1813

14+
// Example: To get the IP address of telehack.com (an example telnet server), run in a terminal:
15+
// ping telehack.com
16+
// or
17+
// nslookup telehack.com
18+
// Then use the returned IP address in the code.
19+
1920
// Enter the IP address of the server you're connecting to:
2021
IPAddress server(1, 1, 1, 1);
22+
int port = 23; // Telnet port
2123

2224
// Initialize the Ethernet client library
2325
// with the IP address and port of the server
@@ -52,7 +54,7 @@ void setup() {
5254
Serial.println("connecting...");
5355

5456
// if you get a connection, report back via serial:
55-
if (client.connect(server, 10002)) {
57+
if (client.connect(server, port)) {
5658
Serial.println("connected");
5759
} else {
5860
// if you didn't get a connection to the server:

libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packe
2424
ZephyrUDP Udp;
2525

2626
void setup() {
27-
2827
// Open serial communications and wait for port to open:
2928
Serial.begin(9600);
3029
while (!Serial) {

libraries/Ethernet/examples/WebClient/WebClient.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ bool printWebData = true; // set to false for better speed measurement
3232

3333
void setup()
3434
{
35-
3635
// Open serial communications and wait for port to open:
3736
Serial.begin(9600);
3837
while (!Serial) {

libraries/Ethernet/examples/WebClientRepeatingManual/WebClientRepeatingManual.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
IPAddress ip(192, 168, 1, 177);
1919
IPAddress myDns(192, 168, 1, 1);
2020
IPAddress gateway(192, 168, 1, 1);
21-
IPAddress subnet(255, 255, 0, 0);
21+
IPAddress subnet(255, 255, 255, 0);
2222

2323
// initialize the library instance:
2424
ZephyrClient client;

libraries/Ethernet/examples/WebServer/WebServer.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/*
22
Web Server
33
4-
A simple web server that shows the value of the analog input pins.
5-
using an Arduino Wiznet Ethernet shield.
6-
4+
A simple web server that shows the value of the analog input pins.
5+
To view the page, open a web browser and type the server’s IP address in the address bar.
76
*/
87

98
#include "ZephyrServer.h"
109
#include "ZephyrClient.h"
1110
#include "ZephyrEthernet.h"
1211

1312
// The IP address will be dependent on your local network:
14-
IPAddress ip(192, 168, 2, 177);
13+
IPAddress ip(192, 168, 1, 177);
1514

1615
// Initialize the Ethernet server library
1716
// with the IP address and port you want to use

0 commit comments

Comments
 (0)