Skip to content

Commit 0ec9036

Browse files
committed
Merge remote branch 'upstream/new-extension'
Moved my fork to the Arduino 1.0 codebase
2 parents 326f65b + 992131d commit 0ec9036

File tree

10 files changed

+394
-19
lines changed

10 files changed

+394
-19
lines changed

Client.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern "C" {
55
#include "string.h"
66
}
77

8-
#include "WProgram.h"
8+
#include "Arduino.h"
99

1010
#include "Ethernet.h"
1111
#include "Client.h"
@@ -156,18 +156,8 @@ uint8_t Client::status() {
156156
return W5100.readSnSR(_sock);
157157
}
158158

159-
// the next three functions are a hack so we can compare the client returned
160-
// by Server::available() to null, or use it as the condition in an
161-
// if-statement. this lets us stay compatible with the Processing network
162-
// library.
163-
164-
uint8_t Client::operator==(int p) {
165-
return _sock == MAX_SOCK_NUM;
166-
}
167-
168-
uint8_t Client::operator!=(int p) {
169-
return _sock != MAX_SOCK_NUM;
170-
}
159+
// the next function allows us to use the client returned by
160+
// Server::available() as the condition in an if-statement.
171161

172162
Client::operator bool() {
173163
return _sock != MAX_SOCK_NUM;

Client.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef client_h
22
#define client_h
3-
#include "WProgram.h"
3+
#include "Arduino.h"
44
#include "Print.h"
55

66
class Client : public Stream {
@@ -22,8 +22,6 @@ class Client : public Stream {
2222
virtual void flush();
2323
void stop();
2424
uint8_t connected();
25-
uint8_t operator==(int);
26-
uint8_t operator!=(int);
2725
operator bool();
2826

2927
friend class Server;

Dhcp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <string.h>
77
#include <stdlib.h>
88
#include "Dhcp.h"
9-
#include "wiring.h"
9+
#include "Arduino.h"
1010
#include "util.h"
1111

1212
int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)

Dns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "Dns.h"
1010
#include <string.h>
1111
//#include <stdlib.h>
12-
#include "wiring.h"
12+
#include "Arduino.h"
1313

1414

1515
#define SOCKET_NONE 255

IPAddress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include <WProgram.h>
2+
#include <Arduino.h>
33
#include <IPAddress.h>
44

55
IPAddress::IPAddress()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
DHCP-based IP printer
3+
4+
This sketch uses the DHCP extensions to the Ethernet library
5+
to get an IP address via DHCP and print the address obtained.
6+
using an Arduino Wiznet Ethernet shield.
7+
8+
Circuit:
9+
* Ethernet shield attached to pins 10, 11, 12, 13
10+
11+
created 12 April 2011
12+
by Tom Igoe
13+
14+
*/
15+
16+
#include <SPI.h>
17+
#include <Ethernet.h>
18+
19+
// Enter a MAC address for your controller below.
20+
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
21+
byte mac[] = {
22+
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
23+
24+
// Initialize the Ethernet client library
25+
// with the IP address and port of the server
26+
// that you want to connect to (port 80 is default for HTTP):
27+
Client client;
28+
29+
void setup() {
30+
// start the serial library:
31+
Serial.begin(9600);
32+
// start the Ethernet connection:
33+
Serial.println("Trying to get an IP address using DHCP");z
34+
if (Ethernet.begin(mac) == 0) {
35+
Serial.println("Failed to configure Ethernet using DHCP");
36+
// no point in carrying on, so do nothing forevermore:
37+
while(true);
38+
}
39+
// print your local IP address:
40+
Serial.print("My IP address: ");
41+
IPAddress myIPAddress = Ethernet.localIP();
42+
for (byte thisByte = 0; thisByte < 4; thisByte++) {
43+
// print the value of each byte of the IP address:
44+
Serial.print(myIPAddress[thisByte], DEC);
45+
Serial.print(".");
46+
}
47+
Serial.println();
48+
}
49+
50+
void loop() {
51+
52+
}
53+
54+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
DHCP-based IP printer
3+
4+
This sketch uses the DHCP extensions to the Ethernet library
5+
to get an IP address via DHCP and print the address obtained.
6+
using an Arduino Wiznet Ethernet shield.
7+
8+
Circuit:
9+
* Ethernet shield attached to pins 10, 11, 12, 13
10+
11+
created 12 April 2011
12+
by Tom Igoe
13+
14+
*/
15+
16+
#include <SPI.h>
17+
#include <Ethernet.h>
18+
19+
// Enter a MAC address for your controller below.
20+
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
21+
byte mac[] = {
22+
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
23+
24+
// Initialize the Ethernet client library
25+
// with the IP address and port of the server
26+
// that you want to connect to (port 80 is default for HTTP):
27+
Client client;
28+
29+
void setup() {
30+
// start the serial library:
31+
Serial.begin(9600);
32+
// start the Ethernet connection:
33+
if (Ethernet.begin(mac) == 0) {
34+
Serial.println("Failed to configure Ethernet using DHCP");
35+
// no point in carrying on, so do nothing forevermore:
36+
for(;;)
37+
;
38+
}
39+
// print your local IP address:
40+
Serial.print("My IP address: ");
41+
for (byte thisByte = 0; thisByte < 4; thisByte++) {
42+
// print the value of each byte of the IP address:
43+
Serial.print(Ethernet.localIP()[thisByte], DEC);
44+
Serial.print(".");
45+
}
46+
Serial.println();
47+
}
48+
49+
void loop() {
50+
51+
}
52+
53+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
DHCP Chat Server
3+
4+
A simple server that distributes any incoming messages to all
5+
connected clients. To use telnet to your device's IP address and type.
6+
You can see the client's input in the serial monitor as well.
7+
Using an Arduino Wiznet Ethernet shield.
8+
9+
THis version attempts to get an IP address using DHCP
10+
11+
Circuit:
12+
* Ethernet shield attached to pins 10, 11, 12, 13
13+
14+
created 21 May 2011
15+
by Tom Igoe
16+
Based on ChatServer example by David A. Mellis
17+
18+
*/
19+
20+
#include <SPI.h>
21+
#include <Ethernet.h>
22+
23+
// Enter a MAC address and IP address for your controller below.
24+
// The IP address will be dependent on your local network.
25+
// gateway and subnet are optional:
26+
byte mac[] = {
27+
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
28+
IPAddress ip(192,168,1, 177);
29+
IPAddress gateway(192,168,1, 1);
30+
IPAddress subnet(255, 255, 0, 0);
31+
32+
// telnet defaults to port 23
33+
Server server(23);
34+
boolean gotAMessage = false; // whether or not you got a message from the client yet
35+
36+
void setup() {
37+
// open the serial port
38+
Serial.begin(9600);
39+
// start the Ethernet connection:
40+
Serial.println("Trying to get an IP address using DHCP");
41+
if (Ethernet.begin(mac) == 0) {
42+
Serial.println("Failed to configure Ethernet using DHCP");
43+
// initialize the ethernet device not using DHCP:
44+
Ethernet.begin(mac, ip, gateway, subnet);
45+
}
46+
// print your local IP address:
47+
Serial.print("My IP address: ");
48+
ip = Ethernet.localIP();
49+
for (byte thisByte = 0; thisByte < 4; thisByte++) {
50+
// print the value of each byte of the IP address:
51+
Serial.print(ip[thisByte], DEC);
52+
Serial.print(".");
53+
}
54+
Serial.println();
55+
// start listening for clients
56+
server.begin();
57+
58+
}
59+
60+
void loop() {
61+
// wait for a new client:
62+
Client client = server.available();
63+
64+
// when the client sends the first byte, say hello:
65+
if (client) {
66+
if (!gotAMessage) {
67+
Serial.println("We have a new client");
68+
client.println("Hello, client!");
69+
gotAMessage = true;
70+
}
71+
72+
// read the bytes incoming from the client:
73+
char thisChar = client.read();
74+
// echo the bytes back to the client:
75+
server.write(thisChar);
76+
// echo the bytes to the server as well:
77+
Serial.print(thisChar);
78+
}
79+
}
80+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
DNS and DHCP-based Web client
3+
4+
This sketch connects to a website (http://www.google.com)
5+
using an Arduino Wiznet Ethernet shield.
6+
7+
Circuit:
8+
* Ethernet shield attached to pins 10, 11, 12, 13
9+
10+
created 18 Dec 2009
11+
by David A. Mellis
12+
modified 12 April 2011
13+
by Tom Igoe, based on work by Adrian McEwen
14+
15+
*/
16+
17+
#include <SPI.h>
18+
#include <Ethernet.h>
19+
20+
// Enter a MAC address for your controller below.
21+
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
22+
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
23+
char serverName[] = "www.google.com";
24+
25+
// Initialize the Ethernet client library
26+
// with the IP address and port of the server
27+
// that you want to connect to (port 80 is default for HTTP):
28+
Client client;
29+
30+
void setup() {
31+
// start the serial library:
32+
Serial.begin(9600);
33+
// start the Ethernet connection:
34+
if (Ethernet.begin(mac) == 0) {
35+
Serial.println("Failed to configure Ethernet using DHCP");
36+
// no point in carrying on, so do nothing forevermore:
37+
while(true);
38+
}
39+
// give the Ethernet shield a second to initialize:
40+
delay(1000);
41+
Serial.println("connecting...");
42+
43+
// if you get a connection, report back via serial:
44+
45+
if (client.connect(serverName, 80)) {
46+
Serial.println("connected");
47+
// Make a HTTP request:
48+
client.println("GET /search?q=arduino HTTP/1.0");
49+
client.println();
50+
}
51+
else {
52+
// kf you didn't get a connection to the server:
53+
Serial.println("connection failed");
54+
}
55+
}
56+
57+
void loop()
58+
{
59+
// if there are incoming bytes available
60+
// from the server, read them and print them:
61+
if (client.available()) {
62+
char c = client.read();
63+
Serial.print(c);
64+
}
65+
66+
// if the server's disconnected, stop the client:
67+
if (!client.connected()) {
68+
Serial.println();
69+
Serial.println("disconnecting.");
70+
client.stop();
71+
72+
// do nothing forevermore:
73+
while(true);
74+
}
75+
}
76+

0 commit comments

Comments
 (0)