mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Clean up Ethernet example comments
- Fix typos and formatting. - Remove analog inputs part of Circuit comment in ChatServer and AdvancedChatServer. The examples don't use these analog inputs.
This commit is contained in:
parent
f1d6a0cbed
commit
7f4c29927d
@ -3,13 +3,12 @@
|
|||||||
|
|
||||||
A more advanced server that distributes any incoming messages
|
A more advanced server that distributes any incoming messages
|
||||||
to all connected clients but the client the message comes from.
|
to all connected clients but the client the message comes from.
|
||||||
To use telnet to your device's IP address and type.
|
To use, telnet to your device's IP address and type.
|
||||||
You can see the client's input in the serial monitor as well.
|
You can see the client's input in the serial monitor as well.
|
||||||
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
|
||||||
* Analog inputs attached to pins A0 through A5 (optional)
|
|
||||||
|
|
||||||
created 18 Dec 2009
|
created 18 Dec 2009
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
@ -41,7 +40,7 @@ EthernetServer server(23);
|
|||||||
EthernetClient clients[4];
|
EthernetClient clients[4];
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// initialize the ethernet device
|
// initialize the Ethernet device
|
||||||
Ethernet.begin(mac, ip, myDns, gateway, subnet);
|
Ethernet.begin(mac, ip, myDns, gateway, subnet);
|
||||||
// start listening for clients
|
// start listening for clients
|
||||||
server.begin();
|
server.begin();
|
||||||
@ -77,7 +76,7 @@ void loop() {
|
|||||||
for (byte i = 0; i < 4; i++) {
|
for (byte i = 0; i < 4; i++) {
|
||||||
if (!clients[i] && clients[i] != client) {
|
if (!clients[i] && clients[i] != client) {
|
||||||
clients[i] = client;
|
clients[i] = client;
|
||||||
// clead out the input buffer:
|
// clear out the input buffer:
|
||||||
client.flush();
|
client.flush();
|
||||||
Serial.println("We have a new client");
|
Serial.println("We have a new client");
|
||||||
client.print("Hello, client number: ");
|
client.print("Hello, client number: ");
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
|
||||||
|
|
||||||
// assign a MAC address for the ethernet controller.
|
// assign a MAC address for the Ethernet controller.
|
||||||
// fill in your address here:
|
// fill in your address here:
|
||||||
byte mac[] = {
|
byte mac[] = {
|
||||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
Chat Server
|
Chat Server
|
||||||
|
|
||||||
A simple server that distributes any incoming messages to all
|
A simple server that distributes any incoming messages to all
|
||||||
connected clients. To use telnet to your device's IP address and type.
|
connected clients. To use, telnet to your device's IP address and type.
|
||||||
You can see the client's input in the serial monitor as well.
|
You can see the client's input in the serial monitor as well.
|
||||||
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
|
||||||
* Analog inputs attached to pins A0 through A5 (optional)
|
|
||||||
|
|
||||||
created 18 Dec 2009
|
created 18 Dec 2009
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
@ -59,7 +58,7 @@ void loop() {
|
|||||||
// when the client sends the first byte, say hello:
|
// when the client sends the first byte, say hello:
|
||||||
if (client) {
|
if (client) {
|
||||||
if (!alreadyConnected) {
|
if (!alreadyConnected) {
|
||||||
// clead out the input buffer:
|
// clear out the input buffer:
|
||||||
client.flush();
|
client.flush();
|
||||||
Serial.println("We have a new client");
|
Serial.println("We have a new client");
|
||||||
client.println("Hello, client!");
|
client.println("Hello, client!");
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
DHCP Chat Server
|
DHCP Chat Server
|
||||||
|
|
||||||
A simple server that distributes any incoming messages to all
|
A simple server that distributes any incoming messages to all
|
||||||
connected clients. To use telnet to your device's IP address and type.
|
connected clients. To use, telnet to your device's IP address and type.
|
||||||
You can see the client's input in the serial monitor as well.
|
You can see the client's input in the serial monitor as well.
|
||||||
Using an Arduino Wiznet Ethernet shield.
|
Using an Arduino Wiznet Ethernet shield.
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ void setup() {
|
|||||||
Serial.println("Trying to get an IP address using DHCP");
|
Serial.println("Trying to get an IP address using DHCP");
|
||||||
if (Ethernet.begin(mac) == 0) {
|
if (Ethernet.begin(mac) == 0) {
|
||||||
Serial.println("Failed to configure Ethernet using DHCP");
|
Serial.println("Failed to configure Ethernet using DHCP");
|
||||||
// initialize the ethernet device not using DHCP:
|
// initialize the Ethernet device not using DHCP:
|
||||||
Ethernet.begin(mac, ip, myDns, gateway, subnet);
|
Ethernet.begin(mac, ip, myDns, gateway, subnet);
|
||||||
}
|
}
|
||||||
// print your local IP address:
|
// print your local IP address:
|
||||||
|
@ -34,7 +34,7 @@ IPAddress server(1, 1, 1, 1);
|
|||||||
// Initialize the Ethernet client library
|
// Initialize the Ethernet client library
|
||||||
// with the IP address and port of the server
|
// with the IP address and port of the server
|
||||||
// that you want to connect to (port 23 is default for telnet;
|
// that you want to connect to (port 23 is default for telnet;
|
||||||
// if you're using Processing's ChatServer, use port 10002):
|
// if you're using Processing's ChatServer, use port 10002):
|
||||||
EthernetClient client;
|
EthernetClient client;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
UDPSendReceive.pde:
|
UDPSendReceiveString:
|
||||||
This sketch receives UDP message strings, prints them to the serial port
|
This sketch receives UDP message strings, prints them to the serial port
|
||||||
and sends an "acknowledge" string back to the sender
|
and sends an "acknowledge" string back to the sender
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ IPAddress ip(192, 168, 1, 177);
|
|||||||
unsigned int localPort = 8888; // local port to listen on
|
unsigned int localPort = 8888; // local port to listen on
|
||||||
|
|
||||||
// buffers for receiving and sending data
|
// buffers for receiving and sending data
|
||||||
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
|
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
|
||||||
char ReplyBuffer[] = "acknowledged"; // a string to send back
|
char ReplyBuffer[] = "acknowledged"; // a string to send back
|
||||||
|
|
||||||
// An EthernetUDP instance to let us send and receive packets over UDP
|
// An EthernetUDP instance to let us send and receive packets over UDP
|
||||||
@ -64,7 +64,7 @@ void loop() {
|
|||||||
Serial.println("Contents:");
|
Serial.println("Contents:");
|
||||||
Serial.println(packetBuffer);
|
Serial.println(packetBuffer);
|
||||||
|
|
||||||
// send a reply, to the IP address and port that sent us the packet we received
|
// send a reply to the IP address and port that sent us the packet we received
|
||||||
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
|
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
|
||||||
Udp.write(ReplyBuffer);
|
Udp.write(ReplyBuffer);
|
||||||
Udp.endPacket();
|
Udp.endPacket();
|
||||||
|
@ -66,8 +66,8 @@ void loop() {
|
|||||||
// We've received a packet, read the data from it
|
// We've received a packet, read the data from it
|
||||||
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
|
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
|
||||||
|
|
||||||
//the timestamp starts at byte 40 of the received packet and is four bytes,
|
// the timestamp starts at byte 40 of the received packet and is four bytes,
|
||||||
// or two words, long. First, esxtract the two words:
|
// or two words, long. First, extract the two words:
|
||||||
|
|
||||||
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
|
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
|
||||||
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
|
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
|
||||||
|
@ -43,7 +43,6 @@ void setup() {
|
|||||||
// start the Ethernet connection:
|
// start the Ethernet connection:
|
||||||
if (Ethernet.begin(mac) == 0) {
|
if (Ethernet.begin(mac) == 0) {
|
||||||
Serial.println("Failed to configure Ethernet using DHCP");
|
Serial.println("Failed to configure Ethernet using DHCP");
|
||||||
// no point in carrying on, so do nothing forevermore:
|
|
||||||
// try to congifure using IP address instead of DHCP:
|
// try to congifure using IP address instead of DHCP:
|
||||||
Ethernet.begin(mac, ip);
|
Ethernet.begin(mac, ip);
|
||||||
}
|
}
|
||||||
@ -60,7 +59,7 @@ void setup() {
|
|||||||
client.println("Connection: close");
|
client.println("Connection: close");
|
||||||
client.println();
|
client.println();
|
||||||
} else {
|
} else {
|
||||||
// kf you didn't get a connection to the server:
|
// if you didn't get a connection to the server:
|
||||||
Serial.println("connection failed");
|
Serial.println("connection failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user