1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Proposed fix for issue 243, adding DNS to the Ethernet library. Uses a slightly modified version of the agreed API as the host/port parameters have been moved from the Client constructor to the Client::connect methods. This means it's possible for errors to be returned if the DNS lookup fails and also reduces the RAM footprint of the Client class as it no longer needs to store the host/port for later use in Client::connect.

This commit is contained in:
amcewen
2011-01-25 16:29:38 +00:00
committed by David A. Mellis
parent 1b56de694b
commit b455e81b76
9 changed files with 503 additions and 26 deletions

View File

@ -28,11 +28,8 @@
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// The address of the server you want to connect to (pachube.com):
IPAddress server(209,40,205,190);
// initialize the library instance:
Client client(server, 80);
Client 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
@ -85,7 +82,7 @@ void loop() {
// this method makes a HTTP connection to the server:
void sendData(int thisData) {
// if there's a successful connection:
if (client.connect()) {
if (client.connect("www.pachube.com", 80)) {
Serial.println("connecting...");
// send the HTTP PUT request.
// fill in your feed address here:

View File

@ -28,16 +28,9 @@
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// assign an IP address for the controller:
IPAddress ip(192,169,1,20);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255, 255, 255, 0);
// The address of the server you want to connect to (pachube.com):
IPAddress server(209,40,205,190);
// initialize the library instance:
Client client(server, 80);
Client 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
@ -45,8 +38,13 @@ const int postingInterval = 10000; //delay between updates to Pachube.com
void setup() {
// start the ethernet connection and serial port:
Ethernet.begin(mac, ip);
Serial.begin(9600);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// give the ethernet module time to boot up:
delay(1000);
}
@ -92,7 +90,7 @@ void loop() {
// this method makes a HTTP connection to the server:
void sendData(String thisData) {
// if there's a successful connection:
if (client.connect()) {
if (client.connect("www.pachube.com", 80)) {
Serial.println("connecting...");
// send the HTTP PUT request.
// fill in your feed address here:

View File

@ -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(server, 10002);
Client client;
void setup() {
// start the Ethernet connection:
@ -45,7 +45,7 @@ void setup() {
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect()) {
if (client.connect(server, 10002)) {
Serial.println("connected");
}
else {

View File

@ -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(server, 80);
Client client;
void setup() {
// start the serial library:
@ -40,7 +40,7 @@ void setup() {
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect()) {
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.0");