mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +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:
@ -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:
|
||||
|
Reference in New Issue
Block a user