aboutsummaryrefslogtreecommitdiff
path: root/libraries/Ethernet/examples
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/Ethernet/examples')
-rw-r--r--libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino (renamed from libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.pde)8
-rw-r--r--libraries/Ethernet/examples/ChatServer/ChatServer.ino (renamed from libraries/Ethernet/examples/ChatServer/ChatServer.pde)4
-rw-r--r--libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino (renamed from libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.pde)2
-rw-r--r--libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino80
-rw-r--r--libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino (renamed from libraries/Ethernet/examples/DnsWebClient/DnsWebClient.pde)2
-rw-r--r--libraries/Ethernet/examples/PachubeClient/PachubeClient.ino (renamed from libraries/Ethernet/examples/PachubeClient/PachubeClient.pde)13
-rw-r--r--libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino (renamed from libraries/Ethernet/examples/PachubeClientString/PachubeClientString.pde)19
-rw-r--r--libraries/Ethernet/examples/TelnetClient/TelnetClient.ino (renamed from libraries/Ethernet/examples/TelnetClient/TelnetClient.pde)2
-rw-r--r--libraries/Ethernet/examples/TwitterClient/TwitterClient.ino124
-rw-r--r--libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino (renamed from libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.pde)6
-rw-r--r--libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino (renamed from libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.pde)4
-rw-r--r--libraries/Ethernet/examples/WebClient/WebClient.ino (renamed from libraries/Ethernet/examples/WebClient/WebClient.pde)2
-rw-r--r--libraries/Ethernet/examples/WebServer/WebServer.ino (renamed from libraries/Ethernet/examples/WebServer/WebServer.pde)6
13 files changed, 244 insertions, 28 deletions
diff --git a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.pde b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
index 3f43d96..bfbcb6d 100644
--- a/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.pde
+++ b/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
@@ -39,7 +39,7 @@ IPAddress subnet(255, 255, 255, 0);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
-Server server(80);
+EthernetServer server(80);
//Sensor's memory register addresses:
@@ -96,7 +96,7 @@ void loop() {
}
// listen for incoming Ethernet connections:
- listenForClients();
+ listenForEthernetClients();
}
@@ -124,9 +124,9 @@ void getData() {
Serial.println(" Pa");
}
-void listenForClients() {
+void listenForEthernetClients() {
// listen for incoming clients
- Client client = server.available();
+ EthernetClient client = server.available();
if (client) {
Serial.println("Got a client");
// an http request ends with a blank line
diff --git a/libraries/Ethernet/examples/ChatServer/ChatServer.pde b/libraries/Ethernet/examples/ChatServer/ChatServer.ino
index 8267a5d..9f819fd 100644
--- a/libraries/Ethernet/examples/ChatServer/ChatServer.pde
+++ b/libraries/Ethernet/examples/ChatServer/ChatServer.ino
@@ -29,7 +29,7 @@ IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 0, 0);
// telnet defaults to port 23
-Server server(23);
+EthernetServer server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet
void setup() {
@@ -43,7 +43,7 @@ void setup() {
void loop() {
// wait for a new client:
- Client client = server.available();
+ EthernetClient client = server.available();
// when the client sends the first byte, say hello:
if (client) {
diff --git a/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.pde b/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino
index 50a557d..630dd17 100644
--- a/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.pde
+++ b/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino
@@ -24,7 +24,7 @@ byte mac[] = {
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
-Client client;
+EthernetClient client;
void setup() {
// start the serial library:
diff --git a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino
new file mode 100644
index 0000000..5082054
--- /dev/null
+++ b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino
@@ -0,0 +1,80 @@
+/*
+ DHCP Chat Server
+
+ A simple server that distributes any incoming messages to all
+ 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.
+ Using an Arduino Wiznet Ethernet shield.
+
+ THis version attempts to get an IP address using DHCP
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+
+ created 21 May 2011
+ by Tom Igoe
+ Based on ChatServer example by David A. Mellis
+
+ */
+
+#include <SPI.h>
+#include <Ethernet.h>
+
+// Enter a MAC address and IP address for your controller below.
+// The IP address will be dependent on your local network.
+// gateway and subnet are optional:
+byte mac[] = {
+ 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
+IPAddress ip(192,168,1, 177);
+IPAddress gateway(192,168,1, 1);
+IPAddress subnet(255, 255, 0, 0);
+
+// telnet defaults to port 23
+EthernetServer server(23);
+boolean gotAMessage = false; // whether or not you got a message from the client yet
+
+void setup() {
+ // open the serial port
+ Serial.begin(9600);
+ // start the Ethernet connection:
+ Serial.println("Trying to get an IP address using DHCP");
+ if (Ethernet.begin(mac) == 0) {
+ Serial.println("Failed to configure Ethernet using DHCP");
+ // initialize the ethernet device not using DHCP:
+ Ethernet.begin(mac, ip, gateway, subnet);
+ }
+ // print your local IP address:
+ Serial.print("My IP address: ");
+ ip = Ethernet.localIP();
+ for (byte thisByte = 0; thisByte < 4; thisByte++) {
+ // print the value of each byte of the IP address:
+ Serial.print(ip[thisByte], DEC);
+ Serial.print(".");
+ }
+ Serial.println();
+ // start listening for clients
+ server.begin();
+
+}
+
+void loop() {
+ // wait for a new client:
+ EthernetClient client = server.available();
+
+ // when the client sends the first byte, say hello:
+ if (client) {
+ if (!gotAMessage) {
+ Serial.println("We have a new client");
+ client.println("Hello, client!");
+ gotAMessage = true;
+ }
+
+ // read the bytes incoming from the client:
+ char thisChar = client.read();
+ // echo the bytes back to the client:
+ server.write(thisChar);
+ // echo the bytes to the server as well:
+ Serial.print(thisChar);
+ }
+}
+
diff --git a/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.pde b/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino
index 7bec73a..5c7a53a 100644
--- a/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.pde
+++ b/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino
@@ -25,7 +25,7 @@ char serverName[] = "www.google.com";
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
-Client client;
+EthernetClient client;
void setup() {
// start the serial library:
diff --git a/libraries/Ethernet/examples/PachubeClient/PachubeClient.pde b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino
index af9bf1f..a169443 100644
--- a/libraries/Ethernet/examples/PachubeClient/PachubeClient.pde
+++ b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino
@@ -11,7 +11,7 @@
* Ethernet shield attached to pins 10, 11, 12, 13
created 15 March 2010
- updated 4 Sep 2010
+ updated 26 Oct 2011
by Tom Igoe
http://www.tigoe.net/pcomp/code/category/arduinowiring/873
@@ -28,8 +28,11 @@
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+// fill in an available IP address on your network here,
+// for manual configuration:
+IPAddress ip(10,0,1,20);
// initialize the library instance:
-Client client;
+EthernetClient client;
long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
@@ -47,6 +50,12 @@ void setup() {
}
// give the ethernet module time to boot up:
delay(1000);
+ // start the Ethernet connection:
+ if (Ethernet.begin(mac) == 0) {
+ Serial.println("Failed to configure Ethernet using DHCP");
+ // Configure manually:
+ Ethernet.begin(mac, ip);
+ }
}
void loop() {
diff --git a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.pde b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino
index e6dbf09..4a03100 100644
--- a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.pde
+++ b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino
@@ -14,7 +14,7 @@
* Ethernet shield attached to pins 10, 11, 12, 13
created 15 March 2010
- updated 4 Sep 2010
+ updated 26 Oct 2011
by Tom Igoe
This code is in the public domain.
@@ -28,25 +28,28 @@
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+// fill in an available IP address on your network here,
+// for manual configuration:
+IPAddress ip(10,0,1,20);
// initialize the library instance:
-Client client;
+EthernetClient client;
long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const int postingInterval = 10000; //delay between updates to Pachube.com
void setup() {
- // start the ethernet connection and serial port:
+ // start serial port:
Serial.begin(9600);
+ // give the ethernet module time to boot up:
+ delay(1000);
+ // start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
- // no point in carrying on, so do nothing forevermore:
- for(;;)
- ;
+ // Configure manually:
+ Ethernet.begin(mac, ip);
}
- // give the ethernet module time to boot up:
- delay(1000);
}
void loop() {
diff --git a/libraries/Ethernet/examples/TelnetClient/TelnetClient.pde b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino
index 7502d21..5cf1ad8 100644
--- a/libraries/Ethernet/examples/TelnetClient/TelnetClient.pde
+++ b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino
@@ -33,7 +33,7 @@ IPAddress server(1,1,1,1);
// with the IP address and port of the server
// that you want to connect to (port 23 is default for telnet;
// if you're using Processing's ChatServer, use port 10002):
-Client client;
+EthernetClient client;
void setup() {
// start the Ethernet connection:
diff --git a/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino b/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino
new file mode 100644
index 0000000..f113e17
--- /dev/null
+++ b/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino
@@ -0,0 +1,124 @@
+/*
+ Twitter Client with Strings
+
+ This sketch connects to Twitter using an Ethernet shield. It parses the XML
+ returned, and looks for <text>this is a tweet</text>
+
+ You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield,
+ either one will work, as long as it's got a Wiznet Ethernet module on board.
+
+ This example uses the DHCP routines in the Ethernet library which is part of the
+ Arduino core from version 1.0 beta 1
+
+ This example uses the String library, which is part of the Arduino core from
+ version 0019.
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+
+ created 21 May 2011
+ by Tom Igoe
+
+ This code is in the public domain.
+
+ */
+#include <SPI.h>
+#include <Ethernet.h>
+
+
+// Enter a MAC address and IP address for your controller below.
+// The IP address will be dependent on your local network:
+byte mac[] = {
+ 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
+IPAddress ip(192,168,1,20);
+
+// initialize the library instance:
+EthernetClient client;
+
+const int requestInterval = 60000; // delay between requests
+
+char serverName[] = "api.twitter.com"; // twitter URL
+
+boolean requested; // whether you've made a request since connecting
+long lastAttemptTime = 0; // last time you connected to the server, in milliseconds
+
+String currentLine = ""; // string to hold the text from server
+String tweet = ""; // string to hold the tweet
+boolean readingTweet = false; // if you're currently reading the tweet
+
+void setup() {
+ // reserve space for the strings:
+ currentLine.reserve(256);
+ tweet.reserve(150);
+
+// initialize serial:
+ Serial.begin(9600);
+ // attempt a DHCP connection:
+ if (!Ethernet.begin(mac)) {
+ // if DHCP fails, start with a hard-coded address:
+ Ethernet.begin(mac, ip);
+ }
+ // connect to Twitter:
+ connectToServer();
+}
+
+
+
+void loop()
+{
+ if (client.connected()) {
+ if (client.available()) {
+ // read incoming bytes:
+ char inChar = client.read();
+
+ // add incoming byte to end of line:
+ currentLine += inChar;
+
+ // if you get a newline, clear the line:
+ if (inChar == '\n') {
+ currentLine = "";
+ }
+ // if the current line ends with <text>, it will
+ // be followed by the tweet:
+ if ( currentLine.endsWith("<text>")) {
+ // tweet is beginning. Clear the tweet string:
+ readingTweet = true;
+ tweet = "";
+ }
+ // if you're currently reading the bytes of a tweet,
+ // add them to the tweet String:
+ if (readingTweet) {
+ if (inChar != '<') {
+ tweet += inChar;
+ }
+ else {
+ // if you got a "<" character,
+ // you've reached the end of the tweet:
+ readingTweet = false;
+ Serial.println(tweet);
+ // close the connection to the server:
+ client.stop();
+ }
+ }
+ }
+ }
+ else if (millis() - lastAttemptTime > requestInterval) {
+ // if you're not connected, and two minutes have passed since
+ // your last connection, then attempt to connect again:
+ connectToServer();
+ }
+}
+
+void connectToServer() {
+ // attempt to connect, and wait a millisecond:
+ Serial.println("connecting to server...");
+ if (client.connect(serverName, 80)) {
+ Serial.println("making HTTP request...");
+ // make HTTP GET request to twitter:
+ client.println("GET /1/statuses/user_timeline.xml?screen_name=arduino&count=1 HTTP/1.1");
+ client.println("HOST: api.twitter.com");
+ client.println();
+ }
+ // note the time of this connect attempt:
+ lastAttemptTime = millis();
+}
diff --git a/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.pde b/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino
index 081d691..4d4045c 100644
--- a/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.pde
+++ b/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino
@@ -15,7 +15,7 @@
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
-#include <Udp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
+#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
// Enter a MAC address and IP address for your controller below.
@@ -30,8 +30,8 @@ unsigned int localPort = 8888; // local port to listen on
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
-// A UDP instance to let us send and receive packets over UDP
-UDP Udp;
+// An EthernetUDP instance to let us send and receive packets over UDP
+EthernetUDP Udp;
void setup() {
// start the Ethernet and UDP:
diff --git a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.pde b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
index 7c2d3ea..b4e24b8 100644
--- a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.pde
+++ b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
@@ -18,7 +18,7 @@
#include <SPI.h>
#include <Ethernet.h>
-#include <Udp.h>
+#include <EthernetUdp.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
@@ -34,7 +34,7 @@ const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
// A UDP instance to let us send and receive packets over UDP
-UDP Udp;
+EthernetUDP Udp;
void setup()
{
diff --git a/libraries/Ethernet/examples/WebClient/WebClient.pde b/libraries/Ethernet/examples/WebClient/WebClient.ino
index 646c3aa..1806854 100644
--- a/libraries/Ethernet/examples/WebClient/WebClient.pde
+++ b/libraries/Ethernet/examples/WebClient/WebClient.ino
@@ -23,7 +23,7 @@ IPAddress server(173,194,33,104); // Google
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
-Client client;
+EthernetClient client;
void setup() {
// start the serial library:
diff --git a/libraries/Ethernet/examples/WebServer/WebServer.pde b/libraries/Ethernet/examples/WebServer/WebServer.ino
index c69a56a..6837f83 100644
--- a/libraries/Ethernet/examples/WebServer/WebServer.pde
+++ b/libraries/Ethernet/examples/WebServer/WebServer.ino
@@ -1,5 +1,5 @@
/*
- Web Server
+ Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
@@ -26,7 +26,7 @@ IPAddress ip(192,168,1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
-Server server(80);
+EthernetServer server(80);
void setup()
{
@@ -38,7 +38,7 @@ void setup()
void loop()
{
// listen for incoming clients
- Client client = server.available();
+ EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;